11 print, fprint, sprint, snprint, seprint, smprint, vfprint, vsnprint, vseprint, vsmprint \- print formatted output
19 int print(char *format, ...)
22 int fprint(int fd, char *format, ...)
25 int sprint(char *s, char *format, ...)
28 int snprint(char *s, int len, char *format, ...)
31 char* seprint(char *s, char *e, char *format, ...)
34 char* smprint(char *format, ...)
37 int runesprint(Rune *s, char *format, ...)
40 int runesnprint(Rune *s, int len, char *format, ...)
43 Rune* runeseprint(Rune *s, Rune *e, char *format, ...)
46 Rune* runesmprint(char *format, ...)
49 int vfprint(int fd, char *format, va_list v)
52 int vsnprint(char *s, int len, char *format, va_list v)
55 char* vseprint(char *s, char *e, char *format, va_list v)
58 char* vsmprint(char *format, va_list v)
61 int runevsnprint(Rune *s, int len, char *format, va_list v)
64 Rune* runevseprint(Rune *s, Rune *e, char *format, va_list v)
67 Rune* runevsmprint(Rune *format, va_list v)
72 writes text to the standard output.
74 writes to the named output
78 followed by the NUL character
80 in consecutive bytes starting at
82 it is the user's responsibility to ensure that
83 enough storage is available.
84 Each function returns the number of bytes
85 transmitted (not including the NUL
89 a negative value if an output error was encountered.
94 but will not place more than
98 Its result is always NUL-terminated and holds the maximal
99 number of characters that can fit.
103 except that the end is indicated by a pointer
105 rather than a count and the return value points to the terminating NUL of the
110 except that it prints into and returns a string of the required length, which is
126 except that their output is rune strings instead of byte strings.
128 Finally, the routines
139 relatives except they take as arguments a
141 parameter, so they can be called within a variadic function.
142 The Example section shows a representative usage.
144 Each of these functions
145 converts, formats, and prints its
152 contains two types of objects:
153 plain characters, which are simply copied to the
155 and conversion specifications,
156 each of which results in fetching of
159 The results are undefined if there are arguments of the
160 wrong type or too few
161 arguments for the format.
162 If the format is exhausted while
163 arguments remain, the excess
166 Each conversion specification has the following format:
170 The verb is a single character and each flag is a single character or a
171 (decimal) numeric string.
172 Up to two numeric strings may be used;
177 A period can be used to separate them, and if the period is
182 are taken to be zero if missing, otherwise they are `omitted'.
183 Either or both of the numbers may be replaced with the character
185 meaning that the actual number will be obtained from the argument list
187 The flags and numbers are arguments to
201 format their arguments in decimal, decimal,
202 unsigned decimal, octal, binary, hexadecimal, and upper case hexadecimal.
203 Each interprets the flags
213 to mean pad with zeros,
214 short, byte, long, always print a sign, left justified, commas every three digits,
215 and alternate format.
216 Also, a space character in the flag
219 but prints a space instead of a plus sign for non-negative values.
221 short nor long is specified,
222 then the argument is an
224 If an unsigned verb is specified,
225 then the argument is interpreted as a
226 positive number and no sign is output;
229 flags are ignored for unsigned verbs.
233 then the argument is interpreted as a
235 (usually an 8-byte, sometimes a 4-byte integer).
238 is not omitted, the number is padded on the left with zeros
244 is explicitly 0, and the number is 0,
245 no digits are generated, and alternate formatting
247 Then, if alternate format is specified,
250 conversion, the number is preceded by a
252 if it doesn't already begin with one.
253 For non-zero numbers and
255 conversion, the number is preceded by
259 conversion, the number is preceded by
263 is not omitted, the number is padded on the left (or right, if
264 left justification is specified) with enough blanks to
265 make the field at least
269 The floating point verbs
279 Each interprets the flags
286 to mean pad with zeros,
287 long double argument,
293 is the minimum field width and,
294 if the converted value takes up less than
296 characters, it is padded on the left (or right, if `left justified')
299 is the number of digits that are converted after the decimal place for
307 is the maximum number of significant digits for
314 verb produces output of the form
315 .RB [ - ] digits [ .digits\fR].
317 conversion appends an exponent
321 conversion appends an exponent
325 verb will output the argument in either
329 with the goal of producing the smallest output.
330 Also, trailing zeros are omitted from the fraction part of
331 the output, and a trailing decimal point appears only if it is followed
335 verb is similar, but uses
339 When alternate format is specified, the result will always contain a decimal point,
344 conversions, trailing zeros are not removed.
352 The number of characters copied
355 of the size of the string and
359 characters are justified within a field of
361 characters as described above.
364 is given, it is safe for the string not to be nul-terminated
365 as long as it is at least
367 characters (not bytes!) long.
370 verb is similar, but it interprets its pointer as an array
373 the runes are converted to
383 justified within a field of
385 characters as described above.
388 verb is similar, but works on runes.
392 verb formats a pointer value.
393 At the moment, it is a synonym for
395 but that will change if pointers and integers are different sizes.
399 verb takes no arguments; it copies the error string returned by a call to
404 Custom verbs may be installed using
407 This function prints an error message with a variable
408 number of arguments and then quits.
412 void fatal(char *msg, ...)
414 char buf[1024], *out;
417 out = vseprint(buf, buf+sizeof buf, "Fatal error: ");
419 out = vseprint(out, buf+sizeof buf, msg, arg);
421 write(2, buf, out-buf);
430 Routines that write to a file descriptor or call
435 The formatting is close to that specified for ANSI
437 the main difference is that
441 are not in ANSI and some
444 Also, and distinctly not a bug,
454 etc. because runes are byte-order dependent and should not be written directly to a file; use the
462 is deprecated for safety reasons; use
468 Safety also precludes the existence of