I don't see any reason to even open the file if the size is 0.

On Fri, Nov 11, 2011, Michael W. Bombardieri wrote:
> Sorry, let me try that again... Forgot to clean up file descriptor ifd.
> 
> 
> Index: inp.c
> ===================================================================
> RCS file: /usr/src/cvs/src/usr.bin/patch/inp.c,v
> retrieving revision 1.35
> diff -u -r1.35 inp.c
> --- inp.c     27 Oct 2009 23:59:41 -0000      1.35
> +++ inp.c     11 Nov 2011 06:51:13 -0000
> @@ -243,6 +243,10 @@
> if ((ifd = open(filename, O_RDONLY)) < 0)
> pfatal("can't open file %s", filename);
> 
> +     if (i_size == 0) {
> +             close(ifd);
> +             return true;
> +     }
> i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
> if (i_womp == MAP_FAILED) {
> perror("mmap failed");

Reply via email to