Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: NO_CLOBBER attempt 2



-----BEGIN PGP SIGNED MESSAGE-----

This is the proper fix.  Apply this patch instead of 3859.

- -zefram

 *** Src/exec.c	1998/04/23 21:12:31	1.70
 --- Src/exec.c	1998/04/23 21:19:18
 ***************
 *** 1007,1024 ****
   clobber_open(struct redir *f)
   {
       struct stat buf;
 !     int fd;
   
       if (isset(CLOBBER) || IS_CLOBBER_REDIR(f->type))
   	return open(unmeta(f->name), O_WRONLY | O_CREAT | O_TRUNC, 0666);
       if ((fd = open(unmeta(f->name), O_WRONLY | O_CREAT | O_EXCL, 0666)) >= 0)
   	return fd;
 !     if ((fd = open(unmeta(f->name), O_WRONLY)) < 0)
 ! 	return fd;
 !     if (!fstat(fd, &buf) && !S_ISREG(buf.st_mode))
 ! 	return fd;
 !     close(fd);
 !     errno = EEXIST;
       return -1;
   }
   
 --- 1007,1032 ----
   clobber_open(struct redir *f)
   {
       struct stat buf;
 !     int fd, oerrno;
   
 +     /* If clobbering, just open. */
       if (isset(CLOBBER) || IS_CLOBBER_REDIR(f->type))
   	return open(unmeta(f->name), O_WRONLY | O_CREAT | O_TRUNC, 0666);
 + 
 +     /* If not clobbering, attempt to create file exclusively. */
       if ((fd = open(unmeta(f->name), O_WRONLY | O_CREAT | O_EXCL, 0666)) >= 0)
   	return fd;
 ! 
 !     /* If that fails, we are still allowed to open non-regular files. *
 !      * Try opening, and if it's a regular file then close it again    *
 !      * because we weren't supposed to open it.                        */
 !     oerrno = errno;
 !     if ((fd = open(unmeta(f->name), O_WRONLY)) != -1) {
 ! 	if(!fstat(fd, &buf) && !S_ISREG(buf.st_mode))
 ! 	    return fd;
 ! 	close(fd);
 !     }
 !     errno = oerrno;
       return -1;
   }
   

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: ascii

iQEVAwUBNT+x8pmk9GeOHh7BAQEJygf/SCVOAisij4vhvJWJbdj+/QhW6G9zFLa4
E9WMOY2eHeKgg5DKzLlX1t2o3ylG8oGBh98K6tQYPrjeewShrCNPBMtmr/bTXLeL
4ZlshgHSadnJznomk2pkhxTVl6FxzjeWLhVZVXFBwOqachtshs3T0fyrZ567BQOk
OIubQ0gxToKxRm/M8Q3hJW3FH5SwdthvQvD/cBSAYho2bToM5J1BWbuBORZK51Nh
AS1XO/GTi3VsJk6Nlw+mNpGkEw8uXOqUVMBHoNm1zwGUfKUyyxlCiq2L/X9qMlc/
MZO+866YFWNSO9RAt9H7qw9yt9aioiyyT6/MMnLMhNCDxBNGAyGp3w==
=JXqF
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author