1 .\" diffs from /usr/local/plan9/man/man3/print.3:
3 .\" - include different headers
4 .\" - drop reference to bio(3)
5 .\" - change exits to exit
6 .\" - text about unsigned verbs
11 print, fprint, sprint, snprint, seprint, smprint, runesprint, runesnprint, runeseprint, runesmprint, vfprint, vsnprint, vseprint, vsmprint, runevsnprint, runevseprint, runevsmprint \- 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
81 followed by the NUL character
83 in consecutive bytes starting at
85 it is the user's responsibility to ensure that
86 enough storage is available.
87 Each function returns the number of bytes
88 transmitted (not including the NUL
92 a negative value if an output error was encountered.
97 but will not place more than
101 Its result is always NUL-terminated and holds the maximal
102 number of complete UTF-8 characters that can fit.
106 except that the end is indicated by a pointer
108 rather than a count and the return value points to the terminating NUL of the
113 except that it prints into and returns a string of the required length, which is
129 except that their output is rune strings instead of byte strings.
131 Finally, the routines
142 relatives except they take as arguments a
144 parameter, so they can be called within a variadic function.
145 The Example section shows a representative usage.
147 Each of these functions
148 converts, formats, and prints its
155 contains two types of objects:
156 plain characters, which are simply copied to the
158 and conversion specifications,
159 each of which results in fetching of
162 The results are undefined if there are arguments of the
163 wrong type or too few
164 arguments for the format.
165 If the format is exhausted while
166 arguments remain, the excess
169 Each conversion specification has the following format:
173 The verb is a single character and each flag is a single character or a
174 (decimal) numeric string.
175 Up to two numeric strings may be used;
180 A period can be used to separate them, and if the period is
185 are taken to be zero if missing, otherwise they are `omitted'.
186 Either or both of the numbers may be replaced with the character
188 meaning that the actual number will be obtained from the argument list
190 The flags and numbers are arguments to
204 format their arguments in decimal, decimal,
205 unsigned decimal, octal, binary, hexadecimal, and upper case hexadecimal.
206 Each interprets the flags
216 to mean pad with zeros,
217 short, byte, long, always print a sign, left justified, commas every three digits,
218 and alternate format.
219 Also, a space character in the flag
222 but prints a space instead of a plus sign for non-negative values.
224 short nor long is specified,
225 then the argument is an
227 If an unsigned verb is specified,
228 then the argument is interpreted as a
229 positive number and no sign is output;
232 flags are ignored for unsigned verbs.
236 then the argument is interpreted as a
238 (usually an 8-byte, sometimes a 4-byte integer).
241 is not omitted, the number is padded on the left with zeros
247 is explicitly 0, and the number is 0,
248 no digits are generated, and alternate formatting
250 Then, if alternate format is specified,
253 conversion, the number is preceded by a
255 if it doesn't already begin with one.
256 For non-zero numbers and
258 conversion, the number is preceded by
262 conversion, the number is preceded by
266 is not omitted, the number is padded on the left (or right, if
267 left justification is specified) with enough blanks to
268 make the field at least
272 The floating point verbs
282 Each interprets the flags
289 to mean pad with zeros,
290 long double argument,
296 is the minimum field width and,
297 if the converted value takes up less than
299 characters, it is padded on the left (or right, if `left justified')
302 is the number of digits that are converted after the decimal place for
310 is the maximum number of significant digits for
317 verb produces output of the form
318 .RB [ - ] digits [ .digits\fR].
320 conversion appends an exponent
324 conversion appends an exponent
328 verb will output the argument in either
332 with the goal of producing the smallest output.
333 Also, trailing zeros are omitted from the fraction part of
334 the output, and a trailing decimal point appears only if it is followed
338 verb is similar, but uses
342 When alternate format is specified, the result will always contain a decimal point,
347 conversions, trailing zeros are not removed.
355 The number of characters copied
358 of the size of the string and
362 characters are justified within a field of
364 characters as described above.
367 is given, it is safe for the string not to be nul-terminated
368 as long as it is at least
370 characters (not bytes!) long.
373 verb is similar, but it interprets its pointer as an array
376 the runes are converted to
386 justified within a field of
388 characters as described above.
391 verb is similar, but works on runes.
395 verb formats a pointer value.
396 At the moment, it is a synonym for
398 but that will change if pointers and integers are different sizes.
402 verb takes no arguments; it copies the error string returned by a call to
407 Custom verbs may be installed using
410 This function prints an error message with a variable
411 number of arguments and then quits.
415 void fatal(char *msg, ...)
417 char buf[1024], *out;
420 out = seprint(buf, buf+sizeof buf, "Fatal error: ");
422 out = vseprint(out, buf+sizeof buf, msg, arg);
424 write(2, buf, out-buf);
429 .B http://swtch.com/plan9port/unix
435 Routines that write to a file descriptor or call
440 The formatting is close to that specified for ANSI
442 the main difference is that
446 are not in ANSI and some
448 verbs and syntax are missing.
449 Also, and distinctly not a bug,
459 etc. because runes are byte-order dependent and should not be written directly to a file; use the
467 is deprecated for safety reasons; use
473 Safety also precludes the existence of