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
208 to mean pad with zeros,
209 short, byte, long, vlong, unsigned, always print a sign, left justified, commas every three digits,
210 and alternate format.
211 Also, a space character in the flag
214 but prints a space instead of a plus sign for non-negative values.
216 short nor long is specified,
217 then the argument is an
219 If unsigned is specified,
220 then the argument is interpreted as a
221 positive number and no sign is output.
224 is not omitted, the number is padded on the left with zeros
228 Then, if alternate format is specified,
231 conversion, the number is preceded by a
233 if it doesn't already begin with one;
236 conversion, the number is preceded by
240 conversion, the number is preceded by
244 is not omitted, the number is padded on the left (or right, if
245 left justification is specified) with enough blanks to
246 make the field at least
250 The floating point verbs
260 Each interprets the flags
271 is the minimum field width and,
272 if the converted value takes up less than
274 characters, it is padded on the left (or right, if `left justified')
277 is the number of digits that are converted after the decimal place for
285 is the maximum number of significant digits for
292 verb produces output of the form
293 .RB [ - ] digits [ .digits\fR].
295 conversion appends an exponent
299 conversion appends an exponent
303 verb will output the argument in either
307 with the goal of producing the smallest output.
308 Also, trailing zeros are omitted from the fraction part of
309 the output, and a trailing decimal point appears only if it is followed
313 verb is similar, but uses
317 When alternate format is specified, the result will always contain a decimal point,
322 conversions, trailing zeros are not removed.
326 verb copies a nul-terminated string
330 The number of characters copied
333 of the size of the string and
337 characters are justified within a field of
339 characters as described above.
342 is given, it is safe for the string not to be nul-terminated
343 as long as it is at least
345 characters (not bytes!) long.
348 verb is similar, but it interprets its pointer as an array
351 the runes are converted to
361 justified within a field of
363 characters as described above.
366 verb is similar, but works on runes.
370 verb formats a single pointer or pointer-sized integer
378 verb takes no arguments; it copies the error string returned by a call to
381 Custom verbs may be installed using
384 This function prints an error message with a variable
385 number of arguments and then quits.
389 void fatal(char *msg, ...)
391 char buf[1024], *out;
394 out = seprint(buf, buf+sizeof(buf), "Fatal error: ");
396 out = vseprint(out, buf+sizeof(buf), msg, arg);
398 write(2, buf, out-buf);
399 exits("fatal error");
410 Routines that write to a file descriptor or call
415 The formatting is close to that specified for ANSI
417 the main difference is that
421 is a flag here instead of a verb.
422 Also, and distinctly not a bug,
432 etc. because runes are byte-order dependent and should not be written directly to a file; use the
440 is deprecated for safety reasons; use
446 Safety also precludes the existence of