From: Andrew Main <zefram@tao.co.uk>
To: zsh-workers@math.gatech.edu
Subject: PATCH: NO_CLOBBER attempt 2
Date: Fri, 24 Apr 1998 09:06:47 +0100 [thread overview]
Message-ID: <199804240806.JAA23565@diamond.tao.co.uk> (raw)
-----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-----
reply other threads:[~1998-04-24 8:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199804240806.JAA23565@diamond.tao.co.uk \
--to=zefram@tao.co.uk \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).