xref: /freebsd/lib/libc/stdlib/strfmon.3 (revision 058ac3e8063366dafa634d9107642e12b038bf09)
1.\" Copyright (c) 2001 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd October 28, 2022
28.Dt STRFMON 3
29.Os
30.Sh NAME
31.Nm strfmon ,
32.Nm strfmon_l
33.Nd convert monetary value to string
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In monetary.h
38.Ft ssize_t
39.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
40.Ft ssize_t
41.Fn strfmon_l "char * restrict s" "size_t maxsize" "locale_t loc" "const char * restrict format" "..."
42.Sh DESCRIPTION
43The
44.Fn strfmon
45function places characters into the array pointed to by
46.Fa s
47as controlled by the string pointed to by
48.Fa format .
49No more than
50.Fa maxsize
51bytes are placed into the array.
52.Pp
53The
54.Fn strfmon_l
55function does the same as
56.Fn strfmon
57but takes an explicit locale rather than using the current locale.
58.Pp
59The format string is composed of zero or more directives:
60ordinary characters (not
61.Cm % ) ,
62which are copied unchanged to the output stream; and conversion
63specifications, each of which results in fetching zero or more subsequent
64arguments.
65Each conversion specification is introduced by the
66.Cm %
67character.
68After the
69.Cm % ,
70the following appear in sequence:
71.Bl -bullet
72.It
73Zero or more of the following flags:
74.Bl -tag -width "XXX"
75.It Cm = Ns Ar f
76A
77.Sq Cm =
78character followed by another character
79.Ar f
80which is used as the numeric fill character.
81.It Cm ^
82Do not use grouping characters, regardless of the current locale default.
83.It Cm +
84Represent positive values by prefixing them with a positive sign,
85and negative values by prefixing them with a negative sign.
86This is the default.
87.It Cm \&(
88Enclose negative values in parentheses.
89.It Cm \&!
90Do not include a currency symbol in the output.
91.It Cm \-
92Left justify the result.
93Only valid when a field width is specified.
94.El
95.It
96An optional minimum field width as a decimal number.
97By default, there is no minimum width.
98.It
99A
100.Sq Cm #
101sign followed by a decimal number specifying the maximum
102expected number of digits before the radix character.
103When this option is used, values that do not exceed the
104specified number of digits are formatted so they will be
105correctly aligned with other values printed using the same
106format.
107This includes always leaving space for a possible sign
108indicator, even if none is needed for a particular value.
109.It
110A
111.Sq Cm \&.
112character followed by a decimal number specifying the number
113of digits after the radix character.
114.It
115One of the following conversion specifiers:
116.Bl -tag -width "XXX"
117.It Cm i
118The
119.Vt double
120argument is formatted as an international monetary amount.
121.It Cm n
122The
123.Vt double
124argument is formatted as a national monetary amount.
125.It Cm %
126A
127.Sq Li %
128character is written.
129.El
130.El
131.Sh RETURN VALUES
132If the total number of resulting bytes including the terminating
133.Dv NUL
134byte is not more than
135.Fa maxsize ,
136.Fn strfmon
137returns the number of bytes placed into the array pointed to by
138.Fa s ,
139not including the terminating
140.Dv NUL
141byte.
142Otherwise, \-1 is returned,
143the contents of the array are indeterminate,
144and
145.Va errno
146is set to indicate the error.
147.Pp
148The
149.Fn strfmon_l
150function returns the same values as
151.Fn strfmon .
152.Sh ERRORS
153The
154.Fn strfmon
155function will fail if:
156.Bl -tag -width Er
157.It Bq Er E2BIG
158Conversion stopped due to lack of space in the buffer.
159.It Bq Er EINVAL
160The format string is invalid.
161.It Bq Er ENOMEM
162Not enough memory for temporary buffers.
163.El
164.Sh SEE ALSO
165.Xr localeconv 3 ,
166.Xr xlocale 3
167.Sh STANDARDS
168The
169.Fn strfmon
170function
171conforms to
172.St -p1003.1-2001 .
173The
174.Fn strfmon_l
175function conforms to
176.St -p1003.1-2008 .
177.Sh AUTHORS
178.An -nosplit
179The
180.Fn strfmon
181function was implemented by
182.An Alexey Zelkin Aq Mt phantom@FreeBSD.org .
183.Pp
184This manual page was written by
185.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org
186based on the standards' text.
187.Sh BUGS
188The
189.Fn strfmon
190function does not correctly handle multibyte characters in the
191.Fa format
192argument.
193