delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/11/19/12:12:02

Message-Id: <199711191708.MAA00799@delorie.com>
From: Oberhumer Markus <k3040e4 AT c210 DOT edvz DOT uni-linz DOT ac DOT at>
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

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019