]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
More Woe32 support.
authorBruno Haible <bruno@clisp.org>
Mon, 31 Mar 2003 20:18:34 +0000 (20:18 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:18 +0000 (12:10 +0200)
13 files changed:
gettext-tools/lib/ChangeLog
gettext-tools/lib/Makefile.am
gettext-tools/lib/Makefile.msvc
gettext-tools/lib/copy-file.c
gettext-tools/lib/execute.c
gettext-tools/lib/javacomp.c
gettext-tools/lib/pipe-bidi.c
gettext-tools/lib/pipe-in.c
gettext-tools/lib/pipe-out.c
gettext-tools/lib/pipe.h
gettext-tools/lib/progname.c
gettext-tools/lib/relocatable.h
gettext-tools/lib/wait-process.c

index c57b5c7c76b3bab10958678d76629073444f9c32..15f1a97e6750ceb1ccdabdf2b00c62b245292764 100644 (file)
@@ -1,3 +1,30 @@
+2003-03-30  Bruno Haible  <bruno@clisp.org>
+
+       * progname.c (ISSLASH, HAS_DEVICE, IS_PATH_WITH_DIR,
+       FILESYSTEM_PREFIX_LEN): New macros.
+       (maybe_executable): Make a nop on Woe32.
+       (find_executable) [WIN32]: Fix compilation.
+
+       * relocatable.h (RELOCATABLE_DLL_EXPORTED): New macro.
+
+       * w32spawn.h: New file.
+       * execute.c: Add alternative implementation using native Woe32 API.
+       * pipe-bidi.c: Likewise.
+       * pipe-in.c: Likewise.
+       * pipe-out.c: Likewise.
+       * wait-process.c: Likewise.
+       * Makefile.am (libgettextlib_la_SOURCES): Add w32spawn.h.
+
+       * pipe.h (DEV_NULL): New macro.
+       * javacomp.c (compile_java_class): Use DEV_NULL instead of "/dev/null".
+
+       * pipe-bidi.c (STDERR_FILENO): Provide a fallback value.
+       * pipe-in.c (STDERR_FILENO): Likewise.
+       * pipe-out.c (STDERR_FILENO): Likewise.
+
+       * copy-file.c (copy_file_preserving): Don't set owner if the function
+       chown() doesn't exist.
+
 2003-03-17  Bruno Haible  <bruno@clisp.org>
 
        Native Woe32/MSVC support.
index 7c64a5f7026e7b4837431216a304eaf7e08218c8..db30d431ec77fd608e01388e776c3e7994910aad 100644 (file)
@@ -39,7 +39,7 @@ libgettextlib_la_SOURCES = \
   classpath.h classpath.c \
   copy-file.h copy-file.c \
   error.h error.c \
-  execute.h execute.c \
+  execute.h execute.c w32spawn.h \
   exit.h \
   findprog.h findprog.c \
   fstrcmp.h fstrcmp.c \
@@ -55,7 +55,7 @@ libgettextlib_la_SOURCES = \
   obstack.h obstack.c \
   pathmax.h \
   pathname.h concatpath.c \
-  pipe.h pipe-bidi.c pipe-in.c pipe-out.c \
+  pipe.h pipe-bidi.c pipe-in.c pipe-out.c w32spawn.h \
   progname.h progname.c \
   safe-read.h safe-read.c \
   safe-write.h safe-write.c \
index 0cde6b04c9eecfaea49f0881fd5a6e4123db64ad..b49a2b72b9031021d09307e6b72235363d9ff776 100644 (file)
@@ -28,6 +28,8 @@ MFLAGS=-MD
 prefix = c:\usr
 exec_prefix = $(prefix)
 bindir = $(exec_prefix)\bin
+libdir = $(exec_prefix)\lib
+includedir = $(prefix)\include
 
 # Programs used by "make":
 
@@ -52,9 +54,9 @@ OPTIMFLAGS = -Od -Z7
 OPTIMFLAGS = -D_NDEBUG -O1
 !endif
 
-CFLAGS = $(MFLAGS) $(WARN_CFLAGS) $(OPTIMFLAGS) -DHAVE_CONFIG_H
+CFLAGS = $(MFLAGS) $(WARN_CFLAGS) $(OPTIMFLAGS) -DHAVE_CONFIG_H -DEXEEXT=\".exe\"
 
-INCLUDES =
+INCLUDES = -I. -I.. -I..\intl -I..\windows -I$(includedir)
 
 AR = lib
 AR_FLAGS = /out:
@@ -94,7 +96,6 @@ OBJECTS = \
   concatpath.obj \
   pipe-bidi.obj pipe-in.obj pipe-out.obj \
   progname.obj \
-  relocatable.obj \
   safe-read.obj \
   safe-write.obj \
   sh-quote.obj \
@@ -198,9 +199,6 @@ pipe-out.obj : pipe-out.c
 progname.obj : progname.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c progname.c
 
-relocatable.obj : relocatable.c
-       $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c relocatable.c
-
 safe-read.obj : safe-read.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c safe-read.c
 
@@ -276,8 +274,8 @@ gettextlib.lib : $(OBJECTS)
 !else
 
 # gettextlib.dll and gettextlib.lib are created together.
-gettextlib.lib : $(OBJECTS) $(RESOURCES)
-       $(CC) $(MFLAGS) -LD $(OBJECTS) $(RESOURCES)
+gettextlib.lib : ..\windows\gettextlib.def $(OBJECTS) $(RESOURCES)
+       $(CC) $(MFLAGS) -LD ..\windows\gettextlib.def $(OBJECTS) ..\intl\intl.lib $(libdir)\iconv.lib $(RESOURCES) -Fegettextlib.dll
 
 gettextlib.res : ../windows/gettextlib.rc
        rc -Fo gettextlib.res ../windows/gettextlib.rc
index a03047b58ead3e87c2f9a9d023678771e04468e3..7de2ca63d84bc4aac632011dfe81a3ee5bfdf6e2 100644 (file)
@@ -108,8 +108,10 @@ copy_file_preserving (const char *src_filename, const char *dest_filename)
   }
 #endif
 
+#if HAVE_CHOWN
   /* Preserve the owner and group.  */
   chown (dest_filename, statbuf.st_uid, statbuf.st_gid);
+#endif
 
   /* Preserve the access permissions.  */
   chmod (dest_filename, mode);
index 0c5bcaaa960b31bdabab05f3308058b51413637b..c51e7cbead04f6856d8bd6cf5864370841e35aa6 100644 (file)
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_POSIX_SPAWN
-# include <spawn.h>
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+# include <process.h>
+# include "w32spawn.h"
+
 #else
-# ifdef HAVE_VFORK_H
-#  include <vfork.h>
+
+/* Unix API.  */
+# ifdef HAVE_POSIX_SPAWN
+#  include <spawn.h>
+# else
+#  ifdef HAVE_VFORK_H
+#   include <vfork.h>
+#  endif
 # endif
+
 #endif
 
 #include "error.h"
@@ -104,6 +115,71 @@ execute (const char *progname,
         bool null_stdin, bool null_stdout, bool null_stderr,
         bool exit_on_error)
 {
+#if defined _MSC_VER || defined __MINGW32__
+
+  /* Native Woe32 API.  */
+  int orig_stdin;
+  int orig_stdout;
+  int orig_stderr;
+  int child;
+  int nullinfd;
+  int nulloutfd;
+
+  prog_argv = prepare_spawn (prog_argv);
+
+  /* Save standard file handles of parent process.  */
+  if (null_stdin)
+    orig_stdin = dup_noinherit (STDIN_FILENO);
+  if (null_stdout)
+    orig_stdout = dup_noinherit (STDOUT_FILENO);
+  if (null_stderr)
+    orig_stderr = dup_noinherit (STDERR_FILENO);
+  child = -1;
+
+  /* Create standard file handles of child process.  */
+  nullinfd = -1;
+  nulloutfd = -1;
+  if ((!null_stdin
+       || ((nullinfd = open ("NUL", O_RDONLY, 0)) >= 0
+          && (nullinfd == STDIN_FILENO
+              || (dup2 (nullinfd, STDIN_FILENO) >= 0
+                  && close (nullinfd) >= 0))))
+      && (!(null_stdout || null_stderr)
+         || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+             && (!null_stdout
+                 || nulloutfd == STDOUT_FILENO
+                 || dup2 (nulloutfd, STDOUT_FILENO) >= 0)
+             && (!null_stderr
+                 || nulloutfd == STDERR_FILENO
+                 || dup2 (nulloutfd, STDERR_FILENO) >= 0)
+             && ((null_stdout && nulloutfd == STDOUT_FILENO)
+                 || (null_stderr && nulloutfd == STDERR_FILENO)
+                 || close (nulloutfd) >= 0))))
+    child = spawnvp (P_WAIT, prog_path, prog_argv);
+  if (nulloutfd >= 0)
+    close (nulloutfd);
+  if (nullinfd >= 0)
+    close (nullinfd);
+
+  /* Restore standard file handles of parent process.  */
+  if (null_stderr)
+    dup2 (orig_stderr, STDERR_FILENO), close (orig_stderr);
+  if (null_stdout)
+    dup2 (orig_stdout, STDOUT_FILENO), close (orig_stdout);
+  if (null_stdin)
+    dup2 (orig_stdin, STDIN_FILENO), close (orig_stdin);
+
+  if (child == -1)
+    {
+      if (exit_on_error)
+       error (EXIT_FAILURE, errno, _("%s subprocess failed"), progname);
+      else
+       return 127;
+    }
+
+#else
+
+  /* Unix API.  */
   /* Note about 127: Some errors during posix_spawnp() cause the function
      posix_spawnp() to return an error code; some other errors cause the
      subprocess to exit with return code 127.  It is implementation
@@ -186,6 +262,8 @@ execute (const char *progname,
       else
        return 127;
     }
+#endif
+
 #endif
 
   return wait_subprocess (child, progname, exit_on_error);
index 03c9fe11bc9d0327d7c076f7bc088d0df6e0a7ab..21e63f783577920dd7a722c33eba1d4f892a1502 100644 (file)
@@ -198,8 +198,7 @@ compile_java_class (const char * const *java_sources,
        argv[0] = "gcj";
        argv[1] = "--version";
        argv[2] = NULL;
-       child = create_pipe_in ("gcj", "gcj", argv, "/dev/null", true, false,
-                               fd);
+       child = create_pipe_in ("gcj", "gcj", argv, DEV_NULL, true, false, fd);
        gcj_present = false;
        if (child != -1)
          {
index 1e51af5d2e8c843b3106b2b38eee2513b479f4ce..31364a8d873da85b5763adda56f6350edc09e4d7 100644 (file)
@@ -1,5 +1,5 @@
 /* Creation of subprocesses, communicating via pipes.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_POSIX_SPAWN
-# include <spawn.h>
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+# include <process.h>
+# include "w32spawn.h"
+
 #else
-# ifdef HAVE_VFORK_H
-#  include <vfork.h>
+
+/* Unix API.  */
+# ifdef HAVE_POSIX_SPAWN
+#  include <spawn.h>
+# else
+#  ifdef HAVE_VFORK_H
+#   include <vfork.h>
+#  endif
 # endif
+
 #endif
 
 #include "error.h"
@@ -50,6 +61,9 @@
 #ifndef STDOUT_FILENO
 # define STDOUT_FILENO 1
 #endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
 
 #define _(str) gettext (str)
 
@@ -91,6 +105,88 @@ create_pipe_bidi (const char *progname,
                  bool exit_on_error,
                  int fd[2])
 {
+#if defined _MSC_VER || defined __MINGW32__
+
+  /* Native Woe32 API.
+     This uses _pipe(), dup2(), and spawnv().  It could also be implemented
+     using the low-level functions CreatePipe(), DuplicateHandle(),
+     CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
+     and cvs source code.  */
+  int ifd[2];
+  int ofd[2];
+  int orig_stdin;
+  int orig_stdout;
+  int orig_stderr;
+  int child;
+  int nulloutfd;
+
+  prog_argv = prepare_spawn (prog_argv);
+
+  if (_pipe (ifd, 4096, O_BINARY | O_NOINHERIT) < 0)
+    error (EXIT_FAILURE, errno, _("cannot create pipe"));
+  if (_pipe (ofd, 4096, O_BINARY | O_NOINHERIT) < 0)
+    error (EXIT_FAILURE, errno, _("cannot create pipe"));
+/* Data flow diagram:
+ *
+ *           write        system         read
+ *    parent  ->   ofd[1]   ->   ofd[0]   ->   child
+ *    parent  <-   ifd[0]   <-   ifd[1]   <-   child
+ *           read         system         write
+ *
+ */
+
+  /* Save standard file handles of parent process.  */
+  orig_stdin = dup_noinherit (STDIN_FILENO);
+  orig_stdout = dup_noinherit (STDOUT_FILENO);
+  if (null_stderr)
+    orig_stderr = dup_noinherit (STDERR_FILENO);
+  child = -1;
+
+  /* Create standard file handles of child process.  */
+  nulloutfd = -1;
+  if (dup2 (ofd[0], STDIN_FILENO) >= 0
+      && dup2 (ifd[1], STDOUT_FILENO) >= 0
+      && (!null_stderr
+         || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+             && (nulloutfd == STDERR_FILENO
+                 || (dup2 (nulloutfd, STDERR_FILENO) >= 0
+                     && close (nulloutfd) >= 0)))))
+    /* The child process doesn't inherit ifd[0], ifd[1], ofd[0], ofd[1],
+       but it inherits all open()ed or dup2()ed file handles (which is what
+       we want in the case of STD*_FILENO) and also orig_stdin,
+       orig_stdout, orig_stderr (which is not explicitly wanted but
+       harmless).  */
+    child = spawnvp (P_NOWAIT, prog_path, prog_argv);
+  if (nulloutfd >= 0)
+    close (nulloutfd);
+
+  /* Restore standard file handles of parent process.  */
+  if (null_stderr)
+    dup2 (orig_stderr, STDERR_FILENO), close (orig_stderr);
+  dup2 (orig_stdout, STDOUT_FILENO), close (orig_stdout);
+  dup2 (orig_stdin, STDIN_FILENO), close (orig_stdin);
+
+  close (ofd[0]);
+  close (ifd[1]);
+  if (child == -1)
+    {
+      if (exit_on_error)
+       error (EXIT_FAILURE, errno, _("%s subprocess failed"), progname);
+      else
+       {
+         close (ifd[0]);
+         close (ofd[1]);
+         return -1;
+       }
+    }
+
+  fd[0] = ifd[0];
+  fd[1] = ofd[1];
+  return child;
+
+#else
+
+  /* Unix API.  */
   int ifd[2];
   int ofd[2];
 #if HAVE_POSIX_SPAWN
@@ -192,4 +288,6 @@ create_pipe_bidi (const char *progname,
   fd[0] = ifd[0];
   fd[1] = ofd[1];
   return child;
+
+#endif
 }
index 4273dc1df3f6ebe6e8ccdc068dfe264efa100faa..ec661aadf21a02a515d0c031b72b4b5dfb142f20 100644 (file)
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_POSIX_SPAWN
-# include <spawn.h>
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+# include <process.h>
+# include "w32spawn.h"
+
 #else
-# ifdef HAVE_VFORK_H
-#  include <vfork.h>
+
+/* Unix API.  */
+# ifdef HAVE_POSIX_SPAWN
+#  include <spawn.h>
+# else
+#  ifdef HAVE_VFORK_H
+#   include <vfork.h>
+#  endif
 # endif
+
 #endif
 
 #include "error.h"
@@ -50,6 +61,9 @@
 #ifndef STDOUT_FILENO
 # define STDOUT_FILENO 1
 #endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
 
 #define _(str) gettext (str)
 
@@ -103,6 +117,89 @@ create_pipe_in (const char *progname,
                bool exit_on_error,
                int fd[1])
 {
+#if defined _MSC_VER || defined __MINGW32__
+
+  /* Native Woe32 API.
+     This uses _pipe(), dup2(), and spawnv().  It could also be implemented
+     using the low-level functions CreatePipe(), DuplicateHandle(),
+     CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
+     and cvs source code.  */
+  int ifd[2];
+  int orig_stdin;
+  int orig_stdout;
+  int orig_stderr;
+  int child;
+  int nulloutfd;
+  int stdinfd;
+
+  prog_argv = prepare_spawn (prog_argv);
+
+  if (_pipe (ifd, 4096, O_BINARY | O_NOINHERIT) < 0)
+    error (EXIT_FAILURE, errno, _("cannot create pipe"));
+/* Data flow diagram:
+ *
+ *           read        system         write
+ *    parent  <-  ifd[0]   <-   ifd[1]   <-   child
+ */
+
+  /* Save standard file handles of parent process.  */
+  if (prog_stdin != NULL)
+    orig_stdin = dup_noinherit (STDIN_FILENO);
+  orig_stdout = dup_noinherit (STDOUT_FILENO);
+  if (null_stderr)
+    orig_stderr = dup_noinherit (STDERR_FILENO);
+  child = -1;
+
+  /* Create standard file handles of child process.  */
+  nulloutfd = -1;
+  stdinfd = -1;
+  if (dup2 (ifd[1], STDOUT_FILENO) >= 0
+      && (!null_stderr
+         || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+             && (nulloutfd == STDERR_FILENO
+                 || (dup2 (nulloutfd, STDERR_FILENO) >= 0
+                     && close (nulloutfd) >= 0))))
+      && (prog_stdin == NULL
+         || ((stdinfd = open (prog_stdin, O_RDONLY, 0)) >= 0
+             && (stdinfd == STDIN_FILENO
+                 || (dup2 (stdinfd, STDIN_FILENO) >= 0
+                     && close (stdinfd) >= 0)))))
+    /* The child process doesn't inherit ifd[0] and ifd[1], but it
+       inherits all open()ed or dup2()ed file handles (which is what
+       we want in the case of STD*_FILENO) and also orig_stdin,
+       orig_stdout, orig_stderr (which is not explicitly wanted but
+       harmless).  */
+    child = spawnvp (P_NOWAIT, prog_path, prog_argv);
+  if (stdinfd >= 0)
+    close (stdinfd);
+  if (nulloutfd >= 0)
+    close (nulloutfd);
+
+  /* Restore standard file handles of parent process.  */
+  if (null_stderr)
+    dup2 (orig_stderr, STDERR_FILENO), close (orig_stderr);
+  dup2 (orig_stdout, STDOUT_FILENO), close (orig_stdout);
+  if (prog_stdin != NULL)
+    dup2 (orig_stdin, STDIN_FILENO), close (orig_stdin);
+
+  close (ifd[1]);
+  if (child == -1)
+    {
+      if (exit_on_error)
+       error (EXIT_FAILURE, errno, _("%s subprocess failed"), progname);
+      else
+       {
+         close (ifd[0]);
+         return -1;
+       }
+    }
+
+  fd[0] = ifd[0];
+  return child;
+
+#else
+
+  /* Unix API.  */
   int ifd[2];
 #if HAVE_POSIX_SPAWN
   posix_spawn_file_actions_t actions;
@@ -196,4 +293,6 @@ create_pipe_in (const char *progname,
 
   fd[0] = ifd[0];
   return child;
+
+#endif
 }
index cda7db303990ac10d2337264b790cf5f9aa189b0..199116e748af3aa986a086a5096273a77c245b01 100644 (file)
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_POSIX_SPAWN
-# include <spawn.h>
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+# include <process.h>
+# include "w32spawn.h"
+
 #else
-# ifdef HAVE_VFORK_H
-#  include <vfork.h>
+
+/* Unix API.  */
+# ifdef HAVE_POSIX_SPAWN
+#  include <spawn.h>
+# else
+#  ifdef HAVE_VFORK_H
+#   include <vfork.h>
+#  endif
 # endif
+
 #endif
 
 #include "error.h"
@@ -50,6 +61,9 @@
 #ifndef STDOUT_FILENO
 # define STDOUT_FILENO 1
 #endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
 
 #define _(str) gettext (str)
 
@@ -103,6 +117,89 @@ create_pipe_out (const char *progname,
                 bool exit_on_error,
                 int fd[1])
 {
+#if defined _MSC_VER || defined __MINGW32__
+
+  /* Native Woe32 API.
+     This uses _pipe(), dup2(), and spawnv().  It could also be implemented
+     using the low-level functions CreatePipe(), DuplicateHandle(),
+     CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
+     source code.  */
+  int ofd[2];
+  int orig_stdin;
+  int orig_stdout;
+  int orig_stderr;
+  int child;
+  int nulloutfd;
+  int stdoutfd;
+
+  prog_argv = prepare_spawn (prog_argv);
+
+  if (_pipe (ofd, 4096, O_BINARY | O_NOINHERIT) < 0)
+    error (EXIT_FAILURE, errno, _("cannot create pipe"));
+/* Data flow diagram:
+ *
+ *           write        system         read
+ *    parent  ->   ofd[1]   ->   ofd[0]   ->   child
+ */
+
+  /* Save standard file handles of parent process.  */
+  orig_stdin = dup_noinherit (STDIN_FILENO);
+  if (prog_stdout != NULL)
+    orig_stdout = dup_noinherit (STDOUT_FILENO);
+  if (null_stderr)
+    orig_stderr = dup_noinherit (STDERR_FILENO);
+  child = -1;
+
+  /* Create standard file handles of child process.  */
+  nulloutfd = -1;
+  stdoutfd = -1;
+  if (dup2 (ofd[0], STDIN_FILENO) >= 0
+      && (!null_stderr
+         || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+             && (nulloutfd == STDERR_FILENO
+                 || (dup2 (nulloutfd, STDERR_FILENO) >= 0
+                     && close (nulloutfd) >= 0))))
+      && (prog_stdout == NULL
+         || ((stdoutfd = open (prog_stdout, O_WRONLY, 0)) >= 0
+             && (stdoutfd == STDOUT_FILENO
+                 || (dup2 (stdoutfd, STDOUT_FILENO) >= 0
+                     && close (stdoutfd) >= 0)))))
+    /* The child process doesn't inherit ofd[0] and ofd[1], but it
+       inherits all open()ed or dup2()ed file handles (which is what
+       we want in the case of STD*_FILENO) and also orig_stdin,
+       orig_stdout, orig_stderr (which is not explicitly wanted but
+       harmless).  */
+    child = spawnvp (P_NOWAIT, prog_path, prog_argv);
+  if (stdoutfd >= 0)
+    close (stdoutfd);
+  if (nulloutfd >= 0)
+    close (nulloutfd);
+
+  /* Restore standard file handles of parent process.  */
+  if (null_stderr)
+    dup2 (orig_stderr, STDERR_FILENO), close (orig_stderr);
+  if (prog_stdout != NULL)
+    dup2 (orig_stdout, STDOUT_FILENO), close (orig_stdout);
+  dup2 (orig_stdin, STDIN_FILENO), close (orig_stdin);
+
+  close (ofd[0]);
+  if (child == -1)
+    {
+      if (exit_on_error)
+       error (EXIT_FAILURE, errno, _("%s subprocess failed"), progname);
+      else
+       {
+         close (ofd[1]);
+         return -1;
+       }
+    }
+
+  fd[0] = ofd[1];
+  return child;
+
+#else
+
+  /* Unix API.  */
   int ofd[2];
 #if HAVE_POSIX_SPAWN
   posix_spawn_file_actions_t actions;
@@ -196,4 +293,5 @@ create_pipe_out (const char *progname,
 
   fd[0] = ofd[1];
   return child;
+#endif
 }
index f32dcaf0cc4bdf0d9b880a384d5cf17f67173026..97e02ac087923d7f53fedafbdf86e6baa768fdf5 100644 (file)
@@ -1,5 +1,5 @@
 /* Creation of subprocesses, communicating via pipes.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -86,4 +86,13 @@ extern pid_t create_pipe_bidi (const char *progname,
                               bool exit_on_error,
                               int fd[2]);
 
+/* The name of the "always silent" device.  */
+#if defined _MSC_VER || defined __MINGW32__
+/* Native Woe32 API.  */
+# define DEV_NULL "NUL"
+#else
+/* Unix API.  */
+# define DEV_NULL "/dev/null"
+#endif
+
 #endif /* _PIPE_H */
index 11bf92ebe37ed7272dcae4c1e69790a9cd4f6cdd..7b99132626de4401fe64547ba3b151c35493a09b 100644 (file)
 # include "xmalloc.h"
 #endif
 
+/* Pathname support.
+   ISSLASH(C)           tests whether C is a directory separator character.
+   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
+  /* Win32, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+     && (P)[1] == ':')
+# define IS_PATH_WITH_DIR(P) \
+    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+# define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
+#else
+  /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
+# define FILESYSTEM_PREFIX_LEN(P) 0
+#endif
+
 #undef set_program_name
 
 
@@ -96,6 +116,7 @@ static int executable_fd = -1;
 static bool
 maybe_executable (const char *filename)
 {
+#if !defined WIN32
   if (access (filename, X_OK) < 0)
     return false;
 
@@ -117,6 +138,7 @@ maybe_executable (const char *filename)
            return false;
        }
     }
+#endif
 #endif
 
   return true;
@@ -134,7 +156,7 @@ find_executable (const char *argv0)
   int length = GetModuleFileName (NULL, buf, sizeof (buf));
   if (length < 0)
     return NULL;
-  if (!IS_PATH_WITH_DIR (location))
+  if (!IS_PATH_WITH_DIR (buf))
     /* Shouldn't happen.  */
     return NULL;
   return xstrdup (buf);
index 9ca617ada0e28b7da27acfb8fda31e22561f4781..d141200a64235d6820be3406436f839632e775c8 100644 (file)
 /* This can be enabled through the configure --enable-relocatable option.  */
 #if ENABLE_RELOCATABLE
 
+/* When building a DLL, we must export some functions.  Note that because
+   this is a private .h file, we don't need to use __declspec(dllimport)
+   in any case.  */
+#if defined _MSC_VER && BUILDING_DLL
+# define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
+#else
+# define RELOCATABLE_DLL_EXPORTED
+#endif
+
 /* Sets the original and the current installation prefix of the package.
    Relocation simply replaces a pathname starting with the original prefix
    by the corresponding pathname with the current prefix instead.  Both
    prefixes should be directory names without trailing slash (i.e. use ""
    instead of "/").  */
-extern void set_relocation_prefix (const char *orig_prefix,
-                                  const char *curr_prefix);
+extern RELOCATABLE_DLL_EXPORTED void
+       set_relocation_prefix (const char *orig_prefix,
+                             const char *curr_prefix);
 
 /* Returns the pathname, relocated according to the current installation
    directory.  */
index af315f0c7b607bdb0af4dccb2110ce06fddce8e5..ef393a69a8b1c8be70964a03066439c6aafcf29b 100644 (file)
@@ -1,5 +1,5 @@
 /* Waiting for a subprocess to finish.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
 
 #include <sys/types.h>
 
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+
+int
+wait_subprocess (pid_t child, const char *progname, bool exit_on_error)
+{
+  /* Not yet implemented.  Should probably use _cwait.  */
+  return 127;
+}
+
+#else
+
+/* Unix API.  */
+
+#if defined _MSC_VER || defined __MINGW32__
+
+/* Native Woe32 API.  */
+#include <process.h>
+#define waitpid(pid,statusp,options) _cwait (statusp, pid, WAIT_CHILD)
+#define WAIT_T int
+#define WTERMSIG(x) ((x) & 0xff) /* or: SIGABRT ?? */
+#define WCOREDUMP(x) 0
+#define WEXITSTATUS(x) (((x) >> 8) & 0xff) /* or: (x) ?? */
+#define WIFSIGNALED(x) (WTERMSIG (x) != 0) /* or: ((x) == 3) ?? */
+#define WIFEXITED(x) (WTERMSIG (x) == 0) /* or: ((x) != 3) ?? */
+#define WIFSTOPPED(x) 0
+
+#else
+
+/* Unix API.  */
 #include <sys/wait.h>
 /* On Linux, WEXITSTATUS are bits 15..8 and WTERMSIG are bits 7..0, while
    BeOS uses the contrary.  Therefore we use the abstract macros.  */
    WTERMSIG(x) only if WIFSIGNALED(x) is true, and
    WEXITSTATUS(x) only if WIFEXITED(x) is true.  */
 
+#endif
+
 #include "error.h"
 #include "exit.h"
 #include "gettext.h"
@@ -132,3 +165,5 @@ wait_subprocess (pid_t child, const char *progname, bool exit_on_error)
     }
   return WEXITSTATUS (status);
 }
+
+#endif /* Woe32 / Unix */