diff options
author | Kevin Ryde <user42@zip.com.au> | 2004-08-05 01:02:58 +0000 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2004-08-05 01:02:58 +0000 |
commit | 37eb673bc67904e2af6513c2e3812db12157b0a7 (patch) | |
tree | 6a8b5ae3ba8db0f40516f82d8f618466be0b4f5c /libguile/filesys.c | |
parent | 29e61124410f18bc17805aa2d3cedbbae71bd815 (diff) | |
download | guile-37eb673bc67904e2af6513c2e3812db12157b0a7.tar.gz |
(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.
Diffstat (limited to 'libguile/filesys.c')
-rw-r--r-- | libguile/filesys.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c index be8199a9b..29c86883e 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1408,23 +1408,31 @@ SCM_DEFINE (scm_copy_file, "copy-file", 2, 0, 0, #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; } |