unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: copy-file fstat
Date: Mon, 02 Aug 2004 10:47:16 +1000	[thread overview]
Message-ID: <87acxepdrf.fsf@zip.com.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

        * filesys.c (scm_copy_file): Use fstat on the input fd rather than
        stat on the filename, to be certain a file rename can't mean we get
        info on one filesystem object but open another.  This fstat usage is
        similar to Emacs copy-file.

This would be for 1.6 too.  You'd have to be very unlucky to hit the
problem, but it's real enough.


[-- Attachment #2: filesys.c.fstat.diff --]
[-- Type: text/plain, Size: 942 bytes --]

--- filesys.c.~1.129.~	2004-07-31 11:18:38.000000000 +1000
+++ filesys.c	2004-08-02 10:44:56.000000000 +1000
@@ -1408,23 +1408,31 @@
 #define FUNC_NAME s_scm_copy_file
 {
   int oldfd, newfd;
-  int n;
+  int n, rv;
   char buf[BUFSIZ];
   struct stat oldstat;
 
   SCM_VALIDATE_STRING (1, oldfile);
   SCM_VALIDATE_STRING (2, newfile);
-  if (stat (SCM_STRING_CHARS (oldfile), &oldstat) == -1)
-    SCM_SYSERROR;
+
   oldfd = open (SCM_STRING_CHARS (oldfile), O_RDONLY);
   if (oldfd == -1)
     SCM_SYSERROR;
 
+#ifdef __MINGW32__
+  SCM_SYSCALL (rv = fstat_Win32 (oldfd, &oldstat));
+#else
+  SCM_SYSCALL (rv = fstat (oldfd, &oldstat));
+#endif
+  if (rv == -1)
+    goto err_close_oldfd;
+
   /* use POSIX flags instead of 07777?.  */
   newfd = open (SCM_STRING_CHARS (newfile), O_WRONLY | O_CREAT | O_TRUNC,
 		oldstat.st_mode & 07777);
   if (newfd == -1)
     {
+    err_close_oldfd:
       close (oldfd);
       SCM_SYSERROR;
     }

[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

                 reply	other threads:[~2004-08-02  0:47 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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87acxepdrf.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).