2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
18 .\" Copyright 1989 AT&T
19 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
20 .\" Copyright 2016 Nexenta Systems, Inc.
30 .Nd format characters in memory
38 .Fa "const char *format"
45 .Fa "const char *format"
52 .Fa "const char *format"
59 .Fa "const char *format"
67 Pointer to a character string.
69 Size of the buffer pointed to by
72 Pointer to a character string.
74 Pointer to a variable argument list.
79 function places output, followed by the null byte
81 in consecutive bytes starting at
83 it is the user's responsibility to ensure that enough storage is available.
87 function is identical to
89 with the addition of the argument
91 which specifies the size of the buffer referred to by
95 is 0, nothing is written and
97 can be a null pointer.
98 Otherwise, output bytes beyond the
100 are discarded instead of being written to the array and a null byte is written
101 at the end of the bytes actually written into the array.
107 functions are the same as
111 respectively, except that instead of being called with a variable number of
112 arguments, they are called with an argument list,
114 used by the conversion specifications in
117 is a variable argument list and must be initialized by calling
120 is used to clean up and must be called after each traversal of the list.
121 Multiple traversals of the argument list, each bracketed by
127 Each of these functions converts, formats, and prints its arguments under
132 is composed of zero or more directives: ordinary characters, which are simply
133 copied to the output stream and conversion specifications, each of which results
134 in the fetching of zero or more arguments.
135 The results are undefined if there are insufficient arguments for the
139 is exhausted while arguments remain, the excess arguments are evaluated but are
141 .Ss Conversion Specifications
142 Each conversion specification is introduced by the
144 character after which the following appear in sequence:
149 which modify the meaning of the conversion specification.
151 An optional minimum field width.
152 If the converted value has fewer bytes than the field width, it will be padded
153 with spaces by default on the left; it will be padded on the right, if the
156 described below, is given to the field width.
157 The field width takes the form of an asterisk
159 described below, or a decimal integer.
161 An optional precision that gives the minimum number of digits to appear for the
162 .Sy d , D , o , O , x , X ,
166 .Pq the field is padded with leading zeros ;
167 or the maximum number of bytes to be printed from a string in s conversion.
168 The precision takes the form of a period
170 followed either by an asterisk
172 described below, or an optional decimal digit string, where a null digit string
174 If a precision appears with any other conversion specifier, the behavior is
177 An optional length modifier that specified the size of the argument.
179 A conversion specifier that indicates the type of conversion to be applied.
182 A field width, or precision, or both can be indicated by an asterisk
184 In this case, an argument of type int supplies the field width or precision.
185 Arguments specifying field width, or precision, or both must appear in that
186 order before the argument, if any, to be converted.
187 A negative field width is taken as a
189 flag followed by a positive field width.
190 A negative precision is taken as if the precision were omitted.
192 The flag characters and their meanings are:
195 The result of the conversion will be left-justified within the field.
196 The conversion will be right-justified if this flag is not specified.
199 .Sy d , D , o , O , x , X ,
202 conversions, leading zeros
203 .Pq following any indication of sign or base
204 are used to pad to the field width; no space padding is performed.
209 flags both appear, the
211 flag will be ignored.
212 If a precision is specified, the
214 flag will be ignored.
215 For other conversions, the behavior is undefined.
218 The length modifiers and their meanings are:
221 Specifies that a following
222 .Sy d , D , o , O , x , X ,
225 conversion specifier applies to a short or unsigned
227 .Po the argument will have been promoted according to the integer promotions,
228 but its value will be converted to short or unsigned short before printing
231 Specifies that a following
232 .Sy d , D , o , O , x , X ,
235 conversion specifier applies to a signed char or unsigned char argument
236 .Po the argument will have been promoted according to the integer promotions,
237 but its value will be converted to signed char or unsigned char before printing
240 Specifies that a following
241 .Sy d , D , o , O , x , X ,
244 conversion specifier applies to a long or unsigned long argument.
246 Specifies that a following
247 .Sy d , D , o , O , x , X ,
250 conversion specifier applies to a long long or unsigned long long argument.
252 .Ss Conversion Specifiers
253 Each conversion specifier results in fetching zero or more arguments.
254 The results are undefined if there are insufficient arguments for the
258 is exhausted while arguments remain, the excess arguments are ignored.
260 The conversion specifiers and their meanings are:
262 .It Sy d , D , o , O , x , X , u
263 The integer argument is converted to signed decimal
282 The character value of the argument is printed.
286 conversion specification allows bit values to be printed meaningfully.
289 takes an integer value and a format string from the argument list.
290 The first character of the format string should be the output base encoded as a
292 This base is used to print the integer argument.
293 The remaining groups of characters in the format string consist of a bit number
294 .Pq between 1 and 32, also encoded as a control character
295 and the next characters
296 .Pq up to the next control character or '\e0'
297 give the name of the bit field.
298 The string corresponding to the bit fields set in the integer argument is
299 printed after the numerical value.
301 The argument is taken to be a pointer; the value of the pointer is printed in
302 unsigned hexadecimal.
303 The print format is equivalent to
305 To avoid lint warnings, cast pointers to type
311 The argument is taken to be a string
312 .Pq character pointer ,
313 and characters from the string are printed until a null character is ecountered.
314 If the character pointer is
318 is used in its place.
322 no argument is converted.
325 These functions can be called from user, kernel, interrupt, or
326 high-level interrupt context.
337 return the number of bytes that would have been written to
341 had been sufficiently large
342 .Pq excluding the terminating null byte .