xref: /freebsd/lib/libc/stdlib/strfmon.3 (revision b740c88bfb6453416926271c089262e7164dace3)
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 June 25, 2012
28.Dt STRFMON 3
29.Os
30.Sh NAME
31.Nm strfmon
32.Nd convert monetary value to string
33.Sh LIBRARY
34.Lb libc
35.Sh SYNOPSIS
36.In monetary.h
37.Ft ssize_t
38.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
39.Ft ssize_t
40.Fn strfmon_l "char * restrict s" "size_t maxsize" "locale_t loc" "const char * restrict format" "..."
41.Sh DESCRIPTION
42The
43.Fn strfmon
44function places characters into the array pointed to by
45.Fa s
46as controlled by the string pointed to by
47.Fa format .
48No more than
49.Fa maxsize
50bytes are placed into the array.
51.Pp
52The
53.Fn strfmon_l
54function does the same as
55.Fn strfmon
56but takes an explicit locale rather than using the current locale.
57.Pp
58The format string is composed of zero or more directives:
59ordinary characters (not
60.Cm % ) ,
61which are copied unchanged to the output stream; and conversion
62specifications, each of which results in fetching zero or more subsequent
63arguments.
64Each conversion specification is introduced by the
65.Cm %
66character.
67After the
68.Cm % ,
69the following appear in sequence:
70.Bl -bullet
71.It
72Zero or more of the following flags:
73.Bl -tag -width "XXX"
74.It Cm = Ns Ar f
75A
76.Sq Cm =
77character followed by another character
78.Ar f
79which is used as the numeric fill character.
80.It Cm ^
81Do not use grouping characters, regardless of the current locale default.
82.It Cm +
83Represent positive values by prefixing them with a positive sign,
84and negative values by prefixing them with a negative sign.
85This is the default.
86.It Cm \&(
87Enclose negative values in parentheses.
88.It Cm \&!
89Do not include a currency symbol in the output.
90.It Cm \-
91Left justify the result.
92Only valid when a field width is specified.
93.El
94.It
95An optional minimum field width as a decimal number.
96By default, there is no minimum width.
97.It
98A
99.Sq Cm #
100sign followed by a decimal number specifying the maximum
101expected number of digits after the radix character.
102.It
103A
104.Sq Cm \&.
105character followed by a decimal number specifying the number
106the number of digits after the radix character.
107.It
108One of the following conversion specifiers:
109.Bl -tag -width "XXX"
110.It Cm i
111The
112.Vt double
113argument is formatted as an international monetary amount.
114.It Cm n
115The
116.Vt double
117argument is formatted as a national monetary amount.
118.It Cm %
119A
120.Sq Li %
121character is written.
122.El
123.El
124.Sh RETURN VALUES
125If the total number of resulting bytes including the terminating
126.Dv NUL
127byte is not more than
128.Fa maxsize ,
129.Fn strfmon
130returns the number of bytes placed into the array pointed to by
131.Fa s ,
132not including the terminating
133.Dv NUL
134byte.
135Otherwise, \-1 is returned,
136the contents of the array are indeterminate,
137and
138.Va errno
139is set to indicate the error.
140.Pp
141The
142.Fn strfmon_l
143function returns the same values as
144.Fn strfmon .
145.Sh ERRORS
146The
147.Fn strfmon
148function will fail if:
149.Bl -tag -width Er
150.It Bq Er E2BIG
151Conversion stopped due to lack of space in the buffer.
152.It Bq Er EINVAL
153The format string is invalid.
154.It Bq Er ENOMEM
155Not enough memory for temporary buffers.
156.El
157.Sh SEE ALSO
158.Xr localeconv 3
159.Sh STANDARDS
160The
161.Fn strfmon
162function
163conforms to
164.St -p1003.1-2001 .
165The
166.Fn strfmon_l
167function conforms to
168.St -p1003.1-2008 .
169.Sh AUTHORS
170.An -nosplit
171The
172.Fn strfmon
173function was implemented by
174.An Alexey Zelkin Aq Mt phantom@FreeBSD.org .
175.Pp
176This manual page was written by
177.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org
178based on the standards' text.
179.Sh BUGS
180The
181.Fn strfmon
182function does not correctly handle multibyte characters in the
183.Fa format
184argument.
185