]> git.lizzy.rs Git - plan9front.git/blob - sys/src/ape/lib/fmt/runefmtstr.c
sdiahci, sdodin: avoid calling kproc() while holding ilock()
[plan9front.git] / sys / src / ape / lib / fmt / runefmtstr.c
1 /*
2  * The authors of this software are Rob Pike and Ken Thompson.
3  *              Copyright (c) 2002 by Lucent Technologies.
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose without fee is hereby granted, provided that this entire notice
6  * is included in all copies of any software which is or includes a copy
7  * or modification of this software and in all copies of the supporting
8  * documentation for such software.
9  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10  * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
13  */
14 #include <stdarg.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include "utf.h"
18 #include "fmt.h"
19 #include "fmtdef.h"
20
21 static int
22 runeFmtStrFlush(Fmt *f)
23 {
24         Rune *s;
25         int n;
26
27         n = (int)f->farg;
28         n += 256;
29         f->farg = (void*)n;
30         s = (Rune*)f->start;
31         f->start = realloc(s, sizeof(Rune)*n);
32         if(f->start == nil){
33                 f->start = s;
34                 return 0;
35         }
36         f->to = (Rune*)f->start + ((Rune*)f->to - s);
37         f->stop = (Rune*)f->start + n - 1;
38         return 1;
39 }
40
41 int
42 runefmtstrinit(Fmt *f)
43 {
44         int n;
45
46         f->runes = 1;
47         n = 32;
48         f->start = malloc(sizeof(Rune)*n);
49         if(f->start == nil)
50                 return -1;
51         f->to = f->start;
52         f->stop = (Rune*)f->start + n - 1;
53         f->flush = runeFmtStrFlush;
54         f->farg = (void*)n;
55         f->nfmt = 0;
56         return 0;
57 }
58
59 Rune*
60 runefmtstrflush(Fmt *f)
61 {
62         *(Rune*)f->to = '\0';
63         f->to = f->start;
64         return f->start;
65 }