Mail Archives: djgpp-workers/1997/11/19/12:12:02
Subject: 971114: response files
Some patches for reading response files in c1args.c:
- check for file errors (lseek/_read) and avoid malloc(0)
- if the last byte in a response file is '\0', assume it's the
output from 'find -print0' and parse it (this is easy)
Markus
*** c1args.org Thu Oct 9 18:49:22 1997
--- c1args.c Wed Nov 19 02:25:06 1997
***************
*** 180,183 ****
--- 180,213 ----
}
+ /* parse the output from 'find -print0' */
+ static ArgList *
+ parse_print0(char *bytes, int length)
+ {
+ int largc, i;
+ Arg *a, **anext, *afirst;
+ ArgList *al;
+ char *bp=bytes, *ep, *last=bytes+length;
+
+ anext = &afirst;
+ largc = 0;
+ while (bp<last)
+ {
+ size_t arg_len = strlen(bp);
+ ep = bp;
+ bp += arg_len + 1;
+ *anext = a = new_arg();
+ a->was_quoted = 1;
+ anext = &(a->next);
+ largc++;
+ a->arg = (char *)c1xmalloc(arg_len+1);
+ memcpy(a->arg, ep, arg_len);
+ a->arg[arg_len] = 0;
+ }
+ al = new_arglist(largc);
+ for (i=0, a=afirst; i<largc; i++, a=a->next)
+ al->argv[i] = a;
+ return al;
+ }
+
static int
count_args(ArgList *al)
***************
*** 245,252 ****
st_size = lseek(f, 0L, SEEK_END);
lseek(f, 0L, SEEK_SET);
! bytes = (char *)c1xmalloc(st_size);
len = _read(f, bytes, st_size);
_close(f);
! al->argv[i]->arg_file = parse_bytes(bytes, len);
expand_response_files(al->argv[i]->arg_file);
free(bytes);
--- 275,290 ----
st_size = lseek(f, 0L, SEEK_END);
lseek(f, 0L, SEEK_SET);
! if (st_size < 0)
! st_size = 0;
! bytes = (char *)c1xmalloc(st_size+1);
len = _read(f, bytes, st_size);
+ if (len < 0)
+ len = 0;
_close(f);
! /* assume 'find -print0' if the last char is a '\0' */
! if (len > 0 && bytes[len-1] == '\0')
! al->argv[i]->arg_file = parse_print0(bytes, len);
! else
! al->argv[i]->arg_file = parse_bytes(bytes, len);
expand_response_files(al->argv[i]->arg_file);
free(bytes);
- Raw text -