On March 31, 2003 11:31 pm, Alexandre Julliard wrote:
Yes, it's just that I don't like to add non-Unix APIs to the portability layer, but I guess there are good reasons for making an exception here.
I agree -- adding non-Unix APIs is not a good idea. 100% with you. But this one is one particular case of a common operation that is hard to emulate with other APIs, and when emulated, it's slow and/or buggy :).
OK, here's a patch to add _spawnvp to the portability lib. There are still a few questions: -- Should we provide the entire family (I wouldn't, unless we really need them, but that can wait for that need :))? -- What about conflicts with stuff in dlls/msvcrt/process.c? What if we need wine/port. in process.c in the future (not a big deal, we can fudge it then)? What about winelib apps that link with msvcrt?
ChangeLog Add _spawnvp to the portability lib.
Index: include/wine/port.h =================================================================== RCS file: /var/cvs/wine/include/wine/port.h,v retrieving revision 1.36 diff -u -r1.36 port.h --- include/wine/port.h 28 Mar 2003 00:36:13 -0000 1.36 +++ include/wine/port.h 1 Apr 2003 05:32:12 -0000 @@ -211,6 +211,16 @@ ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset ); #endif /* HAVE_PWRITE */
+#ifndef HAVE__SPAWNVP +/* Process creation flags */ +#define _P_WAIT 0 +#define _P_NOWAIT 1 +#define _P_OVERLAY 2 +#define _P_NOWAITO 3 +#define _P_DETACH 4 +int _spawnvp(int mode, const char *cmdname, char *const argv[]); +#endif /* HAVE__SPAWNVP */ + #ifndef HAVE_STATFS int statfs(const char *name, struct statfs *info); #endif /* !defined(HAVE_STATFS) */ Index: libs/port/Makefile.in =================================================================== RCS file: /var/cvs/wine/libs/port/Makefile.in,v retrieving revision 1.5 diff -u -r1.5 Makefile.in --- libs/port/Makefile.in 20 Mar 2003 23:44:36 -0000 1.5 +++ libs/port/Makefile.in 1 Apr 2003 05:20:57 -0000 @@ -16,6 +16,7 @@ mkstemps.c \ pread.c \ pwrite.c \ + spawn.c \ statfs.c \ strcasecmp.c \ strerror.c \ --- /dev/null 2002-08-30 19:31:37.000000000 -0400 +++ libs/port/spawn.c 2003-04-01 00:31:40.000000000 -0500 @@ -0,0 +1,51 @@ +/* + * _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 <errno.h> +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif +#include <sys/stat.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#ifndef HAVE__SPAWNVP +int _spawnvp(int mode, const char *cmdname, char *const argv[]) +{ + 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 */ +} +#endif /* HAVE__SPAWNVP */