xref: /plan9/sys/src/cmd/unix/u9fs/print.c (revision 9df354649c4cda9c2f83c9ee41152de551c09141)
1 #include <plan9.h>
2 
3 #define	SIZE	4096
4 extern	int	printcol;
5 
6 int
print(char * fmt,...)7 print(char *fmt, ...)
8 {
9 	char buf[SIZE], *out;
10 	va_list arg, temp;
11 	int n;
12 
13 	va_start(arg, fmt);
14 	va_copy(temp, arg);
15 	out = doprint(buf, buf+SIZE, fmt, &temp);
16 	va_end(temp);
17 	va_end(arg);
18 	n = write(1, buf, (long)(out-buf));
19 	return n;
20 }
21 
22 int
fprint(int f,char * fmt,...)23 fprint(int f, char *fmt, ...)
24 {
25 	char buf[SIZE], *out;
26 	va_list arg, temp;
27 	int n;
28 
29 	va_start(arg, fmt);
30 	va_copy(temp, arg);
31 	out = doprint(buf, buf+SIZE, fmt, &temp);
32 	va_end(temp);
33 	va_end(arg);
34 	n = write(f, buf, (long)(out-buf));
35 	return n;
36 }
37 
38 int
sprint(char * buf,char * fmt,...)39 sprint(char *buf, char *fmt, ...)
40 {
41 	char *out;
42 	va_list arg, temp;
43 	int scol;
44 
45 	scol = printcol;
46 	va_start(arg, fmt);
47 	va_copy(temp, arg);
48 	out = doprint(buf, buf+SIZE, fmt, &temp);
49 	va_end(temp);
50 	va_end(arg);
51 	printcol = scol;
52 	return out-buf;
53 }
54 
55 int
snprint(char * buf,int len,char * fmt,...)56 snprint(char *buf, int len, char *fmt, ...)
57 {
58 	char *out;
59 	va_list arg, temp;
60 	int scol;
61 
62 	scol = printcol;
63 	va_start(arg, fmt);
64 	va_copy(temp, arg);
65 	out = doprint(buf, buf+len, fmt, &temp);
66 	va_end(temp);
67 	va_end(arg);
68 	printcol = scol;
69 	return out-buf;
70 }
71 
72 char*
seprint(char * buf,char * e,char * fmt,...)73 seprint(char *buf, char *e, char *fmt, ...)
74 {
75 	char *out;
76 	va_list arg, temp;
77 	int scol;
78 
79 	scol = printcol;
80 	va_start(arg, fmt);
81 	va_copy(temp, arg);
82 	out = doprint(buf, e, fmt, &temp);
83 	va_end(temp);
84 	va_end(arg);
85 	printcol = scol;
86 	return out;
87 }
88