Date: Sun, 15 Jul 2007 15:07:48 -0700 From: Garrett Cooper <yanegomi@gmail.com> To: "M. Warner Losh" <imp@bsdimp.com> Cc: perforce@freebsd.org, gcooper@freebsd.org Subject: Re: PERFORCE change 123550 for review Message-ID: <469A9AB4.6050702@gmail.com> In-Reply-To: <20070715.150629.-457441111.imp@bsdimp.com> References: <200707152008.l6FK8Nr8028280@repoman.freebsd.org> <20070715.150629.-457441111.imp@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
M. Warner Losh wrote: > In message: <200707152008.l6FK8Nr8028280@repoman.freebsd.org> > Garrett Cooper <gcooper@freebsd.org> writes: > : http://perforce.freebsd.org/chv.cgi?CH=123550 > : > : Change 123550 by gcooper@optimus-revised_pkgtools on 2007/07/15 20:07:45 > : > : Quite simply, works with read, but not fread. Or maybe it's just me :)? > : > : Affected files ... > : > : .. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/file.c#4 edit > : > : Differences ... > : > : ==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/file.c#4 (text+ko) ==== > : > : @@ -223,7 +223,7 @@ > : > : contents = (char *)malloc(sb.st_size + 1); > : > : - if ((int) fread(contents, sb.st_size, 1, fd) == FAIL) { > : + if (read(fileno(fd), contents, sb.st_size) == FAIL) { > : cleanup(0); > : errx(2, "%s: short read on '%s' - did not get %lld bytes", __func__, > : fname, (long long)sb.st_size); > > > The functions fread() and fwrite() advance the file position indicator > for the stream by the number of bytes read or written. They return the > number of objects read or written. If an error occurs, or the end-of- > file is reached, the return value is a short object count (or zero). > > vs > > If successful, the number of bytes actually read is returned. Upon read- > ing end-of-file, zero is returned. Otherwise, a -1 is returned and the > global variable errno is set to indicate the error. > > /me guesses FAIL is defined to be -1... > > Warner > Warner, Yes, FAIL is -1 according to <lib/lib.h>. What I'm ultimately looking for is 0, for the EOF, since this is an attempt to prebuffer as many file lines as possible. Should I be doing additional file checking, i.e. file doesn't have EOF? I know it shouldn't happen with most file writes, but it could (or at least it does from time to time according to vim's status bar), and I want to avoid security risks and/or bugs.. As a sidenote, I was concerned about memory usage but it appears to be fairly minimal. I'll discuss it on relevant lists. Thanks! -Garrett
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?469A9AB4.6050702>