[Debootloaders-devel] r91 - trunk/rsrce

Jeremie Koenig jkoenig-guest at costa.debian.org
Wed Jul 12 06:33:54 UTC 2006


Author: jkoenig-guest
Date: 2006-07-12 06:33:52 +0000 (Wed, 12 Jul 2006)
New Revision: 91

Modified:
   trunk/rsrce/translate.c
Log:
There's nothing wrong with empty strings.


Modified: trunk/rsrce/translate.c
===================================================================
--- trunk/rsrce/translate.c	2006-07-12 01:42:46 UTC (rev 90)
+++ trunk/rsrce/translate.c	2006-07-12 06:33:52 UTC (rev 91)
@@ -59,16 +59,13 @@
 {
 	int sz, c;
 
-	sz = *len;
+	*data = realloc(*data, sz = BUFSZ);
 	*len = 1;
+
 	while((c = fgetc(f)) >= 0 && c != '\n') {
-		if(*len >= sz)
-			*data = realloc(*data, sz += BUFSZ);
+		if(*len >= sz) *data = realloc(*data, sz += BUFSZ);
 		((unsigned char *) *data)[(*len)++] = c;
 	}
-	if(*len == 1)
-		return -1;
-
 	* (unsigned char *) *data = *len - 1;
 
 	return (feof(f) || c == '\n') ? 0 : -1;
@@ -97,27 +94,18 @@
 
 int tr_strhash_import(FILE *f, void **data, int *len)
 {
-	void *sd;
-	int sl, ret;
+	void *sd = NULL;
+	int sl = 0, sn;
 	
 	*len = sizeof(unsigned short);
 	*data = realloc(*data, *len);
 
-	* (unsigned short *) *data = 0;
-	do {
-		sd = NULL;
-		sl = 0;
-		ret = tr_str_import(f, &sd, &sl);
-		if(ret == 0) {	
-			*data = realloc(*data, *len + sl);
-			memcpy(*data + *len, sd, sl);
-			*len += sl;
-			if(sd) free(sd);
-			(* (unsigned short *) *data)++;
-		}
-	} while(ret == 0 && !feof(f));
-	
-	* (unsigned short *) *data = htons(* (unsigned short *) *data);
+	for(sn = 0; !tr_str_import(f, &sd,&sl) && (!feof(f) || sl > 1); sn++) {
+		*data = realloc(*data, *len + sl);
+		memcpy(*data + *len, sd, sl);
+		*len += sl;
+	}
+	* (unsigned short *) *data = htons(sn);
 
 	return feof(f) ? 0 : -1;
 }





More information about the Debootloaders-devel mailing list