]>
jfr.im git - solanum.git/blob - libltdl/lt__strl.c
1 /* lt__strl.c -- size-bounded string copying and concatenation
3 Copyright (C) 2004 Free Software Foundation, Inc.
4 Written by Bob Friesenhahn, 2004
6 NOTE: The canonical source of this file is maintained with the
7 GNU Libtool package. Report bugs to bug-libtool@gnu.org.
9 GNU Libltdl is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 As a special exception to the GNU Lesser General Public License,
15 if you distribute this file as part of a program or library that
16 is built using GNU Libtool, you may include this file under the
17 same distribution terms that you use for the rest of that program.
19 GNU Libltdl is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with GNU Libltdl; see the file COPYING.LIB. If not, a
26 copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
27 or obtained by writing to the Free Software Foundation, Inc.,
28 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37 lt_strlcat appends the NULL-terminated string src to the end of dst.
38 It will append at most dstsize - strlen(dst) - 1 bytes,
39 NULL-terminating the result. The total length of the string which
40 would have been created given sufficient buffer size (may be longer
41 than dstsize) is returned. This function substitutes for strlcat()
42 which is available under NetBSD, FreeBSD and Solaris 9.
44 Buffer overflow can be checked as follows:
46 if (lt_strlcat(dst, src, dstsize) >= dstsize)
49 #if !defined(HAVE_STRLCAT)
51 lt_strlcat(char *dst
, const char *src
, const size_t dstsize
)
58 assert(src
!= (const char *) NULL
);
64 Copy remaining characters from src while constraining length to
67 for ( p
= dst
+ length
, q
= src
;
68 (*q
!= 0) && (length
< dstsize
- 1) ;
75 Add remaining length of src to length.
82 #endif /* !defined(HAVE_STRLCAT) */
85 lt_strlcpy copies up to dstsize - 1 characters from the NULL-terminated
86 string src to dst, NULL-terminating the result. The total length of
87 the string which would have been created given sufficient buffer
88 size (may be longer than dstsize) is returned. This function
89 substitutes for strlcpy() which is available under OpenBSD, FreeBSD
92 Buffer overflow can be checked as follows:
94 if (lt_strlcpy(dst, src, dstsize) >= dstsize)
97 #if !defined(HAVE_STRLCPY)
99 lt_strlcpy(char *dst
, const char *src
, const size_t dstsize
)
106 assert(src
!= (const char *) NULL
);
107 assert(dstsize
>= 1);
110 Copy src to dst within bounds of size-1.
112 for ( p
=dst
, q
=src
, length
=0 ;
113 (*q
!= 0) && (length
< dstsize
-1) ;
120 Add remaining length of src to length.
127 #endif /* !defined(HAVE_STRLCPY) */