quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [patch 5/5] port of Joe's backup-files.c over my nftw/ftw/ft


From: Gary V. Vaughan
Subject: [Quilt-dev] [patch 5/5] port of Joe's backup-files.c over my nftw/ftw/fts replacement
Date: Thu, 15 Sep 2005 16:15:38 +0100
User-agent: Mozilla Thunderbird 1.0 (X11/20050305)

First set some canonical macros to recognise various flavours of Windows
and then use them to patch up some file-system accesses on Windows.

 lib/backup-files.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

Index: quilt-HEAD/lib/backup-files.c
===================================================================
--- quilt-HEAD.orig/lib/backup-files.c
+++ quilt-HEAD/lib/backup-files.c
@@ -25,12 +25,27 @@
  * -B and -Z options.
  */

-#define _GNU_SOURCE
-
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif

+#define _GNU_SOURCE
+
+#if defined(__MINGW32__) && !defined(__MINGW__)
+# define __MINGW__ __MINGW32__
+#endif
+#if defined(__CYGWIN32__) && !defined(__CYGWIN__)
+# define __CYGWIN__ __CYGWIN32__
+#endif
+#if defined(_WIN32) && !defined(WIN32)
+# define WIN32 _WIN32
+#if defined(WIN32) && !defined(__WINDOWS__)
+# define __WINDOWS__ WIN32
+#endif
+#if defined(__CYGWIN__) && defined(__WINDOWS__)
+# undef __WINDOWS__
+#endif
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <utime.h>
@@ -111,7 +126,11 @@ create_parents(const char *filename)
        while (f != NULL) {
                *f = '\0';
                if (!rv || (rv = stat(f, &st)) != 0) {
+#ifdef __WINDOWS__
+                       mkdir(fn);
+#else
                        mkdir(fn, 0777);
+#endif
                }
                *f = '/';
                f = strchr(f+1, '/');
@@ -150,6 +169,7 @@ link_or_copy(const char *from, struct st
 {
        int from_fd, to_fd, error = 1;

+#ifndef __WINDOWS__
        if (link(from, to) == 0)
                return 0;
        if (errno != EXDEV && errno != EPERM && errno != EMLINK) {
@@ -159,11 +179,18 @@ link_or_copy(const char *from, struct st
        }

        if ((from_fd = open(from, O_RDONLY)) == -1) {
+#else
+ if ((from_fd = open(from, O_RDONLY|O_BINARY, _S_IREAD|_S_IWRITE)) == -1) {
+#endif
                perror(from);
                return 1;
        }
        unlink(to);  /* make sure we don't inherit this file's mode. */
+#ifdef __WINDOWS__
+ if ((to_fd = open(to, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, _S_IREAD|_S_IWRITE)) != -1) {
+#else
        if ((to_fd = creat(to, st->st_mode))) {
+#endif
                perror(to);
                close(from_fd);
                return 1;

--
Gary V. Vaughan      ())_.  address@hidden,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]