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.
122 They return a rune count rather than a byte count.
124 Finally, the routines
135 relatives except they take as arguments a
137 parameter, so they can be called within a variadic function.
138 The Example section shows a representative usage.
140 Each of these functions
141 converts, formats, and prints its
148 contains two types of objects:
149 plain characters, which are simply copied to the
151 and conversion specifications,
152 each of which results in fetching of
155 The results are undefined if there are arguments of the
156 wrong type or too few
157 arguments for the format.
158 If the format is exhausted while
159 arguments remain, the excess
162 Each conversion specification has the following format:
166 The verb is a single character and each flag is a single character or a
167 (decimal) numeric string.
168 Up to two numeric strings may be used;
173 A period can be used to separate them, and if the period is
178 are taken to be zero if missing, otherwise they are `omitted'.
179 Either or both of the numbers may be replaced with the character
181 meaning that the actual number will be obtained from the argument list
183 The flags and numbers are arguments to
195 format their arguments in decimal,
196 octal, binary, hexadecimal, and upper case hexadecimal.
197 Each interprets the flags
208 to mean pad with zeros,
209 short, byte, long, 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.
225 then the argument is interpreted as a
227 (usually an 8-byte, sometimes a 4-byte integer).
230 is not omitted, the number is padded on the left with zeros
236 is explicitly 0, and the number is 0,
237 no digits are generated, and alternate formatting
239 Then, if alternate format is specified,
242 conversion, the number is preceded by a
244 if it doesn't already begin with one;
247 conversion, the number is preceded by
251 conversion, the number is preceded by
255 is not omitted, the number is padded on the left (or right, if
256 left justification is specified) with enough blanks to
257 make the field at least
261 The floating point verbs
271 Each interprets the flags
278 to mean pad with zeros,
279 long double argument,
285 is the minimum field width and,
286 if the converted value takes up less than
288 characters, it is padded on the left (or right, if `left justified')
291 is the number of digits that are converted after the decimal place for
299 is the maximum number of significant digits for
306 verb produces output of the form
307 .RB [ - ] digits [ .digits\fR].
309 conversion appends an exponent
313 conversion appends an exponent
317 verb will output the argument in either
321 with the goal of producing the smallest output.
322 Also, trailing zeros are omitted from the fraction part of
323 the output, and a trailing decimal point appears only if it is followed
327 verb is similar, but uses
331 When alternate format is specified, the result will always contain a decimal point,
336 conversions, trailing zeros are not removed.
340 verb copies a NUL-terminated string
344 The number of characters copied
347 of the size of the string and
351 characters are justified within a field of
353 characters as described above.
356 is given, it is safe for the string not to be nul-terminated
357 as long as it is at least
359 characters (not bytes!) long.
362 verb is similar, but it interprets its pointer as an array
365 the runes are converted to
375 justified within a field of
377 characters as described above.
380 verb is similar, but works on runes.
384 verb formats a pointer value.
385 At the moment, it is a synonym for
387 but that will change if pointers and integers are different sizes.
391 verb takes no arguments; it copies the error string returned by a call to
394 Custom verbs may be installed using
397 This function prints an error message with a variable
398 number of arguments and then quits.
402 void fatal(char *msg, ...)
404 char buf[1024], *out;
407 out = seprint(buf, buf+sizeof buf, "Fatal error: ");
409 out = vseprint(out, buf+sizeof buf, msg, arg);
411 write(2, buf, out-buf);
412 exits("fatal error");
422 Routines that write to a file descriptor or call
427 The formatting is close to that specified for ANSI
429 the main difference is that
435 is a flag here instead of a verb.
436 Also, and distinctly not a bug,
446 etc. because runes are byte-order dependent and should not be written directly to a file; use the
454 is deprecated for safety reasons; use
460 Safety also precludes the existence of