printf.3 (20631f47f16df06373ffdbbc2f2d4a4307f0b047) | printf.3 (15aa00d597010009c3fb718ded37438aa3f601ab) |
---|---|
1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38.Dd June 4, 1993 39.Dt PRINTF 3 40.Os 41.Sh NAME 42.Nm printf , 43.Nm fprintf , 44.Nm sprintf , 45.Nm snprintf , | 1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38.Dd June 4, 1993 39.Dt PRINTF 3 40.Os 41.Sh NAME 42.Nm printf , 43.Nm fprintf , 44.Nm sprintf , 45.Nm snprintf , |
46.Nm asprintf , |
|
46.Nm vprintf , 47.Nm vfprintf, 48.Nm vsprintf , | 47.Nm vprintf , 48.Nm vfprintf, 49.Nm vsprintf , |
49.Nm vsnprintf | 50.Nm vsnprintf , 51.Nm vasprintf |
50.Nd formatted output conversion 51.Sh SYNOPSIS 52.Fd #include <stdio.h> 53.Ft int 54.Fn printf "const char *format" ... 55.Ft int 56.Fn fprintf "FILE *stream" "const char *format" ... 57.Ft int 58.Fn sprintf "char *str" "const char *format" ... 59.Ft int 60.Fn snprintf "char *str" "size_t size" "const char *format" ... | 52.Nd formatted output conversion 53.Sh SYNOPSIS 54.Fd #include <stdio.h> 55.Ft int 56.Fn printf "const char *format" ... 57.Ft int 58.Fn fprintf "FILE *stream" "const char *format" ... 59.Ft int 60.Fn sprintf "char *str" "const char *format" ... 61.Ft int 62.Fn snprintf "char *str" "size_t size" "const char *format" ... |
61.\" .Ft int 62.\" .Fn smprintf "const char *format" ... | 63.Ft int 64.Fn asprintf "char **ret" "const char *format" ... |
63.Fd #include <stdarg.h> 64.Ft int 65.Fn vprintf "const char *format" "va_list ap" 66.Ft int 67.Fn vfprintf "FILE *stream" "const char *format" "va_list ap" 68.Ft int 69.Fn vsprintf "char *str" "char *format" "va_list ap" 70.Ft int 71.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" | 65.Fd #include <stdarg.h> 66.Ft int 67.Fn vprintf "const char *format" "va_list ap" 68.Ft int 69.Fn vfprintf "FILE *stream" "const char *format" "va_list ap" 70.Ft int 71.Fn vsprintf "char *str" "char *format" "va_list ap" 72.Ft int 73.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" |
72.\" .Ft int 73.\" .Fn vsmprintf "const char *format" "va_list ap" | 74.Ft int 75.Fn vasprintf "char **ret" "const char *format" "va_list ap" |
74.Sh DESCRIPTION 75The 76.Fn printf 77family of functions produces output according to a 78.Fa format 79as described below. 80.Fn Printf 81and --- 7 unchanged lines hidden (view full) --- 89write output to the given output 90.Fa stream ; 91.Fn sprintf , 92.Fn snprintf , 93.Fn vsprintf , 94and 95.Fn vsnprintf 96write to the character string | 76.Sh DESCRIPTION 77The 78.Fn printf 79family of functions produces output according to a 80.Fa format 81as described below. 82.Fn Printf 83and --- 7 unchanged lines hidden (view full) --- 91write output to the given output 92.Fa stream ; 93.Fn sprintf , 94.Fn snprintf , 95.Fn vsprintf , 96and 97.Fn vsnprintf 98write to the character string |
97.Fa str . 98.\" .IR str ; 99.\" and 100.\" .I smprintf 101.\" and 102.\" .I vsmprintf 103.\" dynamically allocate a new string with 104.\" .IR malloc . | 99.Fa str ; 100and 101.Fn asprintf 102and 103.Fn vasprintf 104dynamically allocate a new string with 105.Xr malloc 3 106/ 107.Xr realloc 3 . 108.Pp |
105These functions write the output under the control of a 106.Fa format 107string that specifies how subsequent arguments 108(or arguments accessed via the variable-length argument facilities of 109.Xr stdarg 3 ) 110are converted for output. | 109These functions write the output under the control of a 110.Fa format 111string that specifies how subsequent arguments 112(or arguments accessed via the variable-length argument facilities of 113.Xr stdarg 3 ) 114are converted for output. |
111.\" Except for 112.\" .I smprintf 113.\" and 114.\" .IR vsmprintf , 115.\" all of these functions return | 115.Pp |
116These functions return 117the number of characters printed 118(not including the trailing 119.Ql \e0 120used to end output to strings). | 116These functions return 117the number of characters printed 118(not including the trailing 119.Ql \e0 120used to end output to strings). |
121.\" .I Smprintf 122.\" and 123.\" .I vsmprintf 124.\" return a pointer to a string of an appropriate length; 125.\" this pointer should be passed to 126.\" .I free 127.\" to release the associated storage 128.\" when it is no longer needed. 129.\" If sufficient space is not avaliable, 130.\" .I smprintf 131.\" and 132.\" .I vsmprintf 133.\" will return 134.\" .SM 135.\" .BR | 121.Pp 122.Fn Asprintf 123and 124.Fn vasprintf 125return a pointer to a buffer sufficiently large to hold the 126string in the 127.Fa ret 128argument; 129This pointer should be passed to 130.Xr free 3 131to release the allocated storage when it is no longer needed. 132If sufficient space cannot be allocated, 133.Fn asprintf 134and 135.Fn vasprintf 136will return -1 and set 137.Fa ret 138to be a NULL pointer. 139.Pp |
136.Fn Snprintf 137and 138.Fn vsnprintf 139will write at most 140.Fa size Ns \-1 141of the characters printed into the output string 142(the 143.Fa size Ns 'th 144character then gets the terminating 145.Ql \e0 ) ; 146if the return value is greater than or equal to the 147.Fa size 148argument, the string was too short 149and some of the printed characters were discarded. | 140.Fn Snprintf 141and 142.Fn vsnprintf 143will write at most 144.Fa size Ns \-1 145of the characters printed into the output string 146(the 147.Fa size Ns 'th 148character then gets the terminating 149.Ql \e0 ) ; 150if the return value is greater than or equal to the 151.Fa size 152argument, the string was too short 153and some of the printed characters were discarded. |
154.Pp |
|
150.Fn Sprintf 151and 152.Fn vsprintf 153effectively assume an infinite 154.Fa size . 155.Pp 156The format string is composed of zero or more directives: 157ordinary --- 437 unchanged lines hidden (view full) --- 595conform to 596.St -ansiC . 597.Sh HISTORY 598The functions 599.Fn snprintf 600and 601.Fn vsnprintf 602are new to this release. | 155.Fn Sprintf 156and 157.Fn vsprintf 158effectively assume an infinite 159.Fa size . 160.Pp 161The format string is composed of zero or more directives: 162ordinary --- 437 unchanged lines hidden (view full) --- 600conform to 601.St -ansiC . 602.Sh HISTORY 603The functions 604.Fn snprintf 605and 606.Fn vsnprintf 607are new to this release. |
608.Pp 609The functions 610.Fn asprintf 611and 612.Fn vasprintf 613first appeared in the GNU C library. This implementation is thought 614to be compatable but is not derived from the GNU code. This implementation 615was written by Peter Wemm <peter@FreeBSD.org> and first appeared in 616FreeBSD-2.2. |
|
603.Sh BUGS 604The conversion formats 605.Cm \&%D , 606.Cm \&%O , 607and 608.Cm %U 609are not standard and 610are provided only for backward compatibility. --- 28 unchanged lines hidden --- | 617.Sh BUGS 618The conversion formats 619.Cm \&%D , 620.Cm \&%O , 621and 622.Cm %U 623are not standard and 624are provided only for backward compatibility. --- 28 unchanged lines hidden --- |