aboutsummaryrefslogtreecommitdiff
path: root/libste.3
blob: f81e079fc450ea95c0ccc06c0fe4b89d740da8ae (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
110
111
112
113
114
115
.Dd November 5, 2021
.Dt LIBSTE 3
.Os
.Sh NAME
.Nm stecpy ,
.Nm stecpe ,
.Nm stechr ,
.Nm steprn
.Nd string library based on string ends
.Sh SYNOPSIS
.In ste.h
.Ft "char *"
.Fn stecpy "char *dst" "char *end" "const char *src"
.Ft "char *"
.Fn stecpe "char *dst" "char *end" "const char *src" "const char *srcend"
.Ft "char *"
.Fn stechr "const char *src" "const char *end" "int c"
.Ft "char *"
.Fn steprn "char *dst" "char *end" "const char *fmt" "..."
.Sh DESCRIPTION
.Nm libste
provides four useful functions for dealing with strings.
.Pp
.Nm stecpy
copies the NUL-terminated string
.Fa src
to
.Fa dst ,
but writes no characters beyond
.Fa end .
If any characters are copied,
.Fa dst
will be NUL-terminated
and the return value is a pointer to the NUL byte.
On truncation,
.Fa end
is returned.
.Pp
.Nm stecpe
copies the string between
.Fa src
and
.Fa srcend
to
.Fa dst ,
but writes no characters beyond
.Fa end .
If any characters are copied,
.Fa dst
will be NUL-terminated
and the return value is a pointer to the NUL byte.
On truncation,
.Fa end
is returned.
.Pp
.Nm stechr
returns a pointer to the first occurence of
.Fa c
.Pq converted to a Vt char
in the NUL-terminated string pointed to by
.Fa src ,
but reads no characters beyond
.Fa end .
If
.Fa c
is not found,
.Nm
returns a pointer to the first NUL byte in
.Fa src ,
or
.Fa end
if none was found.
.Pp
.Nm steprn
uses
.Xr vsnprintf 3
to write formatted output to
.Fa dst ,
but writes no characters beyond
.Fa end .
If any characters are written,
.Fa dst
will be NUL-terminated
and the return value is a pointer to the NUL byte.
On truncation,
.Fa end
is returned.
.Pp
Note that it is safe to pass the return value of all functions listed above
as argument for
.Fa dst
when the same
.Fa end
is reused.
In this case, the function call does nothing but return
.Fa dst
again.
At any point, truncation can be checked by comparing the return value to
.Fa end .
.\" .Sh RETURN VALUES
.\" .Sh SEE ALSO
.\" .Sh STANDARDS
.\" .Sh HISTORY
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE
.Nm libste
is in the public domain.
.Pp
To the extent possible under law,
the creator of this work
has waived all copyright and related or
neighboring rights to this work.
.Pp
.Lk http://creativecommons.org/publicdomain/zero/1.0/