summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-03-31 20:18:34 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:10:18 +0200
commit5129bdb430376abc996f6be163ebe45baa6f3c32 (patch)
tree58a72c44d83e4b60cfe6488d167eefd0d272cc97
parent0fbcf3e924cad3983b88783bfd0f8fe80f4464dd (diff)
downloadexternal_gettext-5129bdb430376abc996f6be163ebe45baa6f3c32.zip
external_gettext-5129bdb430376abc996f6be163ebe45baa6f3c32.tar.gz
external_gettext-5129bdb430376abc996f6be163ebe45baa6f3c32.tar.bz2
More Woe32 support.
-rw-r--r--gettext-tools/lib/ChangeLog27
-rw-r--r--gettext-tools/lib/Makefile.am4
-rw-r--r--gettext-tools/lib/Makefile.msvc14
-rw-r--r--gettext-tools/lib/copy-file.c2
-rw-r--r--gettext-tools/lib/execute.c86
-rw-r--r--gettext-tools/lib/javacomp.c3
-rw-r--r--gettext-tools/lib/pipe-bidi.c108
-rw-r--r--gettext-tools/lib/pipe-in.c107
-rw-r--r--gettext-tools/lib/pipe-out.c106
-rw-r--r--gettext-tools/lib/pipe.h11
-rw-r--r--gettext-tools/lib/progname.c24
-rw-r--r--gettext-tools/lib/relocatable.h14
-rw-r--r--gettext-tools/lib/wait-process.c37
13 files changed, 509 insertions, 34 deletions
diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog
index c57b5c7..15f1a97 100644
--- a/gettext-tools/lib/ChangeLog
+++ b/gettext-tools/lib/ChangeLog
@@ -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.
diff --git a/gettext-tools/lib/Makefile.am b/gettext-tools/lib/Makefile.am
index 7c64a5f..db30d43 100644
--- a/gettext-tools/lib/Makefile.am
+++ b/gettext-tools/lib/Makefile.am
@@ -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 \
diff --git a/gettext-tools/lib/Makefile.msvc b/gettext-tools/lib/Makefile.msvc
index 0cde6b0..b49a2b7 100644
--- a/gettext-tools/lib/Makefile.msvc
+++ b/gettext-tools/lib/Makefile.msvc
@@ -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
diff --git a/gettext-tools/lib/copy-file.c b/gettext-tools/lib/copy-file.c
index a03047b..7de2ca6 100644
--- a/gettext-tools/lib/copy-file.c
+++ b/gettext-tools/lib/copy-file.c
@@ -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);
diff --git a/gettext-tools/lib/execute.c b/gettext-tools/lib/execute.c
index 0c5bcaa..c51e7cb 100644
--- a/gettext-tools/lib/execute.c
+++ b/gettext-tools/lib/execute.c
@@ -33,12 +33,23 @@
# 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
@@ -188,5 +264,7 @@ execute (const char *progname,
}
#endif
+#endif
+
return wait_subprocess (child, progname, exit_on_error);
}
diff --git a/gettext-tools/lib/javacomp.c b/gettext-tools/lib/javacomp.c
index 03c9fe1..21e63f7 100644
--- a/gettext-tools/lib/javacomp.c
+++ b/gettext-tools/lib/javacomp.c
@@ -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)
{
diff --git a/gettext-tools/lib/pipe-bidi.c b/gettext-tools/lib/pipe-bidi.c
index 1e51af5..31364a8 100644
--- a/gettext-tools/lib/pipe-bidi.c
+++ b/gettext-tools/lib/pipe-bidi.c
@@ -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
@@ -32,12 +32,23 @@
# 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
}
diff --git a/gettext-tools/lib/pipe-in.c b/gettext-tools/lib/pipe-in.c
index 4273dc1..ec661aa 100644
--- a/gettext-tools/lib/pipe-in.c
+++ b/gettext-tools/lib/pipe-in.c
@@ -32,12 +32,23 @@
# 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
}
diff --git a/gettext-tools/lib/pipe-out.c b/gettext-tools/lib/pipe-out.c
index cda7db3..199116e 100644
--- a/gettext-tools/lib/pipe-out.c
+++ b/gettext-tools/lib/pipe-out.c
@@ -32,12 +32,23 @@
# 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
}
diff --git a/gettext-tools/lib/pipe.h b/gettext-tools/lib/pipe.h
index f32dcaf..97e02ac 100644
--- a/gettext-tools/lib/pipe.h
+++ b/gettext-tools/lib/pipe.h
@@ -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 */
diff --git a/gettext-tools/lib/progname.c b/gettext-tools/lib/progname.c
index 11bf92e..7b99132 100644
--- a/gettext-tools/lib/progname.c
+++ b/gettext-tools/lib/progname.c
@@ -54,6 +54,26 @@
# 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;
@@ -118,6 +139,7 @@ maybe_executable (const char *filename)
}
}
#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);
diff --git a/gettext-tools/lib/relocatable.h b/gettext-tools/lib/relocatable.h
index 9ca617a..d141200 100644
--- a/gettext-tools/lib/relocatable.h
+++ b/gettext-tools/lib/relocatable.h
@@ -23,13 +23,23 @@
/* 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. */
diff --git a/gettext-tools/lib/wait-process.c b/gettext-tools/lib/wait-process.c
index af315f0..ef393a6 100644
--- a/gettext-tools/lib/wait-process.c
+++ b/gettext-tools/lib/wait-process.c
@@ -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
@@ -29,6 +29,37 @@
#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. */
@@ -70,6 +101,8 @@
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 */