Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c xfuncs.c xfuncs.h
Date: Sat, 31 Jan 2009 17:58:40
Message-Id: E1LTK73-0007yT-Tr@stork.gentoo.org
1 grobian 09/01/31 17:58:37
2
3 Modified: scanelf.c xfuncs.c xfuncs.h
4 Log:
5 For bug #249731, add an xstrndup wrapper, and implement strndup on hosts that don't have it, based on the strndup implementation of sandbox, with a little change to make it C90 compliant.
6
7 Revision Changes Path
8 1.208 pax-utils/scanelf.c
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.208&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.208&content-type=text/plain
12 diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?r1=1.207&r2=1.208
13
14 Index: scanelf.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
17 retrieving revision 1.207
18 retrieving revision 1.208
19 diff -u -r1.207 -r1.208
20 --- scanelf.c 30 Dec 2008 13:38:35 -0000 1.207
21 +++ scanelf.c 31 Jan 2009 17:58:37 -0000 1.208
22 @@ -1,13 +1,13 @@
23 /*
24 * Copyright 2003-2007 Gentoo Foundation
25 * Distributed under the terms of the GNU General Public License v2
26 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.207 2008/12/30 13:38:35 vapier Exp $
27 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.208 2009/01/31 17:58:37 grobian Exp $
28 *
29 * Copyright 2003-2007 Ned Ludd - <solar@g.o>
30 * Copyright 2004-2007 Mike Frysinger - <vapier@g.o>
31 */
32
33 -static const char *rcsid = "$Id: scanelf.c,v 1.207 2008/12/30 13:38:35 vapier Exp $";
34 +static const char *rcsid = "$Id: scanelf.c,v 1.208 2009/01/31 17:58:37 grobian Exp $";
35 const char * const argv0 = "scanelf";
36
37 #include "paxinc.h"
38 @@ -1038,7 +1038,7 @@
39 ++this_sym; \
40 } \
41 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \
42 - this_sym = strndup(this_sym, next_sym-this_sym); \
43 + this_sym = xstrndup(this_sym, next_sym-this_sym); \
44 /* ok, lets compare the name now */ \
45 if (scanelf_match_symname(this_sym, symname)) { \
46 if (be_semi_verbose) { \
47
48
49
50 1.4 pax-utils/xfuncs.c
51
52 file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?rev=1.4&view=markup
53 plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?rev=1.4&content-type=text/plain
54 diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?r1=1.3&r2=1.4
55
56 Index: xfuncs.c
57 ===================================================================
58 RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v
59 retrieving revision 1.3
60 retrieving revision 1.4
61 diff -u -r1.3 -r1.4
62 --- xfuncs.c 30 Dec 2008 13:00:29 -0000 1.3
63 +++ xfuncs.c 31 Jan 2009 17:58:37 -0000 1.4
64 @@ -1,7 +1,7 @@
65 /*
66 * Copyright 2003-2007 Gentoo Foundation
67 * Distributed under the terms of the GNU General Public License v2
68 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.3 2008/12/30 13:00:29 vapier Exp $
69 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.4 2009/01/31 17:58:37 grobian Exp $
70 *
71 * Copyright 2003-2007 Ned Ludd - <solar@g.o>
72 * Copyright 2004-2007 Mike Frysinger - <vapier@g.o>
73 @@ -16,6 +16,32 @@
74 return ret;
75 }
76
77 +#ifndef strndup
78 +static inline char *my_strndup(const char *str, size_t n)
79 +{
80 + size_t r;
81 + char *ret;
82 + for (r = 0; r < n; ++r)
83 + if (!str[r])
84 + break;
85 +
86 + ret = xmalloc(r + 1);
87 + memcpy(ret, str, r);
88 + ret[r] = '\0';
89 + return ret;
90 +}
91 +/* do this to avoid warning: declaration of 'strndup' shadows a built-in
92 + * function */
93 +#define strndup(S, N) my_strndup(S, N)
94 +#endif
95 +
96 +char *xstrndup(const char *s, const size_t n)
97 +{
98 + char *ret = strndup(s, n);
99 + if (!ret) err("Could not strdup(): %s", strerror(errno));
100 + return ret;
101 +}
102 +
103 void *xmalloc(size_t size)
104 {
105 void *ret = malloc(size);
106
107
108
109 1.3 pax-utils/xfuncs.h
110
111 file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?rev=1.3&view=markup
112 plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?rev=1.3&content-type=text/plain
113 diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?r1=1.2&r2=1.3
114
115 Index: xfuncs.h
116 ===================================================================
117 RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v
118 retrieving revision 1.2
119 retrieving revision 1.3
120 diff -u -r1.2 -r1.3
121 --- xfuncs.h 30 Dec 2008 12:58:08 -0000 1.2
122 +++ xfuncs.h 31 Jan 2009 17:58:37 -0000 1.3
123 @@ -1,7 +1,7 @@
124 /*
125 * Copyright 2003-2007 Gentoo Foundation
126 * Distributed under the terms of the GNU General Public License v2
127 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.2 2008/12/30 12:58:08 vapier Exp $
128 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.3 2009/01/31 17:58:37 grobian Exp $
129 *
130 * Copyright 2003-2007 Ned Ludd - <solar@g.o>
131 * Copyright 2004-2007 Mike Frysinger - <vapier@g.o>
132 @@ -11,6 +11,7 @@
133 #define __XFUNCS_H__
134
135 char *xstrdup(const char *s);
136 +char *xstrndup(const char *s, const size_t n);
137 void *xmalloc(size_t size);
138 void *xzalloc(size_t size);
139 void *xrealloc(void *ptr, size_t size);