[PATCH] minor size optimization for dd.c

Denis Vlasenko vda at ilport.com.ua
Wed Mar 15 07:21:51 UTC 2006


On Tuesday 14 March 2006 15:41, Tito wrote:
> Hi,
> this patch reduces size of dd.c.
> Size reduction is:
> 
>    text    data     bss     dec     hex filename
>   1346       0       0    1346     542 coreutils/dd.o.orig
>   1302       0       0    1302     516 coreutils/dd.o
> 
> Changes are trivial.
> 
> Please apply.

                if ((ofd = open(outfile, oflag, 0666)) < 0) {
-                       bb_perror_msg_and_die("%s", outfile);
+                       goto OUTFILE_ERROR;
                }

I think it is better to use bb_xopen(), which will be doing
the bb_perror_msg_and_die thing to you. Pity current bb_xopen()
has only two arguments, but it's trivial to have three-argument one.
See at http://195.66.192.167/linux/bbox/bb_xopen3.patch

diff -urpN busybox.org/libbb/xfuncs.c busybox.unlzma2/libbb/xfuncs.c
--- busybox.org/libbb/xfuncs.c	Tue Mar  7 07:58:22 2006
+++ busybox.unlzma2/libbb/xfuncs.c	Mon Mar 13 09:59:22 2006
@@ -108,6 +108,19 @@ int bb_xopen(const char *pathname, int f
 }
 #endif
 
+#ifdef L_xopen3
+int bb_xopen3(const char *pathname, int flags, int mode)
+{
+	int ret;
+
+	ret = open(pathname, flags, mode);
+	if (ret == -1) {
+		bb_perror_msg_and_die("%s", pathname);
+	}
+	return ret;
+}
+#endif

Or else you may change bb_xopen() definition so that
it can take 3 params. FYI: libc defines open() as 
int open(const char *file, int oflag, ...);

Unfortunately, it's not trivial to do the same to lseek etc:

	bb_xlseek(ifd, skip * bs, SEEK_CUR);

does not have any way to report _filename_ on error :(
Maybe

	bb_xlseek(ifd, skip * bs, SEEK_CUR, infile);

where "infile" is a filename to use in bb_perror_msg_and_die
if lseek will fail.
--
vda



More information about the busybox mailing list