svn commit: trunk/busybox: include libbb miscutils printutils util- etc...

vda at busybox.net vda at busybox.net
Sat Apr 19 19:32:08 UTC 2008


Author: vda
Date: 2008-04-19 12:32:08 -0700 (Sat, 19 Apr 2008)
New Revision: 21775

Log:
libbb: introduce xmalloc_xopen_read_close and use where appropriate
instead of xmalloc_open_read_close.

function                                             old     new   delta
xmalloc_xopen_read_close                               -      34     +34
xmalloc_open_read_close                              163     171      +8
passwd_main                                         1070    1074      +4
rexecve                                              254     257      +3
handle_incoming_and_exit                            2657    2659      +2
parse_command                                       1509    1510      +1
buffer_fill_and_print                                 76      73      -3
evaltreenr                                           599     589     -10
evaltree                                             599     589     -10
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 5/3 up/down: 52/-23)             Total: 29 bytes



Modified:
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/read.c
   trunk/busybox/miscutils/chat.c
   trunk/busybox/printutils/lpd.c
   trunk/busybox/util-linux/readprofile.c


Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-04-19 19:06:23 UTC (rev 21774)
+++ trunk/busybox/include/libbb.h	2008-04-19 19:32:08 UTC (rev 21775)
@@ -556,7 +556,10 @@
 extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p);
 extern ssize_t read_close(int fd, void *buf, size_t maxsz);
 extern ssize_t open_read_close(const char *filename, void *buf, size_t maxsz);
+/* Returns NULL if file can't be opened */
 extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p);
+/* Never returns NULL */
+extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p);
 
 extern ssize_t safe_write(int fd, const void *buf, size_t count);
 // NB: will return short write on error, not -1,
@@ -568,9 +571,9 @@
 extern void xprint_and_close_file(FILE *file);
 /* Reads up to (and including) TERMINATING_STRING: */
 extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string);
-/* Chops off TERMINATING_STRING: from the end: */
+/* Chops off TERMINATING_STRING from the end: */
 extern char *xmalloc_fgetline_str(FILE *file, const char *terminating_string);
-/* Reads up to (and including) "\n" or NUL byte */
+/* Reads up to (and including) "\n" or NUL byte: */
 extern char *xmalloc_fgets(FILE *file);
 /* Chops off '\n' from the end, unlike fgets: */
 extern char *xmalloc_fgetline(FILE *file);

Modified: trunk/busybox/libbb/read.c
===================================================================
--- trunk/busybox/libbb/read.c	2008-04-19 19:06:23 UTC (rev 21774)
+++ trunk/busybox/libbb/read.c	2008-04-19 19:32:08 UTC (rev 21775)
@@ -212,7 +212,9 @@
 	int fd;
 	off_t len;
 
-	fd = xopen(filename, O_RDONLY);
+	fd = open(filename, O_RDONLY);
+	if (fd < 0)
+		return NULL;
 	/* /proc/N/stat files report len 0 here */
 	/* In order to make such files readable, we add small const */
 	len = xlseek(fd, 0, SEEK_END) | 0x3ff; /* + up to 1k */
@@ -229,3 +231,11 @@
 		*sizep = size;
 	return buf;
 }
+
+void *xmalloc_xopen_read_close(const char *filename, size_t *sizep)
+{
+	void *buf = xmalloc_open_read_close(filename, sizep);
+	if (!buf)
+		bb_perror_msg_and_die("can't read '%s'", filename);
+	return buf;
+}

Modified: trunk/busybox/miscutils/chat.c
===================================================================
--- trunk/busybox/miscutils/chat.c	2008-04-19 19:06:23 UTC (rev 21774)
+++ trunk/busybox/miscutils/chat.c	2008-04-19 19:32:08 UTC (rev 21775)
@@ -363,7 +363,7 @@
 				if ('@' == *buf) {
 					// skip the @ and any following white-space
 					trim(++buf);
-					buf = loaded = xmalloc_open_read_close(buf, NULL);
+					buf = loaded = xmalloc_xopen_read_close(buf, NULL);
 				}
 
 				// expand escape sequences in command

Modified: trunk/busybox/printutils/lpd.c
===================================================================
--- trunk/busybox/printutils/lpd.c	2008-04-19 19:06:23 UTC (rev 21774)
+++ trunk/busybox/printutils/lpd.c	2008-04-19 19:32:08 UTC (rev 21775)
@@ -160,7 +160,7 @@
 			// (we exit 127 if helper cannot be executed)
 			var[1] = '\0';
 			// read and delete ctrlfile
-			q = xmalloc_open_read_close(filenames[0], NULL);
+			q = xmalloc_xopen_read_close(filenames[0], NULL);
 			unlink(filenames[0]);
 			// provide datafile name
 			// we can use leaky setenv since we are about to exec or exit

Modified: trunk/busybox/util-linux/readprofile.c
===================================================================
--- trunk/busybox/util-linux/readprofile.c	2008-04-19 19:06:23 UTC (rev 21774)
+++ trunk/busybox/util-linux/readprofile.c	2008-04-19 19:32:08 UTC (rev 21775)
@@ -109,9 +109,9 @@
 	 * Use an fd for the profiling buffer, to skip stdio overhead
 	 */
 	len = MAXINT(ssize_t);
-	buf = xmalloc_open_read_close(proFile, &len);
+	buf = xmalloc_xopen_read_close(proFile, &len);
 	if (!optNative) {
-		int entries = len/sizeof(*buf);
+		int entries = len / sizeof(*buf);
 		int big = 0, small = 0, i;
 		unsigned *p;
 




More information about the busybox-cvs mailing list