aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/strfromd.3
blob: acd3867c0425c346fd5dd53db1ebb9d4fe553409 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
.\"
.\" Copyright (c) 2026 Faraz Vahedi <kfv@kfv.io>
.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.Dd June 27, 2026
.Dt STRFROMD 3
.Os
.Sh NAME
.Nm strfromd ,
.Nm strfromf ,
.Nm strfroml
.Nd convert floating point value to
.Tn ASCII
string
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In stdlib.h
.Ft int
.Fn strfromd "char * restrict str" "size_t size" "const char * restrict format" "double fp"
.Ft int
.Fn strfromf "char * restrict str" "size_t size" "const char * restrict format" "float fp"
.Ft int
.Fn strfroml "char * restrict str" "size_t size" "const char * restrict format" "long double fp"
.Sh DESCRIPTION
Functions
.Fn strfromd ,
.Fn strfromf ,
and
.Fn strfroml
convert the floating-point value
.Fa fp
to a null terminated string, storing at most
.Fa size
bytes
.Pq including the terminating null character
into the array pointed to by
.Fa str .
.Pp
These functions are equivalent to
.Fn snprintf "s" "n" "format" "fp" ,
except that default argument promotions are not applied to
.Fa fp ,
and the
.Fa format
string is restricted.
It shall consist of exactly the character
.Ql % ,
followed by an optional precision that does not contain an asterisk
.Ql * ,
followed by one of the conversion specifiers
.Cm a , A , e , E , f , F , g ,
or
.Cm G .
The conversion specifier applies to the type indicated by the
function suffix, rather than by a length modifier.
.Pp
Use of any other format string results in undefined behaviour,
as does any undefined behaviour inherited from
.Xr snprintf 3
per se.
In case of a format string not specified by the standard, the string
.Ql EDOOFUS
is written to
.Fa str ,
subject to the same truncation rules as a successful conversion, and
.Va errno
is set to
.Er EDOOFUS .
.Sh RETURN VALUES
The
.Fn strfromd ,
.Fn strfromf ,
and
.Fn strfroml
functions, as per
.Xr snprintf 3 ,
return the number of characters
.Po
not counting the terminating null character
.Pc
that would have been written
had
.Fa n
been sufficiently large.
Thus, the null terminated output has been completely written if
and only if the returned value is both nonnegative and less than
.Fa size .
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EDOOFUS
The
.Fa format
string is not of the form the standard specifies.
.El
.Sh SEE ALSO
.Xr snprintf 3 ,
.Xr strtod 3 ,
.Xr strtol 3 ,
.Xr strtoul 3
.Sh STANDARDS
Functions
.Fn strfromd ,
.Fn strfromf ,
and
.Fn strfroml
conform to
.St -isoC-2023 .