1 |
vapier 11/02/21 07:33:22 |
2 |
|
3 |
Modified: colors.c libq.h virtuals.c |
4 |
Log: |
5 |
convert many fgets() to getline(), clean up ARRAY_SIZE usage, and some other random fixes |
6 |
|
7 |
Revision Changes Path |
8 |
1.10 portage-utils/libq/colors.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/colors.c?rev=1.10&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/colors.c?rev=1.10&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/colors.c?r1=1.9&r2=1.10 |
13 |
|
14 |
Index: colors.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/colors.c,v |
17 |
retrieving revision 1.9 |
18 |
retrieving revision 1.10 |
19 |
diff -u -r1.9 -r1.10 |
20 |
--- colors.c 23 May 2007 13:47:31 -0000 1.9 |
21 |
+++ colors.c 21 Feb 2011 07:33:22 -0000 1.10 |
22 |
@@ -20,10 +20,6 @@ |
23 |
|
24 |
static const char *COLOR_MAP = "/etc/portage/color.map"; |
25 |
|
26 |
-#ifndef ARR_SIZE |
27 |
-# define ARR_SIZE(arr) (sizeof(arr) / sizeof(*arr)) |
28 |
-#endif |
29 |
- |
30 |
#define COLOR _MAKE_COLOR |
31 |
|
32 |
typedef struct { |
33 |
@@ -54,14 +50,16 @@ |
34 |
{ |
35 |
FILE *fp; |
36 |
int i; |
37 |
- char buf[512]; |
38 |
+ size_t buflen; |
39 |
+ char *buf; |
40 |
char *p; |
41 |
int lineno = 0; |
42 |
|
43 |
if ((fp = fopen(COLOR_MAP, "r")) == NULL) |
44 |
return; |
45 |
|
46 |
- while (fgets(buf, sizeof(buf), fp) != NULL) { |
47 |
+ buf = NULL; |
48 |
+ while (getline(&buf, &buflen, fp) != -1) { |
49 |
lineno++; |
50 |
/* eat comments */ |
51 |
if ((p = strchr(buf, '#')) != NULL) |
52 |
@@ -78,7 +76,7 @@ |
53 |
|
54 |
p = strchr(buf, '='); |
55 |
*p++ = 0; /* split the pair */ |
56 |
- for (i = 0; i < ARR_SIZE(color_pairs); ++i) |
57 |
+ for (i = 0; i < ARRAY_SIZE(color_pairs); ++i) |
58 |
if (strcmp(buf, color_pairs[i].name) == 0) { |
59 |
if (strncmp(p, "0x", 2) == 0) |
60 |
warn("[%s=%s] RGB values in color map are not supported on line %d of %s", buf, p, lineno, COLOR_MAP); |
61 |
@@ -86,9 +84,11 @@ |
62 |
snprintf(color_pairs[i].value, sizeof(color_pairs[i].value), "\e[%s", p); |
63 |
} |
64 |
} |
65 |
+ |
66 |
+ free(buf); |
67 |
fclose(fp); |
68 |
|
69 |
- for (i = 0; i < ARR_SIZE(color_pairs); ++i) { |
70 |
+ for (i = 0; i < ARRAY_SIZE(color_pairs); ++i) { |
71 |
/* unmapped: MAGENTA YELLOW */ |
72 |
if (strcmp(color_pairs[i].name, "white") == 0) |
73 |
WHITE = color_pairs[i].value; |
74 |
|
75 |
|
76 |
|
77 |
1.6 portage-utils/libq/libq.h |
78 |
|
79 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.h?rev=1.6&view=markup |
80 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.h?rev=1.6&content-type=text/plain |
81 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.h?r1=1.5&r2=1.6 |
82 |
|
83 |
Index: libq.h |
84 |
=================================================================== |
85 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/libq.h,v |
86 |
retrieving revision 1.5 |
87 |
retrieving revision 1.6 |
88 |
diff -u -r1.5 -r1.6 |
89 |
--- libq.h 13 Jan 2010 14:02:35 -0000 1.5 |
90 |
+++ libq.h 21 Feb 2011 07:33:22 -0000 1.6 |
91 |
@@ -18,7 +18,7 @@ |
92 |
#define errf(fmt, args...) _err(warnf, fmt , ## args) |
93 |
#define errp(fmt, args...) _err(warnp, fmt , ## args) |
94 |
#define errfp(fmt, args...) _err(warnfp, fmt, ## args) |
95 |
-#define ARR_SIZE(arr) (sizeof(arr) / sizeof(*arr)) |
96 |
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr)) |
97 |
|
98 |
#ifndef BUFSIZE |
99 |
# define BUFSIZE 8192 |
100 |
|
101 |
|
102 |
|
103 |
1.24 portage-utils/libq/virtuals.c |
104 |
|
105 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?rev=1.24&view=markup |
106 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?rev=1.24&content-type=text/plain |
107 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?r1=1.23&r2=1.24 |
108 |
|
109 |
Index: virtuals.c |
110 |
=================================================================== |
111 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v |
112 |
retrieving revision 1.23 |
113 |
retrieving revision 1.24 |
114 |
diff -u -r1.23 -r1.24 |
115 |
--- virtuals.c 7 Apr 2010 05:58:16 -0000 1.23 |
116 |
+++ virtuals.c 21 Feb 2011 07:33:22 -0000 1.24 |
117 |
@@ -1,12 +1,12 @@ |
118 |
/* |
119 |
* Copyright 2005-2010 Gentoo Foundation |
120 |
* Distributed under the terms of the GNU General Public License v2 |
121 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.23 2010/04/07 05:58:16 solar Exp $ |
122 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.24 2011/02/21 07:33:22 vapier Exp $ |
123 |
* |
124 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
125 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
126 |
* |
127 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.23 2010/04/07 05:58:16 solar Exp $ |
128 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.24 2011/02/21 07:33:22 vapier Exp $ |
129 |
*/ |
130 |
|
131 |
#include <stdio.h> |
132 |
@@ -152,7 +152,7 @@ |
133 |
{ |
134 |
DIR *dir, *dirp; |
135 |
struct dirent *dentry_cat, *dentry_pkg; |
136 |
- char buf[BUFSIZE]; |
137 |
+ char buf[_Q_PATH_MAX]; |
138 |
depend_atom *atom; |
139 |
|
140 |
xchdir("/"); |
141 |
@@ -169,84 +169,84 @@ |
142 |
|
143 |
/* scan all the packages in this category */ |
144 |
while ((dentry_pkg = q_vdb_get_next_dir(dirp)) != NULL) { |
145 |
- FILE *fp; |
146 |
char *p; |
147 |
/* see if user wants any of these packages */ |
148 |
snprintf(buf, sizeof(buf), "%s/%s/%s/PROVIDE", vdb, dentry_cat->d_name, dentry_pkg->d_name); |
149 |
- if ((fp = fopen(buf, "r")) != NULL) { |
150 |
- if (fgets(buf, sizeof(buf), fp) == NULL) |
151 |
- buf[0] = '\0'; |
152 |
|
153 |
- if ((p = strrchr(buf, '\n')) != NULL) |
154 |
- *p = 0; |
155 |
+ if (!eat_file(buf, buf, sizeof(buf))) |
156 |
+ continue; |
157 |
|
158 |
- rmspace(buf); |
159 |
+ if ((p = strrchr(buf, '\n')) != NULL) |
160 |
+ *p = 0; |
161 |
+ |
162 |
+ rmspace(buf); |
163 |
|
164 |
- if (*buf) { |
165 |
- int ok = 0; |
166 |
- char *v, *tmp = xstrdup(buf); |
167 |
- snprintf(buf, sizeof(buf), "%s/%s", dentry_cat->d_name, dentry_pkg->d_name); |
168 |
- |
169 |
- atom = atom_explode(buf); |
170 |
- if (!atom) { |
171 |
- warn("could not explode '%s'", buf); |
172 |
- continue; |
173 |
- } |
174 |
- sprintf(buf, "%s/%s", atom->CATEGORY, atom->PN); |
175 |
- if ((v = virtual(tmp, virtuals)) != NULL) { |
176 |
- /* IF_DEBUG(fprintf(stderr, "%s provided by %s (removing)\n", tmp, v)); */ |
177 |
- virtuals = del_set(tmp, virtuals, &ok); |
178 |
- } |
179 |
- virtuals = add_set(tmp, buf, virtuals); |
180 |
- /* IF_DEBUG(fprintf(stderr, "%s provided by %s/%s (adding)\n", tmp, atom->CATEGORY, dentry_pkg->d_name)); */ |
181 |
- free(tmp); |
182 |
- atom_implode(atom); |
183 |
+ if (*buf) { |
184 |
+ int ok = 0; |
185 |
+ char *v, *tmp = xstrdup(buf); |
186 |
+ snprintf(buf, sizeof(buf), "%s/%s", dentry_cat->d_name, dentry_pkg->d_name); |
187 |
+ |
188 |
+ atom = atom_explode(buf); |
189 |
+ if (!atom) { |
190 |
+ warn("could not explode '%s'", buf); |
191 |
+ continue; |
192 |
} |
193 |
- fclose(fp); |
194 |
+ sprintf(buf, "%s/%s", atom->CATEGORY, atom->PN); |
195 |
+ if ((v = virtual(tmp, virtuals)) != NULL) { |
196 |
+ /* IF_DEBUG(fprintf(stderr, "%s provided by %s (removing)\n", tmp, v)); */ |
197 |
+ virtuals = del_set(tmp, virtuals, &ok); |
198 |
+ } |
199 |
+ virtuals = add_set(tmp, buf, virtuals); |
200 |
+ /* IF_DEBUG(fprintf(stderr, "%s provided by %s/%s (adding)\n", tmp, atom->CATEGORY, dentry_pkg->d_name)); */ |
201 |
+ free(tmp); |
202 |
+ atom_implode(atom); |
203 |
} |
204 |
} |
205 |
} |
206 |
+ |
207 |
return virtuals; |
208 |
} |
209 |
|
210 |
-static queue *resolve_local_profile_virtuals(); |
211 |
-static queue *resolve_local_profile_virtuals() |
212 |
+static queue *resolve_local_profile_virtuals(void) |
213 |
{ |
214 |
- char buf[BUFSIZ]; |
215 |
+ static size_t buflen; |
216 |
+ static char *buf = NULL; |
217 |
FILE *fp; |
218 |
char *p; |
219 |
- char *paths[] = { (char *) "/etc/portage/profile/virtuals", (char *) "/etc/portage/virtuals" }; |
220 |
+ static const char * const paths[] = { "/etc/portage/profile/virtuals", "/etc/portage/virtuals" }; |
221 |
size_t i; |
222 |
|
223 |
- for (i = 0; i < sizeof(paths)/sizeof(paths[0]); i++) { |
224 |
- if ((fp = fopen(paths[i], "r")) != NULL) { |
225 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
226 |
- if (*buf != 'v') continue; |
227 |
- for (p = buf; *p != 0; ++p) if (isspace(*p)) *p = ' '; |
228 |
- if ((p = strchr(buf, ' ')) != NULL) { |
229 |
- int ok = 0; |
230 |
- *p = 0; |
231 |
- virtuals = del_set(buf, virtuals, &ok); |
232 |
- virtuals = add_set(buf, rmspace(++p), virtuals); |
233 |
- ok = 0; |
234 |
- } |
235 |
+ for (i = 0; i < ARRAY_SIZE(paths); ++i) { |
236 |
+ fp = fopen(paths[i], "r"); |
237 |
+ if (!fp) |
238 |
+ continue; |
239 |
+ |
240 |
+ while (getline(&buf, &buflen, fp) != -1) { |
241 |
+ if (*buf != 'v') |
242 |
+ continue; |
243 |
+ rmspace(buf); |
244 |
+ if ((p = strchr(buf, ' ')) != NULL) { |
245 |
+ int ok = 0; |
246 |
+ *p = 0; |
247 |
+ virtuals = del_set(buf, virtuals, &ok); |
248 |
+ virtuals = add_set(buf, rmspace(++p), virtuals); |
249 |
+ ok = 0; |
250 |
} |
251 |
- fclose(fp); |
252 |
} |
253 |
+ |
254 |
+ fclose(fp); |
255 |
} |
256 |
+ |
257 |
return virtuals; |
258 |
} |
259 |
|
260 |
-static queue *resolve_virtuals(); |
261 |
-static queue *resolve_virtuals() |
262 |
+static queue *resolve_virtuals(void) |
263 |
{ |
264 |
- static char buf[BUFSIZ]; |
265 |
- static char savecwd[_POSIX_PATH_MAX]; |
266 |
+ static char buf[_Q_PATH_MAX]; |
267 |
+ static char savecwd[_Q_PATH_MAX]; |
268 |
static char *p; |
269 |
FILE *fp; |
270 |
|
271 |
- memset(buf, 0, sizeof(buf)); |
272 |
- |
273 |
xgetcwd(savecwd, sizeof(savecwd)); |
274 |
|
275 |
free_sets(virtuals); |
276 |
@@ -265,7 +265,7 @@ |
277 |
if ((fp = fopen("virtuals", "r")) != NULL) { |
278 |
while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
279 |
if (*buf != 'v') continue; |
280 |
- for (p = buf; *p != 0; ++p) if (isspace(*p)) *p = ' '; |
281 |
+ rmspace(buf); |
282 |
if ((p = strchr(buf, ' ')) != NULL) { |
283 |
*p = 0; |
284 |
if (virtual(buf, virtuals) == NULL) |