Skip to content

Commit 51e3bef

Browse files
committed
remove xbps_strl{cat,cpy} and use strl{cat,cpy} directly
1 parent cf5afa8 commit 51e3bef

File tree

26 files changed

+168
-178
lines changed

26 files changed

+168
-178
lines changed

bin/xbps-alternatives/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ main(int argc, char **argv)
230230
memset(&xh, 0, sizeof(xh));
231231
xh.state_cb = state_cb;
232232
if (rootdir)
233-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
233+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
234234
if (confdir)
235-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
235+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
236236

237237
xh.flags = flags;
238238

bin/xbps-checkvers/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ rcv_init(rcv_t *rcv, const char *prog)
113113
assert(rcv->cache);
114114

115115
if (rcv->xbps_conf != NULL) {
116-
xbps_strlcpy(rcv->xhp.confdir, rcv->xbps_conf, sizeof(rcv->xhp.confdir));
116+
strlcpy(rcv->xhp.confdir, rcv->xbps_conf, sizeof(rcv->xhp.confdir));
117117
}
118118
if (rcv->rootdir != NULL) {
119-
xbps_strlcpy(rcv->xhp.rootdir, rcv->rootdir, sizeof(rcv->xhp.rootdir));
119+
strlcpy(rcv->xhp.rootdir, rcv->rootdir, sizeof(rcv->xhp.rootdir));
120120
}
121121
if (xbps_init(&rcv->xhp) != 0)
122122
abort();
@@ -820,8 +820,8 @@ main(int argc, char **argv)
820820
if ((p = strrchr(argv[i], '/')) && (strcmp(p, "/template")) == 0) {
821821
tmpl = argv[i];
822822
} else {
823-
xbps_strlcat(tmp, argv[i], sizeof tmp);
824-
xbps_strlcat(tmp, "/template", sizeof tmp);
823+
strlcat(tmp, argv[i], sizeof tmp);
824+
strlcat(tmp, "/template", sizeof tmp);
825825
tmpl = tmp;
826826
}
827827
rcv_process_file(&rcv, tmpl, rcv_check_version);

bin/xbps-dgraph/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,9 @@ main(int argc, char **argv)
598598
/* Initialize libxbps */
599599
memset(&xh, 0, sizeof(xh));
600600
if (rootdir != NULL)
601-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
601+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
602602
if (confdir)
603-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
603+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
604604

605605
xh.flags = flags;
606606
if ((rv = xbps_init(&xh)) != 0)

bin/xbps-install/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ main(int argc, char **argv)
216216
xh.fetch_cb = fetch_file_progress_cb;
217217
xh.fetch_cb_data = &xfer;
218218
if (rootdir)
219-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
219+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
220220
if (cachedir)
221-
xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
221+
strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
222222
if (confdir)
223-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
223+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
224224
xh.flags = flags;
225225
if (flags & XBPS_FLAG_VERBOSE)
226226
xh.unpack_cb = unpack_progress_cb;

bin/xbps-pkgdb/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ main(int argc, char **argv)
144144

145145
memset(&xh, 0, sizeof(xh));
146146
if (rootdir)
147-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
147+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
148148
if (confdir)
149-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
149+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
150150
xh.flags = flags;
151151

152152
if ((rv = xbps_init(&xh)) != 0) {

bin/xbps-query/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ main(int argc, char **argv)
241241
* Initialize libxbps.
242242
*/
243243
if (rootdir)
244-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
244+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
245245
if (cachedir)
246-
xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
246+
strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
247247
if (confdir)
248-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
248+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
249249

250250
xh.flags = flags;
251251

bin/xbps-reconfigure/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ main(int argc, char **argv)
168168
memset(&xh, 0, sizeof(xh));
169169
xh.state_cb = state_cb;
170170
if (rootdir)
171-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
171+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
172172
if (confdir)
173-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
173+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
174174

175175
xh.flags = flags;
176176

bin/xbps-remove/clean-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int
4343
binpkg_parse(char *buf, size_t bufsz, const char *path, const char **pkgver, const char **arch)
4444
{
4545
char *p;
46-
size_t n = xbps_strlcpy(buf, path, bufsz);
46+
size_t n = strlcpy(buf, path, bufsz);
4747
if (n >= bufsz)
4848
return -ENOBUFS;
4949

bin/xbps-remove/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ main(int argc, char **argv)
251251
memset(&xh, 0, sizeof(xh));
252252
xh.state_cb = state_cb_rm;
253253
if (rootdir)
254-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
254+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
255255
if (cachedir)
256-
xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
256+
strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
257257
if (confdir)
258-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
258+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
259259

260260
xh.flags = flags;
261261

bin/xbps-uhelper/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ main(int argc, char **argv)
146146
xh.fetch_cb_data = &xfer;
147147
xh.flags = flags;
148148
if (rootdir)
149-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
149+
strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
150150
if (confdir)
151-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
151+
strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
152152
if ((rv = xbps_init(&xh)) != 0) {
153153
xbps_error_printf("xbps-uhelper: failed to "
154154
"initialize libxbps: %s.\n", strerror(rv));

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ echo "CC = $CC" >>$CONFIG_MK
195195
echo "CFLAGS = -O2" >>$CONFIG_MK
196196

197197
echo "LDFLAGS = -L\$(TOPDIR)/lib" >>$CONFIG_MK
198-
echo "CPPFLAGS = -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK
198+
echo "CPPFLAGS = -I\$(TOPDIR)/lib/compat -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK
199199
echo "CPPFLAGS += -DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK
200200
echo "CPPFLAGS += -DXBPS_SYSDEFCONF_PATH=\\\"${SHAREDIR}/xbps.d\\\"" >>$CONFIG_MK
201201
echo "CPPFLAGS += -DXBPS_VERSION=\\\"${VERSION}\\\"" >>$CONFIG_MK

include/compat.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@
88

99
#include "macro.h"
1010

11-
#ifndef HAVE_STRLCAT
12-
size_t HIDDEN strlcat(char *, const char *, size_t);
13-
#endif
14-
15-
#ifndef HAVE_STRLCPY
16-
size_t HIDDEN strlcpy(char *, const char *, size_t);
17-
#endif
18-
19-
#ifndef HAVE_STRCASESTR
20-
char HIDDEN *strcasestr(const char *, const char *);
21-
#endif
22-
23-
#ifndef HAVE_VASPRINTF
24-
int HIDDEN vasprintf(char **, const char *, va_list);
25-
#endif
2611

2712
#ifndef HAVE_HUMANIZE_NUMBER
2813
#define HN_DECIMAL 0x01

lib/compat/stdio.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef XBPS_COMPAT_STDIO_H
2+
#define XBPS_COMPAT_STDIO_H
3+
4+
#include_next <stdio.h>
5+
6+
#ifndef HAVE_VASPRINTF
7+
int vasprintf(char **, const char *, va_list);
8+
#endif
9+
10+
#endif /*!XBPS_COMPAT_STDIO_H*/

lib/compat/string.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef XBPS_COMPAT_STRING_H
2+
#define XBPS_COMPAT_STRING_H
3+
4+
#include_next <string.h>
5+
6+
#ifndef HAVE_STRLCAT
7+
size_t strlcat(char *, const char *, size_t);
8+
#endif
9+
10+
#ifndef HAVE_STRLCPY
11+
size_t strlcpy(char *, const char *, size_t);
12+
#endif
13+
14+
#ifndef HAVE_STRCASESTR
15+
char *strcasestr(const char *, const char *);
16+
#endif
17+
18+
#endif /*!XBPS_COMPAT_STRING_H*/

lib/compat/strlcat.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
1+
/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */
22

33
/*
4-
* Copyright (c) 1998 Todd C. Miller <[email protected]>
4+
* Copyright (c) 1998, 2015 Todd C. Miller <[email protected]>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -19,39 +19,37 @@
1919
#include <sys/types.h>
2020
#include <string.h>
2121

22-
#include "compat.h"
23-
2422
/*
25-
* Appends src to string dst of size siz (unlike strncat, siz is the
26-
* full size of dst, not space left). At most siz-1 characters
27-
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
28-
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
29-
* If retval >= siz, truncation occurred.
23+
* Appends src to string dst of size dsize (unlike strncat, dsize is the
24+
* full size of dst, not space left). At most dsize-1 characters
25+
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
26+
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
27+
* If retval >= dsize, truncation occurred.
3028
*/
31-
size_t HIDDEN
32-
strlcat(char *dst, const char *src, size_t siz)
29+
size_t
30+
strlcat(char *dst, const char *src, size_t dsize)
3331
{
34-
char *d = dst;
35-
const char *s = src;
36-
size_t n = siz;
32+
const char *odst = dst;
33+
const char *osrc = src;
34+
size_t n = dsize;
3735
size_t dlen;
3836

39-
/* Find the end of dst and adjust bytes left but don't go past end */
40-
while (n-- != 0 && *d != '\0')
41-
d++;
42-
dlen = d - dst;
43-
n = siz - dlen;
37+
/* Find the end of dst and adjust bytes left but don't go past end. */
38+
while (n-- != 0 && *dst != '\0')
39+
dst++;
40+
dlen = dst - odst;
41+
n = dsize - dlen;
4442

45-
if (n == 0)
46-
return(dlen + strlen(s));
47-
while (*s != '\0') {
48-
if (n != 1) {
49-
*d++ = *s;
43+
if (n-- == 0)
44+
return(dlen + strlen(src));
45+
while (*src != '\0') {
46+
if (n != 0) {
47+
*dst++ = *src;
5048
n--;
5149
}
52-
s++;
50+
src++;
5351
}
54-
*d = '\0';
52+
*dst = '\0';
5553

56-
return(dlen + (s - src)); /* count does not include NUL */
54+
return(dlen + (src - osrc)); /* count does not include NUL */
5755
}

lib/compat/strlcpy.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
1+
/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
22

33
/*
4-
* Copyright (c) 1998 Todd C. Miller <[email protected]>
4+
* Copyright (c) 1998, 2015 Todd C. Miller <[email protected]>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -19,35 +19,32 @@
1919
#include <sys/types.h>
2020
#include <string.h>
2121

22-
#include "compat.h"
23-
2422
/*
25-
* Copy src to string dst of size siz. At most siz-1 characters
26-
* will be copied. Always NUL terminates (unless siz == 0).
27-
* Returns strlen(src); if retval >= siz, truncation occurred.
23+
* Copy string src to buffer dst of size dsize. At most dsize-1
24+
* chars will be copied. Always NUL terminates (unless dsize == 0).
25+
* Returns strlen(src); if retval >= dsize, truncation occurred.
2826
*/
29-
size_t HIDDEN
30-
strlcpy(char *dst, const char *src, size_t siz)
27+
size_t
28+
strlcpy(char *dst, const char *src, size_t dsize)
3129
{
32-
char *d = dst;
33-
const char *s = src;
34-
size_t n = siz;
30+
const char *osrc = src;
31+
size_t nleft = dsize;
3532

36-
/* Copy as many bytes as will fit */
37-
if (n != 0) {
38-
while (--n != 0) {
39-
if ((*d++ = *s++) == '\0')
33+
/* Copy as many bytes as will fit. */
34+
if (nleft != 0) {
35+
while (--nleft != 0) {
36+
if ((*dst++ = *src++) == '\0')
4037
break;
4138
}
4239
}
4340

44-
/* Not enough room in dst, add NUL and traverse rest of src */
45-
if (n == 0) {
46-
if (siz != 0)
47-
*d = '\0'; /* NUL-terminate dst */
48-
while (*s++)
41+
/* Not enough room in dst, add NUL and traverse rest of src. */
42+
if (nleft == 0) {
43+
if (dsize != 0)
44+
*dst = '\0'; /* NUL-terminate dst */
45+
while (*src++)
4946
;
5047
}
5148

52-
return(s - src - 1); /* count does not include NUL */
49+
return(src - osrc - 1); /* count does not include NUL */
5350
}

lib/conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ store_preserved_file(struct xbps_handle *xhp, const char *file)
109109
len = strlen(globbuf.gl_pathv[i]) - strlen(xhp->rootdir) + 1;
110110
p = malloc(len);
111111
assert(p);
112-
xbps_strlcpy(p, globbuf.gl_pathv[i] + strlen(xhp->rootdir), len);
112+
strlcpy(p, globbuf.gl_pathv[i] + strlen(xhp->rootdir), len);
113113
xbps_array_add_cstring(xhp->preserved_files, p);
114114
xbps_dbg_printf("Added preserved file: %s (expanded from %s)\n", p, file);
115115
free(p);

lib/download.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
122122

123123
memset(&fetch_flags, 0, sizeof(fetch_flags));
124124
if (flags != NULL)
125-
xbps_strlcpy(fetch_flags, flags, 7);
125+
strlcpy(fetch_flags, flags, 7);
126126

127127
tempfile = xbps_xasprintf("%s.part", filename);
128128
/*
@@ -145,7 +145,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
145145
if (stat(filename, &st) == 0) {
146146
refetch = true;
147147
url->last_modified = st.st_mtime;
148-
xbps_strlcat(fetch_flags, "i", sizeof(fetch_flags));
148+
strlcat(fetch_flags, "i", sizeof(fetch_flags));
149149
} else {
150150
if (errno != ENOENT) {
151151
rv = -1;

lib/external/dewey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ dewey_match(const char *pattern, const char *pkg)
331331
if (sep2) {
332332
char ver[PKG_PATTERN_MAX];
333333

334-
xbps_strlcpy(ver, sep, MIN((ssize_t)sizeof(ver), sep2-sep+1));
334+
strlcpy(ver, sep, MIN((ssize_t)sizeof(ver), sep2-sep+1));
335335
if (dewey_cmp(version, op, ver))
336336
return 1;
337337
} else {

lib/initend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ xbps_init(struct xbps_handle *xhp)
114114

115115
/* allow to overwrite uname(3) and conf file with env variable */
116116
if ((native_arch = getenv("XBPS_ARCH")) && *native_arch != '\0') {
117-
if (xbps_strlcpy(xhp->native_arch, native_arch,
117+
if (strlcpy(xhp->native_arch, native_arch,
118118
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
119119
return ENOBUFS;
120120
}
@@ -123,7 +123,7 @@ xbps_init(struct xbps_handle *xhp)
123123
struct utsname un;
124124
if (uname(&un) == -1)
125125
return ENOTSUP;
126-
if (xbps_strlcpy(xhp->native_arch, un.machine,
126+
if (strlcpy(xhp->native_arch, un.machine,
127127
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
128128
return ENOBUFS;
129129
}

0 commit comments

Comments
 (0)