1 |
vapier 11/02/21 07:33:22 |
2 |
|
3 |
Modified: main.c main.h qcache.c qfile.c qlist.c qlop.c |
4 |
qpkg.c qsize.c quse.c |
5 |
Log: |
6 |
convert many fgets() to getline(), clean up ARRAY_SIZE usage, and some other random fixes |
7 |
|
8 |
Revision Changes Path |
9 |
1.182 portage-utils/main.c |
10 |
|
11 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.182&view=markup |
12 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.182&content-type=text/plain |
13 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?r1=1.181&r2=1.182 |
14 |
|
15 |
Index: main.c |
16 |
=================================================================== |
17 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/main.c,v |
18 |
retrieving revision 1.181 |
19 |
retrieving revision 1.182 |
20 |
diff -u -r1.181 -r1.182 |
21 |
--- main.c 21 Feb 2011 06:20:24 -0000 1.181 |
22 |
+++ main.c 21 Feb 2011 07:33:21 -0000 1.182 |
23 |
@@ -1,7 +1,7 @@ |
24 |
/* |
25 |
* Copyright 2005-2008 Gentoo Foundation |
26 |
* Distributed under the terms of the GNU General Public License v2 |
27 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.181 2011/02/21 06:20:24 vapier Exp $ |
28 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.182 2011/02/21 07:33:21 vapier Exp $ |
29 |
* |
30 |
* Copyright 2005-2008 Ned Ludd - <solar@g.o> |
31 |
* Copyright 2005-2008 Mike Frysinger - <vapier@g.o> |
32 |
@@ -203,6 +203,34 @@ |
33 |
return ret; |
34 |
} |
35 |
|
36 |
+#if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) |
37 |
+static ssize_t getline(char **line, size_t *len, FILE *fp) |
38 |
+{ |
39 |
+ char *s; |
40 |
+ size_t off; |
41 |
+ |
42 |
+ if (!*line) { |
43 |
+ *len = BUFSIZE; |
44 |
+ *line = xmalloc(*len); |
45 |
+ } |
46 |
+ |
47 |
+ off = 0; |
48 |
+ while (1) { |
49 |
+ s = fgets(*line + off, *len - off, fp); |
50 |
+ if (s == NULL) |
51 |
+ return -1; |
52 |
+ |
53 |
+ s = strchr(s, '\n'); |
54 |
+ if (s) |
55 |
+ break; |
56 |
+ |
57 |
+ off = *len; |
58 |
+ *len += BUFSIZE; |
59 |
+ *line = xrealloc(*line, *len); |
60 |
+ } |
61 |
+} |
62 |
+#endif |
63 |
+ |
64 |
static bool prompt(const char *p) |
65 |
{ |
66 |
printf("%s? [Y/n] ", p); |
67 |
@@ -498,9 +526,9 @@ |
68 |
/* Helper to read a portage env file (e.g. make.conf) */ |
69 |
static void read_portage_env_file(const char *file, const env_vars vars[]) |
70 |
{ |
71 |
- size_t i; |
72 |
+ size_t i, buflen, line; |
73 |
FILE *fp; |
74 |
- char buf[BUFSIZE], *s, *p; |
75 |
+ char *buf, *s, *p; |
76 |
|
77 |
IF_DEBUG(fprintf(stderr, "profile %s\n", file)); |
78 |
|
79 |
@@ -508,7 +536,10 @@ |
80 |
if (fp == NULL) |
81 |
return; |
82 |
|
83 |
- while (fgets(buf, sizeof(buf), fp) != NULL) { |
84 |
+ line = 0; |
85 |
+ buf = NULL; |
86 |
+ while (getline(&buf, &buflen, fp) != -1) { |
87 |
+ ++line; |
88 |
rmspace(buf); |
89 |
if (*buf == '#' || *buf == '\0') |
90 |
continue; |
91 |
@@ -538,7 +569,7 @@ |
92 |
/* If the last char is not a quote, then we span lines */ |
93 |
char *q = s + l + 1, *qq = NULL; |
94 |
q[-1] = ' '; |
95 |
- while (fgets(q, sizeof(buf) - (s - buf), fp) != NULL) { |
96 |
+ while (fgets(q, buflen - (s - buf), fp) != NULL) { |
97 |
l = strlen(q); |
98 |
qq = strchr(q, *s); |
99 |
if (qq) { |
100 |
@@ -547,7 +578,7 @@ |
101 |
} |
102 |
} |
103 |
if (!qq) |
104 |
- warn("%s: %s: quote mismatch", file, vars[i].name); |
105 |
+ warn("%s:%zu: %s: quote mismatch", file, line, vars[i].name); |
106 |
++s; |
107 |
} else { |
108 |
s[l - 1] = '\0'; |
109 |
@@ -559,6 +590,7 @@ |
110 |
} |
111 |
} |
112 |
|
113 |
+ free(buf); |
114 |
fclose(fp); |
115 |
} |
116 |
|
117 |
@@ -642,7 +674,7 @@ |
118 |
read_portage_profile(EPREFIX "/etc/portage/make.profile", vars_to_read); |
119 |
|
120 |
/* now read all the config files */ |
121 |
- for (i = 0; i < ARR_SIZE(files); ++i) |
122 |
+ for (i = 0; i < ARRAY_SIZE(files); ++i) |
123 |
read_portage_env_file(files[i], vars_to_read); |
124 |
|
125 |
/* finally, check the env */ |
126 |
|
127 |
|
128 |
|
129 |
1.6 portage-utils/main.h |
130 |
|
131 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.h?rev=1.6&view=markup |
132 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.h?rev=1.6&content-type=text/plain |
133 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.h?r1=1.5&r2=1.6 |
134 |
|
135 |
Index: main.h |
136 |
=================================================================== |
137 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/main.h,v |
138 |
retrieving revision 1.5 |
139 |
retrieving revision 1.6 |
140 |
diff -u -r1.5 -r1.6 |
141 |
--- main.h 7 Apr 2010 05:58:16 -0000 1.5 |
142 |
+++ main.h 21 Feb 2011 07:33:21 -0000 1.6 |
143 |
@@ -1,7 +1,7 @@ |
144 |
/* |
145 |
* Copyright 2005-2010 Gentoo Foundation |
146 |
* Distributed under the terms of the GNU General Public License v2 |
147 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.h,v 1.5 2010/04/07 05:58:16 solar Exp $ |
148 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.h,v 1.6 2011/02/21 07:33:21 vapier Exp $ |
149 |
* |
150 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
151 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
152 |
@@ -16,8 +16,6 @@ |
153 |
# define _Q_PATH_MAX _POSIX_PATH_MAX |
154 |
#endif |
155 |
|
156 |
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr)) |
157 |
- |
158 |
/* http://tinderbox.dev.gentoo.org/default-linux/arm */ |
159 |
/* http://tinderbox.dev.gentoo.org/default-linux/hppa */ |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
1.39 portage-utils/qcache.c |
165 |
|
166 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qcache.c?rev=1.39&view=markup |
167 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qcache.c?rev=1.39&content-type=text/plain |
168 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qcache.c?r1=1.38&r2=1.39 |
169 |
|
170 |
Index: qcache.c |
171 |
=================================================================== |
172 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qcache.c,v |
173 |
retrieving revision 1.38 |
174 |
retrieving revision 1.39 |
175 |
diff -u -r1.38 -r1.39 |
176 |
--- qcache.c 21 Feb 2011 01:33:47 -0000 1.38 |
177 |
+++ qcache.c 21 Feb 2011 07:33:21 -0000 1.39 |
178 |
@@ -1,7 +1,7 @@ |
179 |
/* |
180 |
* Copyright 2005-2010 Gentoo Foundation |
181 |
* Distributed under the terms of the GNU General Public License v2 |
182 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qcache.c,v 1.38 2011/02/21 01:33:47 vapier Exp $ |
183 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qcache.c,v 1.39 2011/02/21 07:33:21 vapier Exp $ |
184 |
* |
185 |
* Copyright 2006 Thomas A. Cort - <tcort@g.o> |
186 |
*/ |
187 |
@@ -47,7 +47,7 @@ |
188 |
COMMON_OPTS_HELP |
189 |
}; |
190 |
|
191 |
-static const char qcache_rcsid[] = "$Id: qcache.c,v 1.38 2011/02/21 01:33:47 vapier Exp $"; |
192 |
+static const char qcache_rcsid[] = "$Id: qcache.c,v 1.39 2011/02/21 07:33:21 vapier Exp $"; |
193 |
#define qcache_usage(ret) usage(ret, QCACHE_FLAGS, qcache_long_opts, qcache_opts_help, lookup_applet_idx("qcache")) |
194 |
|
195 |
/********************************************************************/ |
196 |
@@ -329,10 +329,10 @@ |
197 |
portage_cache *qcache_read_cache_file(const char *filename) |
198 |
{ |
199 |
struct stat s; |
200 |
- char *ptr, buf[BUFSIZE]; |
201 |
+ char *ptr, *buf; |
202 |
FILE *f; |
203 |
portage_cache *ret = NULL; |
204 |
- size_t len; |
205 |
+ size_t len, buflen; |
206 |
|
207 |
if ((f = fopen(filename, "r")) == NULL) |
208 |
goto err; |
209 |
@@ -345,7 +345,7 @@ |
210 |
len = sizeof(*ret) + s.st_size + 1; |
211 |
ret = xzalloc(len); |
212 |
|
213 |
- while ((fgets(buf, sizeof(buf), f)) != NULL) { |
214 |
+ while (getline(&buf, &buflen, f) != -1) { |
215 |
if ((ptr = strrchr(buf, '\n')) != NULL) |
216 |
*ptr = 0; |
217 |
|
218 |
@@ -389,6 +389,7 @@ |
219 |
ret->SRC_URI = xstrdup(buf + 8); |
220 |
} |
221 |
|
222 |
+ free(buf); |
223 |
ret->atom = atom_explode(filename); |
224 |
fclose(f); |
225 |
|
226 |
|
227 |
|
228 |
|
229 |
1.55 portage-utils/qfile.c |
230 |
|
231 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.55&view=markup |
232 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.55&content-type=text/plain |
233 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.54&r2=1.55 |
234 |
|
235 |
Index: qfile.c |
236 |
=================================================================== |
237 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v |
238 |
retrieving revision 1.54 |
239 |
retrieving revision 1.55 |
240 |
diff -u -r1.54 -r1.55 |
241 |
--- qfile.c 21 Feb 2011 01:33:47 -0000 1.54 |
242 |
+++ qfile.c 21 Feb 2011 07:33:21 -0000 1.55 |
243 |
@@ -1,7 +1,7 @@ |
244 |
/* |
245 |
* Copyright 2005-2010 Gentoo Foundation |
246 |
* Distributed under the terms of the GNU General Public License v2 |
247 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.54 2011/02/21 01:33:47 vapier Exp $ |
248 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.55 2011/02/21 07:33:21 vapier Exp $ |
249 |
* |
250 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
251 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
252 |
@@ -34,7 +34,7 @@ |
253 |
"Display installed packages with slots", |
254 |
COMMON_OPTS_HELP |
255 |
}; |
256 |
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.54 2011/02/21 01:33:47 vapier Exp $"; |
257 |
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.55 2011/02/21 07:33:21 vapier Exp $"; |
258 |
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile")) |
259 |
|
260 |
#define qfile_is_prefix(path, prefix, prefix_length) \ |
261 |
@@ -68,8 +68,8 @@ |
262 |
DIR *dir; |
263 |
struct dirent *dentry; |
264 |
const char *base; |
265 |
- char *p; |
266 |
- char buf[1024]; |
267 |
+ size_t buflen; |
268 |
+ char *p, *buf; |
269 |
char pkg[150]; |
270 |
depend_atom *atom = NULL; |
271 |
int i, path_ok; |
272 |
@@ -86,6 +86,9 @@ |
273 |
return; |
274 |
} |
275 |
|
276 |
+ buflen = _Q_PATH_MAX; |
277 |
+ buf = xmalloc(buflen); |
278 |
+ |
279 |
while ((dentry = readdir(dir))) { |
280 |
if (dentry->d_name[0] == '.') |
281 |
continue; |
282 |
@@ -118,8 +121,8 @@ |
283 |
warn("invalid atom %s", pkg); |
284 |
goto dont_skip_pkg; |
285 |
} |
286 |
- snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN); |
287 |
- if (strncmp(args->exclude_pkg, buf, sizeof(buf)) != 0 |
288 |
+ snprintf(buf, buflen, "%s/%s", atom->CATEGORY, atom->PN); |
289 |
+ if (strncmp(args->exclude_pkg, buf, buflen) != 0 |
290 |
&& strcmp(args->exclude_pkg, atom->PN) != 0) |
291 |
goto dont_skip_pkg; /* "(CAT/)?PN" doesn't match */ |
292 |
check_pkg_slot: /* Also compare slots, if any was specified */ |
293 |
@@ -127,10 +130,10 @@ |
294 |
continue; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */ |
295 |
buf[0] = '0'; buf[1] = '\0'; |
296 |
strcpy(p, "/SLOT"); |
297 |
- eat_file(pkg, buf, sizeof(buf)); |
298 |
+ eat_file(pkg, buf, buflen); |
299 |
rmspace(buf); |
300 |
*p = '\0'; |
301 |
- if (strncmp(args->exclude_slot, buf, sizeof(buf)) == 0) |
302 |
+ if (strncmp(args->exclude_slot, buf, buflen) == 0) |
303 |
continue; /* "(CAT/)?(PN|PF):SLOT" matches */ |
304 |
} |
305 |
dont_skip_pkg: /* End of the package exclusion tests. */ |
306 |
@@ -141,7 +144,7 @@ |
307 |
if (fp == NULL) |
308 |
continue; |
309 |
|
310 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
311 |
+ while (getline(&buf, &buflen, fp) != -1) { |
312 |
contents_entry *e; |
313 |
e = contents_parse_line(buf); |
314 |
if (!e) |
315 |
@@ -251,6 +254,7 @@ |
316 |
} |
317 |
closedir(dir); |
318 |
|
319 |
+ free(buf); |
320 |
return; |
321 |
} |
322 |
|
323 |
@@ -492,7 +496,8 @@ |
324 |
short done = 0; |
325 |
FILE *args_file = NULL; |
326 |
int max_args = QFILE_DEFAULT_MAX_ARGS; |
327 |
- char path[_Q_PATH_MAX]; |
328 |
+ size_t buflen; |
329 |
+ char *buf = NULL; |
330 |
|
331 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
332 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
333 |
@@ -568,15 +573,17 @@ |
334 |
|
335 |
do { /* This block may be repeated if using --from with a big files list */ |
336 |
if (args_file != NULL) { |
337 |
- qargc = 0; |
338 |
/* Read up to max_args files from the input file */ |
339 |
- while ((fgets(path, _Q_PATH_MAX, args_file)) != NULL) { |
340 |
- if ((p = strchr(path, '\n')) != NULL) |
341 |
+ qargc = 0; |
342 |
+ while (getline(&buf, &buflen, args_file) != -1) { |
343 |
+ if ((p = strchr(buf, '\n')) != NULL) |
344 |
*p = '\0'; |
345 |
- if (path == p) continue; |
346 |
- qargv[qargc] = xstrdup(path); |
347 |
+ if (buf == p) |
348 |
+ continue; |
349 |
+ qargv[qargc] = xstrdup(buf); |
350 |
qargc++; |
351 |
- if (qargc >= max_args) break; |
352 |
+ if (qargc >= max_args) |
353 |
+ break; |
354 |
} |
355 |
} |
356 |
|
357 |
@@ -604,8 +611,10 @@ |
358 |
|
359 |
/* Iteration over VDB categories */ |
360 |
while (nb_of_queries && (dentry = q_vdb_get_next_dir(dir))) { |
361 |
- snprintf(path, _Q_PATH_MAX, "%s/%s/%s", qfile_args->real_root, portvdb, dentry->d_name); |
362 |
+ char *path; |
363 |
+ xasprintf(&path, "%s/%s/%s", qfile_args->real_root, portvdb, dentry->d_name); |
364 |
qfile(path, (assume_root_prefix ? root_prefix : NULL), qfile_args); |
365 |
+ free(path); |
366 |
} |
367 |
|
368 |
if (qfile_args->non_orphans != NULL) { |
369 |
|
370 |
|
371 |
|
372 |
1.59 portage-utils/qlist.c |
373 |
|
374 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlist.c?rev=1.59&view=markup |
375 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlist.c?rev=1.59&content-type=text/plain |
376 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlist.c?r1=1.58&r2=1.59 |
377 |
|
378 |
Index: qlist.c |
379 |
=================================================================== |
380 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qlist.c,v |
381 |
retrieving revision 1.58 |
382 |
retrieving revision 1.59 |
383 |
diff -u -r1.58 -r1.59 |
384 |
--- qlist.c 21 Feb 2011 01:33:47 -0000 1.58 |
385 |
+++ qlist.c 21 Feb 2011 07:33:21 -0000 1.59 |
386 |
@@ -1,7 +1,7 @@ |
387 |
/* |
388 |
* Copyright 2005-2010 Gentoo Foundation |
389 |
* Distributed under the terms of the GNU General Public License v2 |
390 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qlist.c,v 1.58 2011/02/21 01:33:47 vapier Exp $ |
391 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qlist.c,v 1.59 2011/02/21 07:33:21 vapier Exp $ |
392 |
* |
393 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
394 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
395 |
@@ -41,7 +41,7 @@ |
396 |
/* "query filename for pkgname", */ |
397 |
COMMON_OPTS_HELP |
398 |
}; |
399 |
-static const char qlist_rcsid[] = "$Id: qlist.c,v 1.58 2011/02/21 01:33:47 vapier Exp $"; |
400 |
+static const char qlist_rcsid[] = "$Id: qlist.c,v 1.59 2011/02/21 07:33:21 vapier Exp $"; |
401 |
#define qlist_usage(ret) usage(ret, QLIST_FLAGS, qlist_long_opts, qlist_opts_help, lookup_applet_idx("qlist")) |
402 |
|
403 |
extern char *grab_vdb_item(const char *, const char *, const char *); |
404 |
@@ -68,7 +68,7 @@ |
405 |
|
406 |
static char *grab_pkg_umap(char *CAT, char *PV) |
407 |
{ |
408 |
- static char umap[BUFSIZ] = ""; |
409 |
+ static char umap[BUFSIZ]; |
410 |
char *use = NULL; |
411 |
char *iuse = NULL; |
412 |
int use_argc = 0, iuse_argc = 0; |
413 |
@@ -118,21 +118,22 @@ |
414 |
free_sets(sets); |
415 |
/* end filter */ |
416 |
|
417 |
- return (char *) umap; |
418 |
+ return umap; |
419 |
} |
420 |
|
421 |
-static char *umapstr(char display, char *cat, char *name); |
422 |
-static char *umapstr(char display, char *cat, char *name) |
423 |
+static const char *umapstr(char display, char *cat, char *name) |
424 |
{ |
425 |
- static char buf[BUFSIZ] = ""; |
426 |
+ static char buf[BUFSIZ]; |
427 |
char *umap = NULL; |
428 |
|
429 |
- if (!display) return (char *) ""; |
430 |
+ buf[0] = '\0'; |
431 |
+ if (!display) |
432 |
+ return buf; |
433 |
if ((umap = grab_pkg_umap(cat, name)) == NULL) |
434 |
- return (char *) ""; |
435 |
+ return buf; |
436 |
rmspace(umap); |
437 |
if (!strlen(umap)) |
438 |
- return (char *) ""; |
439 |
+ return buf; |
440 |
snprintf(buf, sizeof(buf), " %s%s%s%s%s", quiet ? "": "(", RED, umap, NORM, quiet ? "": ")"); |
441 |
return buf; |
442 |
} |
443 |
@@ -143,14 +144,15 @@ |
444 |
char qlist_all = 0, just_pkgname = 0, dups_only = 0; |
445 |
char show_dir, show_obj, show_sym, show_slots, show_umap; |
446 |
struct dirent **de, **cat; |
447 |
- char buf[_Q_PATH_MAX]; |
448 |
+ size_t buflen; |
449 |
+ char *buf; |
450 |
char swap[_Q_PATH_MAX]; |
451 |
queue *sets = NULL; |
452 |
depend_atom *pkgname, *atom; |
453 |
- char *slot_separator; |
454 |
+ const char *slot_separator; |
455 |
int columns = 0; |
456 |
|
457 |
- slot_separator = (char *) " "; |
458 |
+ slot_separator = " "; |
459 |
|
460 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
461 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
462 |
@@ -162,7 +164,7 @@ |
463 |
COMMON_GETOPTS_CASES(qlist) |
464 |
case 'a': qlist_all = 1; |
465 |
case 'I': just_pkgname = 1; break; |
466 |
- case 'L': slot_separator = (char *) ":"; break; |
467 |
+ case 'L': slot_separator = ":"; break; |
468 |
case 'S': just_pkgname = 1; show_slots = 1; break; |
469 |
case 'U': just_pkgname = 1; show_umap = 1; break; |
470 |
case 'e': exact = 1; break; |
471 |
@@ -187,6 +189,9 @@ |
472 |
if ((dfd = scandir(".", &cat, filter_hidden, alphasort)) < 0) |
473 |
return EXIT_FAILURE; |
474 |
|
475 |
+ buflen = _Q_PATH_MAX; |
476 |
+ buf = xmalloc(buflen); |
477 |
+ |
478 |
/* open /var/db/pkg */ |
479 |
for (j = 0; j < dfd; j++) { |
480 |
int a, x; |
481 |
@@ -211,8 +216,7 @@ |
482 |
/* see if this cat/pkg is requested */ |
483 |
for (i = optind; i < argc; ++i) { |
484 |
char *name = pkg_name(argv[i]); |
485 |
- snprintf(buf, sizeof(buf), "%s/%s", cat[j]->d_name, |
486 |
- de[x]->d_name); |
487 |
+ snprintf(buf, buflen, "%s/%s", cat[j]->d_name, de[x]->d_name); |
488 |
/* printf("buf=%s:%s\n", buf,grab_vdb_item("SLOT", cat[j]->d_name, de[x]->d_name)); */ |
489 |
if (exact) { |
490 |
if ((atom = atom_explode(buf)) == NULL) { |
491 |
@@ -250,7 +254,7 @@ |
492 |
if (just_pkgname) { |
493 |
if (dups_only) { |
494 |
pkgname = atom_explode(de[x]->d_name); |
495 |
- snprintf(buf, sizeof(buf), "%s/%s", cat[j]->d_name, pkgname->P); |
496 |
+ snprintf(buf, buflen, "%s/%s", cat[j]->d_name, pkgname->P); |
497 |
snprintf(swap, sizeof(swap), "%s/%s", cat[j]->d_name, pkgname->PN); |
498 |
sets = add_set(swap, buf, sets); |
499 |
atom_implode(pkgname); |
500 |
@@ -278,7 +282,7 @@ |
501 |
continue; |
502 |
} |
503 |
|
504 |
- snprintf(buf, sizeof(buf), "%s%s/%s/%s/CONTENTS", portroot, portvdb, |
505 |
+ snprintf(buf, buflen, "%s%s/%s/%s/CONTENTS", portroot, portvdb, |
506 |
cat[j]->d_name, de[x]->d_name); |
507 |
|
508 |
if (verbose > 1) |
509 |
@@ -287,7 +291,7 @@ |
510 |
if ((fp = fopen(buf, "r")) == NULL) |
511 |
continue; |
512 |
|
513 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
514 |
+ while (getline(&buf, &buflen, fp) != -1) { |
515 |
contents_entry *e; |
516 |
|
517 |
e = contents_parse_line(buf); |
518 |
|
519 |
|
520 |
|
521 |
1.56 portage-utils/qlop.c |
522 |
|
523 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlop.c?rev=1.56&view=markup |
524 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlop.c?rev=1.56&content-type=text/plain |
525 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qlop.c?r1=1.55&r2=1.56 |
526 |
|
527 |
Index: qlop.c |
528 |
=================================================================== |
529 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qlop.c,v |
530 |
retrieving revision 1.55 |
531 |
retrieving revision 1.56 |
532 |
diff -u -r1.55 -r1.56 |
533 |
--- qlop.c 21 Feb 2011 01:33:47 -0000 1.55 |
534 |
+++ qlop.c 21 Feb 2011 07:33:21 -0000 1.56 |
535 |
@@ -1,7 +1,7 @@ |
536 |
/* |
537 |
* Copyright 2005-2010 Gentoo Foundation |
538 |
* Distributed under the terms of the GNU General Public License v2 |
539 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qlop.c,v 1.55 2011/02/21 01:33:47 vapier Exp $ |
540 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qlop.c,v 1.56 2011/02/21 07:33:21 vapier Exp $ |
541 |
* |
542 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
543 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
544 |
@@ -52,7 +52,7 @@ |
545 |
"Read emerge logfile instead of " QLOP_DEFAULT_LOGFILE, |
546 |
COMMON_OPTS_HELP |
547 |
}; |
548 |
-static const char qlop_rcsid[] = "$Id: qlop.c,v 1.55 2011/02/21 01:33:47 vapier Exp $"; |
549 |
+static const char qlop_rcsid[] = "$Id: qlop.c,v 1.56 2011/02/21 07:33:21 vapier Exp $"; |
550 |
#define qlop_usage(ret) usage(ret, QLOP_FLAGS, qlop_long_opts, qlop_opts_help, lookup_applet_idx("qlop")) |
551 |
|
552 |
#define QLOP_LIST 0x01 |
553 |
@@ -241,7 +241,8 @@ |
554 |
void show_emerge_history(char listflag, int argc, char **argv, const char *logfile) |
555 |
{ |
556 |
FILE *fp; |
557 |
- char buf[BUFSIZ], merged; |
558 |
+ size_t buflen; |
559 |
+ char *buf, merged; |
560 |
char *p, *q; |
561 |
int i; |
562 |
time_t t; |
563 |
@@ -251,7 +252,8 @@ |
564 |
return; |
565 |
} |
566 |
|
567 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
568 |
+ buf = NULL; |
569 |
+ while (getline(&buf, &buflen, fp) != -1) { |
570 |
if (strlen(buf) < 30) |
571 |
continue; |
572 |
|
573 |
@@ -298,6 +300,8 @@ |
574 |
atom_implode(atom); |
575 |
} |
576 |
} |
577 |
+ |
578 |
+ free(buf); |
579 |
fclose(fp); |
580 |
} |
581 |
|
582 |
@@ -305,8 +309,8 @@ |
583 |
void show_sync_history(const char *logfile) |
584 |
{ |
585 |
FILE *fp; |
586 |
- char buf[BUFSIZ]; |
587 |
- char *p, *q; |
588 |
+ size_t buflen; |
589 |
+ char *buf, *p, *q; |
590 |
time_t t; |
591 |
|
592 |
if ((fp = fopen(logfile, "r")) == NULL) { |
593 |
@@ -314,7 +318,8 @@ |
594 |
return; |
595 |
} |
596 |
|
597 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
598 |
+ buf = NULL; |
599 |
+ while (getline(&buf, &buflen, fp) != -1) { |
600 |
if (strlen(buf) < 35) |
601 |
continue; |
602 |
if (strncmp(buf+12, "=== Sync completed with", 23) != 0) |
603 |
@@ -335,6 +340,8 @@ |
604 |
|
605 |
printf("%s >>> %s%s%s\n", chop_ctime(t), GREEN, q, NORM); |
606 |
} |
607 |
+ |
608 |
+ free(buf); |
609 |
fclose(fp); |
610 |
} |
611 |
|
612 |
|
613 |
|
614 |
|
615 |
1.32 portage-utils/qpkg.c |
616 |
|
617 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qpkg.c?rev=1.32&view=markup |
618 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qpkg.c?rev=1.32&content-type=text/plain |
619 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qpkg.c?r1=1.31&r2=1.32 |
620 |
|
621 |
Index: qpkg.c |
622 |
=================================================================== |
623 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qpkg.c,v |
624 |
retrieving revision 1.31 |
625 |
retrieving revision 1.32 |
626 |
diff -u -r1.31 -r1.32 |
627 |
--- qpkg.c 21 Feb 2011 01:33:47 -0000 1.31 |
628 |
+++ qpkg.c 21 Feb 2011 07:33:21 -0000 1.32 |
629 |
@@ -1,7 +1,7 @@ |
630 |
/* |
631 |
* Copyright 2005-2010 Gentoo Foundation |
632 |
* Distributed under the terms of the GNU General Public License v2 |
633 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qpkg.c,v 1.31 2011/02/21 01:33:47 vapier Exp $ |
634 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qpkg.c,v 1.32 2011/02/21 07:33:21 vapier Exp $ |
635 |
* |
636 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
637 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
638 |
@@ -24,7 +24,7 @@ |
639 |
"alternate package directory", |
640 |
COMMON_OPTS_HELP |
641 |
}; |
642 |
-static const char qpkg_rcsid[] = "$Id: qpkg.c,v 1.31 2011/02/21 01:33:47 vapier Exp $"; |
643 |
+static const char qpkg_rcsid[] = "$Id: qpkg.c,v 1.32 2011/02/21 07:33:21 vapier Exp $"; |
644 |
#define qpkg_usage(ret) usage(ret, QPKG_FLAGS, qpkg_long_opts, qpkg_opts_help, lookup_applet_idx("qpkg")) |
645 |
|
646 |
extern char pretend; |
647 |
@@ -107,7 +107,6 @@ |
648 |
{ |
649 |
FILE *fp; |
650 |
int i, count; |
651 |
- char buf[_Q_PATH_MAX]; |
652 |
size_t disp_units = 0; |
653 |
uint64_t num_all_bytes; |
654 |
struct dirent **dnames; |
655 |
@@ -126,10 +125,10 @@ |
656 |
|
657 |
if (eclean) { |
658 |
char fname[_Q_PATH_MAX] = ""; |
659 |
- char *ecache; |
660 |
+ const char *ecache; |
661 |
|
662 |
/* CACHE_EBUILD_FILE is a macro so don't put it in the .bss */ |
663 |
- ecache = (char *) CACHE_EBUILD_FILE; |
664 |
+ ecache = CACHE_EBUILD_FILE; |
665 |
|
666 |
if (ecache) { |
667 |
if (*ecache != '/') |
668 |
@@ -138,7 +137,11 @@ |
669 |
strncpy(fname, ecache, sizeof(fname)); |
670 |
} |
671 |
if ((fp = fopen(fname, "r")) != NULL) { |
672 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
673 |
+ size_t buflen; |
674 |
+ char *buf; |
675 |
+ |
676 |
+ buf = NULL; |
677 |
+ while (getline(&buf, &buflen, fp) != -1) { |
678 |
char *name, *p; |
679 |
if ((p = strrchr(buf, '.')) == NULL) |
680 |
continue; |
681 |
@@ -158,6 +161,8 @@ |
682 |
/* vdb = del_set(buf, vdb, &i); */ |
683 |
vdb = add_set(buf, "0", vdb); |
684 |
} |
685 |
+ |
686 |
+ free(buf); |
687 |
fclose(fp); |
688 |
} |
689 |
} |
690 |
@@ -165,6 +170,7 @@ |
691 |
num_all_bytes = qpkg_clean_dir(dirp, vdb); |
692 |
|
693 |
for (i = 0; i < count; i++) { |
694 |
+ char buf[_Q_PATH_MAX]; |
695 |
snprintf(buf, sizeof(buf), "%s/%s", dirp, dnames[i]->d_name); |
696 |
num_all_bytes += qpkg_clean_dir(buf, vdb); |
697 |
} |
698 |
@@ -200,7 +206,8 @@ |
699 |
{ |
700 |
FILE *fp, *out; |
701 |
char tmpdir[BUFSIZE], filelist[BUFSIZE], xpak[BUFSIZE], tbz2[BUFSIZE]; |
702 |
- char buf[BUFSIZE]; |
703 |
+ size_t buflen; |
704 |
+ char *buf; |
705 |
int i; |
706 |
char *xpak_argv[2]; |
707 |
struct stat st; |
708 |
@@ -226,15 +233,17 @@ |
709 |
if ((out = fopen(filelist, "w")) == NULL) |
710 |
return -4; |
711 |
|
712 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
713 |
+ buflen = _Q_PATH_MAX; |
714 |
+ buf = xmalloc(buflen); |
715 |
+ while (getline(&buf, &buflen, fp) != -1) { |
716 |
contents_entry *e; |
717 |
e = contents_parse_line(buf); |
718 |
if (!e || e->type == CONTENTS_DIR) |
719 |
continue; |
720 |
fprintf(out, "%s\n", e->name+1); /* dont output leading / */ |
721 |
if (e->type == CONTENTS_OBJ && verbose) { |
722 |
- char *hash = NULL; |
723 |
- if ((hash = (char*) hash_file(e->name, HASH_MD5)) != NULL) { |
724 |
+ char *hash = (char *)hash_file(e->name, HASH_MD5); |
725 |
+ if (hash != NULL) { |
726 |
if (strcmp(e->digest, hash) != 0) |
727 |
warn("MD5: mismatch expected %s got %s for %s", e->digest, hash, e->name); |
728 |
free(hash); |
729 |
@@ -249,18 +258,18 @@ |
730 |
fflush(stdout); |
731 |
|
732 |
snprintf(tbz2, sizeof(tbz2), "%s/bin.tar.bz2", tmpdir); |
733 |
- snprintf(buf, sizeof(buf), "tar jcf '%s' --files-from='%s' --no-recursion >/dev/null 2>&1", tbz2, filelist); |
734 |
+ snprintf(buf, buflen, "tar jcf '%s' --files-from='%s' --no-recursion >/dev/null 2>&1", tbz2, filelist); |
735 |
if ((fp = popen(buf, "r")) == NULL) |
736 |
return 2; |
737 |
pclose(fp); |
738 |
|
739 |
snprintf(xpak, sizeof(xpak), "%s/inf.xpak", tmpdir); |
740 |
- snprintf(buf, sizeof(buf), "%s/%s/%s", portvdb, atom->CATEGORY, atom_to_pvr(atom)); |
741 |
+ snprintf(buf, buflen, "%s/%s/%s", portvdb, atom->CATEGORY, atom_to_pvr(atom)); |
742 |
xpak_argv[0] = buf; |
743 |
xpak_argv[1] = NULL; |
744 |
xpak_create(xpak, 1, xpak_argv); |
745 |
|
746 |
- snprintf(buf, sizeof(buf), "%s/binpkg.tbz2", tmpdir); |
747 |
+ snprintf(buf, buflen, "%s/binpkg.tbz2", tmpdir); |
748 |
tbz2_compose(tbz2, xpak, buf); |
749 |
|
750 |
unlink(filelist); |
751 |
|
752 |
|
753 |
|
754 |
1.37 portage-utils/qsize.c |
755 |
|
756 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qsize.c?rev=1.37&view=markup |
757 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qsize.c?rev=1.37&content-type=text/plain |
758 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qsize.c?r1=1.36&r2=1.37 |
759 |
|
760 |
Index: qsize.c |
761 |
=================================================================== |
762 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qsize.c,v |
763 |
retrieving revision 1.36 |
764 |
retrieving revision 1.37 |
765 |
diff -u -r1.36 -r1.37 |
766 |
--- qsize.c 21 Feb 2011 01:33:47 -0000 1.36 |
767 |
+++ qsize.c 21 Feb 2011 07:33:21 -0000 1.37 |
768 |
@@ -1,7 +1,7 @@ |
769 |
/* |
770 |
* Copyright 2005-2010 Gentoo Foundation |
771 |
* Distributed under the terms of the GNU General Public License v2 |
772 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qsize.c,v 1.36 2011/02/21 01:33:47 vapier Exp $ |
773 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qsize.c,v 1.37 2011/02/21 07:33:21 vapier Exp $ |
774 |
* |
775 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
776 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
777 |
@@ -32,7 +32,7 @@ |
778 |
"Ignore regexp string", |
779 |
COMMON_OPTS_HELP |
780 |
}; |
781 |
-static const char qsize_rcsid[] = "$Id: qsize.c,v 1.36 2011/02/21 01:33:47 vapier Exp $"; |
782 |
+static const char qsize_rcsid[] = "$Id: qsize.c,v 1.37 2011/02/21 07:33:21 vapier Exp $"; |
783 |
#define qsize_usage(ret) usage(ret, QSIZE_FLAGS, qsize_long_opts, qsize_opts_help, lookup_applet_idx("qsize")) |
784 |
|
785 |
int qsize_main(int argc, char **argv) |
786 |
@@ -48,7 +48,8 @@ |
787 |
uint64_t num_all_bytes, num_bytes; |
788 |
size_t disp_units = 0; |
789 |
const char *str_disp_units = NULL; |
790 |
- char buf[_Q_PATH_MAX]; |
791 |
+ size_t buflen; |
792 |
+ char *buf; |
793 |
char filename[_Q_PATH_MAX], *filename_root; |
794 |
queue *ignore_regexp = NULL; |
795 |
|
796 |
@@ -80,13 +81,13 @@ |
797 |
|
798 |
strcpy(filename, portroot); |
799 |
filename_root = filename + strlen(filename); |
800 |
+ buflen = _Q_PATH_MAX; |
801 |
+ buf = xmalloc(buflen); |
802 |
|
803 |
/* open /var/db/pkg */ |
804 |
while ((dentry = q_vdb_get_next_dir(dir))) { |
805 |
|
806 |
- if (chdir(dentry->d_name) != 0) |
807 |
- continue; |
808 |
- if ((dirp = opendir(".")) == NULL) |
809 |
+ if ((dirp = opendir(dentry->d_name)) == NULL) |
810 |
continue; |
811 |
|
812 |
/* open the cateogry */ |
813 |
@@ -98,7 +99,7 @@ |
814 |
/* see if this cat/pkg is requested */ |
815 |
if (!search_all) { |
816 |
for (i = optind; i < argc; ++i) { |
817 |
- snprintf(buf, sizeof(buf), "%s/%s", dentry->d_name, |
818 |
+ snprintf(buf, buflen, "%s/%s", dentry->d_name, |
819 |
de->d_name); |
820 |
if (rematch(argv[i], buf, REG_EXTENDED) == 0) |
821 |
break; |
822 |
@@ -109,13 +110,13 @@ |
823 |
continue; |
824 |
} |
825 |
|
826 |
- snprintf(buf, sizeof(buf), "%s%s/%s/%s/CONTENTS", portroot, portvdb, |
827 |
+ snprintf(buf, buflen, "%s%s/%s/%s/CONTENTS", portroot, portvdb, |
828 |
dentry->d_name, de->d_name); |
829 |
if ((fp = fopen(buf, "r")) == NULL) |
830 |
continue; |
831 |
|
832 |
num_ignored = num_files = num_nonfiles = num_bytes = 0; |
833 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
834 |
+ while (getline(&buf, &buflen, fp) != -1) { |
835 |
contents_entry *e; |
836 |
queue *ll; |
837 |
int ok = 0; |
838 |
@@ -165,7 +166,6 @@ |
839 |
} |
840 |
} |
841 |
closedir(dirp); |
842 |
- xchdir(".."); |
843 |
} |
844 |
|
845 |
if (summary) { |
846 |
|
847 |
|
848 |
|
849 |
1.64 portage-utils/quse.c |
850 |
|
851 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/quse.c?rev=1.64&view=markup |
852 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/quse.c?rev=1.64&content-type=text/plain |
853 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/quse.c?r1=1.63&r2=1.64 |
854 |
|
855 |
Index: quse.c |
856 |
=================================================================== |
857 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/quse.c,v |
858 |
retrieving revision 1.63 |
859 |
retrieving revision 1.64 |
860 |
diff -u -r1.63 -r1.64 |
861 |
--- quse.c 21 Feb 2011 01:33:47 -0000 1.63 |
862 |
+++ quse.c 21 Feb 2011 07:33:21 -0000 1.64 |
863 |
@@ -1,7 +1,7 @@ |
864 |
/* |
865 |
* Copyright 2005-2010 Gentoo Foundation |
866 |
* Distributed under the terms of the GNU General Public License v2 |
867 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/quse.c,v 1.63 2011/02/21 01:33:47 vapier Exp $ |
868 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/quse.c,v 1.64 2011/02/21 07:33:21 vapier Exp $ |
869 |
* |
870 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
871 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
872 |
@@ -35,7 +35,7 @@ |
873 |
"Only show package name", |
874 |
COMMON_OPTS_HELP |
875 |
}; |
876 |
-static const char quse_rcsid[] = "$Id: quse.c,v 1.63 2011/02/21 01:33:47 vapier Exp $"; |
877 |
+static const char quse_rcsid[] = "$Id: quse.c,v 1.64 2011/02/21 07:33:21 vapier Exp $"; |
878 |
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse")) |
879 |
|
880 |
int quse_describe_flag(int ind, int argc, char **argv); |
881 |
@@ -83,8 +83,9 @@ |
882 |
|
883 |
int quse_describe_flag(int ind, int argc, char **argv) |
884 |
{ |
885 |
-#define NUM_SEARCH_FILES ARR_SIZE(search_files) |
886 |
- char buf[BUFSIZE], *p; |
887 |
+#define NUM_SEARCH_FILES ARRAY_SIZE(search_files) |
888 |
+ size_t buflen; |
889 |
+ char *buf, *p; |
890 |
int i, f; |
891 |
size_t s; |
892 |
const char *search_files[] = { "use.desc", "use.local.desc", "arch.list", "lang.desc" }; |
893 |
@@ -92,8 +93,11 @@ |
894 |
DIR *d; |
895 |
struct dirent *de; |
896 |
|
897 |
+ buflen = _Q_PATH_MAX; |
898 |
+ buf = xmalloc(buflen); |
899 |
+ |
900 |
for (i = 0; i < NUM_SEARCH_FILES; ++i) { |
901 |
- snprintf(buf, sizeof(buf), "%s/profiles/%s", portdir, search_files[i]); |
902 |
+ snprintf(buf, buflen, "%s/profiles/%s", portdir, search_files[i]); |
903 |
if ((fp[i] = fopen(buf, "r")) == NULL) |
904 |
if ((strcmp(search_files[i], "lang.desc")) != 0) |
905 |
warnp("skipping %s", search_files[i]); |
906 |
@@ -106,7 +110,7 @@ |
907 |
if (fp[f] == NULL) |
908 |
continue; |
909 |
|
910 |
- while (fgets(buf, sizeof(buf), fp[f]) != NULL) { |
911 |
+ while (getline(&buf, &buflen, fp[f]) != -1) { |
912 |
if (buf[0] == '#' || buf[0] == '\n') |
913 |
continue; |
914 |
|
915 |
@@ -161,23 +165,23 @@ |
916 |
fclose(fp[f]); |
917 |
|
918 |
/* now scan the desc dir */ |
919 |
- snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir); |
920 |
+ snprintf(buf, buflen, "%s/profiles/desc/", portdir); |
921 |
if ((d = opendir(buf)) == NULL) { |
922 |
warnp("skipping profiles/desc/"); |
923 |
- return 0; |
924 |
+ goto done; |
925 |
} |
926 |
|
927 |
while ((de = readdir(d)) != NULL) { |
928 |
if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc")) |
929 |
continue; |
930 |
|
931 |
- snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name); |
932 |
+ snprintf(buf, buflen, "%s/profiles/desc/%s", portdir, de->d_name); |
933 |
if ((fp[0]=fopen(buf, "r")) == NULL) { |
934 |
warn("Could not open '%s' for reading; skipping", de->d_name); |
935 |
continue; |
936 |
} |
937 |
|
938 |
- while (fgets(buf, sizeof(buf), fp[0]) != NULL) { |
939 |
+ while (getline(&buf, &buflen, fp[0]) != -1) { |
940 |
if (buf[0] == '#' || buf[0] == '\n') |
941 |
continue; |
942 |
|
943 |
@@ -205,6 +209,8 @@ |
944 |
} |
945 |
closedir(d); |
946 |
|
947 |
+ done: |
948 |
+ free(buf); |
949 |
return 0; |
950 |
} |
951 |
|
952 |
@@ -217,7 +223,8 @@ |
953 |
char buf1[_Q_PATH_MAX]; |
954 |
char buf2[_Q_PATH_MAX]; |
955 |
|
956 |
- char ebuild[_Q_PATH_MAX]; |
957 |
+ size_t ebuildlen; |
958 |
+ char *ebuild; |
959 |
|
960 |
const char *search_var = NULL; |
961 |
const char *search_vars[] = { "IUSE=", "KEYWORDS=", "LICENSE=", search_var }; |
962 |
@@ -254,7 +261,8 @@ |
963 |
|
964 |
if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL) |
965 |
return 1; |
966 |
- while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) { |
967 |
+ ebuild = NULL; |
968 |
+ while (getline(&ebuild, &ebuildlen, fp) != -1) { |
969 |
FILE *newfp; |
970 |
if ((p = strchr(ebuild, '\n')) != NULL) |
971 |
*p = 0; |
972 |
@@ -303,7 +311,6 @@ |
973 |
|
974 |
multiline: |
975 |
*p = ' '; |
976 |
- memset(buf1, 0, sizeof(buf1)); |
977 |
|
978 |
if ((fgets(buf1, sizeof(buf1), newfp)) == NULL) |
979 |
continue; |