diff --git a/include/wine/port.h b/include/wine/port.h index 97bdabbce15..f7838677e78 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -250,6 +250,16 @@ extern void *memcpy_unaligned( void *dst, const void *src, size_t size ); extern int mkstemps(char *template, int suffix_len); +/* Process creation flags */ +#ifndef _P_WAIT +# define _P_WAIT 0 +# define _P_NOWAIT 1 +# define _P_OVERLAY 2 +# define _P_NOWAITO 3 +# define _P_DETACH 4 +#endif +extern int spawnvp(int mode, const char *cmdname, char *const argv[]); + /* Interlocked functions */ #if defined(__i386__) && defined(__GNUC__) @@ -321,6 +331,7 @@ extern long interlocked_xchg_add( long *dest, long incr ); #define memmove __WINE_NOT_PORTABLE(memmove) #define pread __WINE_NOT_PORTABLE(pread) #define pwrite __WINE_NOT_PORTABLE(pwrite) +#define spawnvp __WINE_NOT_PORTABLE(spawnvp) #define statfs __WINE_NOT_PORTABLE(statfs) #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp) #define strerror __WINE_NOT_PORTABLE(strerror) diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in index c789d8cd78d..11eecc838ee 100644 --- a/libs/port/Makefile.in +++ b/libs/port/Makefile.in @@ -16,6 +16,7 @@ C_SRCS = \ mkstemps.c \ pread.c \ pwrite.c \ + spawn.c \ statfs.c \ strcasecmp.c \ strerror.c \ diff --git a/libs/port/spawn.c b/libs/port/spawn.c new file mode 100644 index 00000000000..c69e024d119 --- /dev/null +++ b/libs/port/spawn.c @@ -0,0 +1,53 @@ +/* + * spawnvp function + * + * Copyright 2003 Dimitrie O. Paun + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#include +#ifdef HAVE_SYS_WAIT_H +#include +#endif +#include +#ifdef HAVE_UNISTD_H +# include +#endif + +int spawnvp(int mode, const char *cmdname, char *const argv[]) +{ +#ifndef HAVE__SPAWNVP + int pid = 0, status, wret; + + if (mode != _P_OVERLAY) pid = fork(); + if (pid == 0) pid = execvp(argv[0], argv); + if (pid < 0) return -1; + + if (mode != _P_WAIT) return pid; + + while (pid != (wret = waitpid(pid, &status, 0))) + if (wret == -1 && errno != EINTR) break; + + if (pid == wret && WIFEXITED(status)) return WEXITSTATUS(status); + + return 255; /* abnormal exit with an abort or an interrupt */ +#else /* HAVE__SPAWNVP */ + return _spawnvp(mode, cmdname, argv); +#endif /* HAVE__SPAWNVP */ +}