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
235 is explicitly 0, and the number is 0,
236 no digits are generated, and alternate formatting
238 Then, if alternate format is specified,
241 conversion, the number is preceded by a
243 if it doesn't already begin with one;
246 conversion, the number is preceded by
250 conversion, the number is preceded by
254 is not omitted, the number is padded on the left (or right, if
255 left justification is specified) with enough blanks to
256 make the field at least
260 The floating point verbs
270 Each interprets the flags
277 to mean pad with zeros,
278 long double argument,
284 is the minimum field width and,
285 if the converted value takes up less than
287 characters, it is padded on the left (or right, if `left justified')
290 is the number of digits that are converted after the decimal place for
298 is the maximum number of significant digits for
305 verb produces output of the form
306 .RB [ - ] digits [ .digits\fR].
308 conversion appends an exponent
312 conversion appends an exponent
316 verb will output the argument in either
320 with the goal of producing the smallest output.
321 Also, trailing zeros are omitted from the fraction part of
322 the output, and a trailing decimal point appears only if it is followed
326 verb is similar, but uses
330 When alternate format is specified, the result will always contain a decimal point,
335 conversions, trailing zeros are not removed.
339 verb copies a NUL-terminated string
343 The number of characters copied
346 of the size of the string and
350 characters are justified within a field of
352 characters as described above.
355 is given, it is safe for the string not to be nul-terminated
356 as long as it is at least
358 characters (not bytes!) long.
361 verb is similar, but it interprets its pointer as an array
364 the runes are converted to
374 justified within a field of
376 characters as described above.
379 verb is similar, but works on runes.
383 verb formats a pointer value.
384 At the moment, it is a synonym for
386 but that will change if pointers and integers are different sizes.
390 verb takes no arguments; it copies the error string returned by a call to
393 Custom verbs may be installed using
396 This function prints an error message with a variable
397 number of arguments and then quits.
401 void fatal(char *msg, ...)
403 char buf[1024], *out;
406 out = seprint(buf, buf+sizeof buf, "Fatal error: ");
408 out = vseprint(out, buf+sizeof buf, msg, arg);
410 write(2, buf, out-buf);
411 exits("fatal error");
421 Routines that write to a file descriptor or call
426 The formatting is close to that specified for ANSI
428 the main difference is that
434 is a flag here instead of a verb.
435 Also, and distinctly not a bug,
445 etc. because runes are byte-order dependent and should not be written directly to a file; use the
453 is deprecated for safety reasons; use
459 Safety also precludes the existence of