Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jul 2007 12:27:08 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 123587 for review
Message-ID:  <200707161227.l6GCR8WB073145@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123587

Change 123587 by gcooper@optimus-revised_pkgtools on 2007/07/16 12:26:44

	- Check to make sure read(2) returns the stat'ed file length, instead of a non-(-1) value.
	- Use write(2) instead of fwrite(2) based on results from my "fat" tool. Hopefully this results in a 30% to 3-fold speedup.

Affected files ...

.. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/file.c#8 edit

Differences ...

==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/file.c#8 (text+ko) ====

@@ -223,7 +223,7 @@
 
     contents = (char *)malloc(sb.st_size + 1);
 
-    if (read(fileno(fd), contents, sb.st_size) == -1) {
+    if (read(fileno(fd), contents, sb.st_size) != sb.st_size) {
 	cleanup(0);
 	errx(2, "%s: short read on '%s' - did not get %lld bytes", __func__,
 	     fname, (long long)sb.st_size);
@@ -280,10 +280,10 @@
 	errx(2, "%s: cannot fopen '%s' for writing", __func__, name);
     }
     len = strlen(str);
-    if (fwrite(str, 1, len, fp) != len) {
+    if (write(fileno(fp), str, len) != len) {
 	cleanup(0);
-	errx(2, "%s: short fwrite on '%s', tried to write %ld bytes",
-	    __func__, name, (long)len);
+	errx(2, "%s: short fwrite on '%s', tried to write %lld bytes",
+	    __func__, name, (long long)len);
     }
     if (fclose(fp)) {
 	cleanup(0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707161227.l6GCR8WB073145>