3 print, fprint, sprint, snprint, seprint, smprint, runesprint, runesnprint, runeseprint, runesmprint, vfprint, vsnprint, vseprint, vsmprint, runevsnprint, runevseprint, runevsmprint \- print formatted output
11 int print(char *format, ...)
14 int fprint(int fd, char *format, ...)
17 int sprint(char *s, char *format, ...)
20 int snprint(char *s, int len, char *format, ...)
23 char* seprint(char *s, char *e, char *format, ...)
26 char* smprint(char *format, ...)
29 int runesprint(Rune *s, char *format, ...)
32 int runesnprint(Rune *s, int len, char *format, ...)
35 Rune* runeseprint(Rune *s, Rune *e, char *format, ...)
38 Rune* runesmprint(char *format, ...)
41 int vfprint(int fd, char *format, va_list v)
44 int vsnprint(char *s, int len, char *format, va_list v)
47 char* vseprint(char *s, char *e, char *format, va_list v)
50 char* vsmprint(char *format, va_list v)
53 int runevsnprint(Rune *s, int len, char *format, va_list v)
56 Rune* runevseprint(Rune *s, Rune *e, char *format, va_list v)
59 Rune* runevsmprint(Rune *format, va_list v)
64 writes text to the standard output.
66 writes to the named output
73 followed by the NUL character
75 in consecutive bytes starting at
77 it is the user's responsibility to ensure that
78 enough storage is available.
79 Each function returns the number of bytes
80 transmitted (not including the NUL
84 a negative value if an output error was encountered.
89 but will not place more than
93 Its result is always NUL-terminated and holds the maximal
94 number of complete UTF-8 characters that can fit.
98 except that the end is indicated by a pointer
100 rather than a count and the return value points to the terminating NUL of the
105 except that it prints into and returns a string of the required length, which is
121 except that their output is rune strings instead of byte strings.
123 Finally, the routines
134 relatives except they take as arguments a
136 parameter, so they can be called within a variadic function.
137 The Example section shows a representative usage.
139 Each of these functions
140 converts, formats, and prints its
147 contains two types of objects:
148 plain characters, which are simply copied to the
150 and conversion specifications,
151 each of which results in fetching of
154 The results are undefined if there are arguments of the
155 wrong type or too few
156 arguments for the format.
157 If the format is exhausted while
158 arguments remain, the excess
161 Each conversion specification has the following format:
165 The verb is a single character and each flag is a single character or a
166 (decimal) numeric string.
167 Up to two numeric strings may be used;
172 A period can be used to separate them, and if the period is
177 are taken to be zero if missing, otherwise they are `omitted'.
178 Either or both of the numbers may be replaced with the character
180 meaning that the actual number will be obtained from the argument list
182 The flags and numbers are arguments to
194 format their arguments in decimal,
195 octal, binary, hexadecimal, and upper case hexadecimal.
196 Each interprets the flags
207 to mean pad with zeros,
208 short, byte, long, unsigned, always print a sign, left justified, commas every three digits,
209 and alternate format.
210 Also, a space character in the flag
213 but prints a space instead of a plus sign for non-negative values.
215 short nor long is specified,
216 then the argument is an
218 If unsigned is specified,
219 then the argument is interpreted as a
220 positive number and no sign is output.
224 then the argument is interpreted as a
226 (usually an 8-byte, sometimes a 4-byte integer).
229 is not omitted, the number is padded on the left with zeros
233 Then, if alternate format is specified,
236 conversion, the number is preceded by a
238 if it doesn't already begin with one;
241 conversion, the number is preceded by
245 conversion, the number is preceded by
249 is not omitted, the number is padded on the left (or right, if
250 left justification is specified) with enough blanks to
251 make the field at least
255 The floating point verbs
265 Each interprets the flags
276 is the minimum field width and,
277 if the converted value takes up less than
279 characters, it is padded on the left (or right, if `left justified')
282 is the number of digits that are converted after the decimal place for
290 is the maximum number of significant digits for
297 verb produces output of the form
298 .RB [ - ] digits [ .digits\fR].
300 conversion appends an exponent
304 conversion appends an exponent
308 verb will output the argument in either
312 with the goal of producing the smallest output.
313 Also, trailing zeros are omitted from the fraction part of
314 the output, and a trailing decimal point appears only if it is followed
318 verb is similar, but uses
322 When alternate format is specified, the result will always contain a decimal point,
327 conversions, trailing zeros are not removed.
331 verb copies a nul-terminated string
335 The number of characters copied
338 of the size of the string and
342 characters are justified within a field of
344 characters as described above.
347 is given, it is safe for the string not to be nul-terminated
348 as long as it is at least
350 characters (not bytes!) long.
353 verb is similar, but it interprets its pointer as an array
356 the runes are converted to
366 justified within a field of
368 characters as described above.
371 verb is similar, but works on runes.
375 verb formats a single pointer or pointer-sized integer
383 verb takes no arguments; it copies the error string returned by a call to
386 Custom verbs may be installed using
389 This function prints an error message with a variable
390 number of arguments and then quits.
394 void fatal(char *msg, ...)
396 char buf[1024], *out;
399 out = seprint(buf, buf+sizeof(buf), "Fatal error: ");
401 out = vseprint(out, buf+sizeof(buf), msg, arg);
403 write(2, buf, out-buf);
404 exits("fatal error");
415 Routines that write to a file descriptor or call
420 The formatting is close to that specified for ANSI
422 the main difference is that
426 is a flag here instead of a verb.
427 Also, and distinctly not a bug,
437 etc. because runes are byte-order dependent and should not be written directly to a file; use the
445 is deprecated for safety reasons; use
451 Safety also precludes the existence of