Message-Id: <199711191708.MAA00799@delorie.com> From: Oberhumer Markus Subject: 971114: response files To: djgpp-workers AT delorie DOT com (djgpp-workers), dj AT delorie DOT com (DJ Delorie) Date: Wed, 19 Nov 1997 18:00:40 +0100 (MET) Return-Read-To: markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk 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 (bpwas_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; inext) + 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);