source: trunk/src/emx/src/lib/process/spawnve.c@ 2254

Last change on this file since 2254 was 2254, checked in by bird, 20 years ago

o LIBC_ASSERT*() are for internal libc errors, LIBCLOG_ERROR*() are

for user related error. Big code adjustements.

o Fixed a few smaller issues.
o Started fixing exec() backend.

  • Property cvs2svn:cvs-rev set to 1.5
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/* spawnve.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
2
3#include "libc-alias.h"
4#include <stdlib.h>
5#include <string.h>
6#include <process.h>
7#include <errno.h>
8#include <alloca.h>
9#include <sys/syslimits.h>
10#include <emx/startup.h>
11#include <emx/syscalls.h>
12#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
13#include <InnoTekLIBC/logstrict.h>
14
15int _STD(spawnve)(int mode, const char *name, char * const argv[], char * const envp[])
16{
17 LIBCLOG_ENTER("mode=%#x name=%s argv=%p envp=%p\n", mode, name, (void *)argv, (void *)envp);
18 struct _new_proc np;
19 int i, size, n, rc;
20 const char * const *p;
21 char *d;
22 char exe[PATH_MAX];
23
24 /*
25 * Init the syscall struct np.
26 */
27 /* mode */
28 np.mode = mode;
29 /* exe name */
30 if (strlen(name) >= sizeof(exe) - 4)
31 {
32 errno = ENAMETOOLONG;
33 LIBCLOG_ERROR_RETURN(-1, "ret -1 - name is too long, %d bytes: %s\n", strlen(name), name);
34 }
35 strcpy(exe, name);
36 _defext(exe, "exe");
37 LIBCLOG_MSG("exe=%s\n", exe);
38 np.fname_off = (unsigned long)exe;
39
40 /* calc environment size */
41 if (envp == NULL)
42 envp = environ;
43 size = 1; n = 0;
44 for (p = (const char * const *)envp; *p != NULL; ++p)
45 {
46 ++n;
47 size += 1 + strlen(*p);
48 }
49 d = alloca(size);
50 LIBCLOG_MSG("environment: %d bytes %d entries block=%p\n", size, n, d);
51 np.env_count = n; np.env_size = size;
52 np.env_off = (unsigned long)d;
53
54 /* copy environment */
55 for (p = (const char * const *)envp; *p != NULL; ++p)
56 {
57 i = strlen(*p);
58 memcpy(d, *p, i + 1);
59 d += i + 1;
60 }
61 *d = 0;
62
63 /* calc argument size */
64 size = 0; n = 0;
65 for (p = (const char * const *)argv; *p != NULL; ++p)
66 {
67 ++n;
68 size += 2 + strlen(*p);
69 }
70 d = alloca(size);
71 LIBCLOG_MSG("arguments: %d bytes %d entries block=%p\n", size, n, d);
72 np.arg_count = n; np.arg_size = size;
73 np.arg_off = (unsigned long)d;
74
75 /* copy arguments */
76 for (p = (const char * const *)argv; *p != NULL; ++p)
77 {
78 i = strlen(*p);
79 *(unsigned char *)d++ = _ARG_NONZERO;
80 memcpy(d, *p, i + 1);
81 d += i + 1;
82 }
83
84 /*
85 * Call syscall.
86 */
87 rc = __spawnve(&np);
88 LIBCLOG_RETURN_INT(rc);
89}
Note: See TracBrowser for help on using the repository browser.