zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: NO_CLOBBER attempt 2
@ 1998-04-24  8:06 Andrew Main
  0 siblings, 0 replies; only message in thread
From: Andrew Main @ 1998-04-24  8:06 UTC (permalink / raw)
  To: zsh-workers

-----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-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-04-24  8:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-24  8:06 PATCH: NO_CLOBBER attempt 2 Andrew Main

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).