aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/exec.cc
blob: 0e6e535d86cf92b56fad992a0172821e2c549e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* exec.cc: exec system call support.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#include "winsup.h"
#include <process.h>
#include "cygerrno.h"
#include "path.h"
#include "environ.h"
#include "sync.h"
#include "fhandler.h"
#include "dtable.h"
#include "pinfo.h"
#include "cygheap.h"
#include "winf.h"

extern "C" int
execl (const char *path, const char *arg0, ...)
{
  int i;
  va_list args;
  const char *argv[1024];

  va_start (args, arg0);
  argv[0] = arg0;
  i = 1;
  do
      argv[i] = va_arg (args, const char *);
  while (argv[i++] != NULL);
  va_end (args);
  return spawnve (_P_OVERLAY, path, (char * const  *) argv, environ);
}

extern "C" int
execle (const char *path, const char *arg0, ...)
{
  int i;
  va_list args;
  const char *argv[1024];
  const char * const *envp;

  va_start (args, arg0);
  argv[0] = arg0;
  i = 1;
  do
      argv[i] = va_arg (args, const char *);
  while (argv[i++] != NULL);
  envp = va_arg (args, const char * const *);
  va_end (args);
  return spawnve (_P_OVERLAY, path, (char * const  *) argv, envp);
}

extern "C" int
execlp (const char *file, const char *arg0, ...)
{
  int i;
  va_list args;
  const char *argv[1024];
  path_conv buf;

  va_start (args, arg0);
  argv[0] = arg0;
  i = 1;
  do
      argv[i] = va_arg (args, const char *);
  while (argv[i++] != NULL);
  va_end (args);
  return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
		  find_exec (file, buf, "PATH", FE_NNF) ?: "",
		  (char * const  *) argv, environ);
}

extern "C" int
execv (const char *path, char * const *argv)
{
  return spawnve (_P_OVERLAY, path, argv, environ);
}

extern "C" int
execve (const char *path, char *const argv[], char *const envp[])
{
  return spawnve (_P_OVERLAY, path, argv, envp);
}

extern "C" int
execvp (const char *file, char * const *argv)
{
  path_conv buf;

  return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
		  find_exec (file, buf, "PATH", FE_NNF) ?: "",
		  argv, environ);
}

extern "C" int
execvpe (const char *file, char * const *argv, char *const *envp)
{
  path_conv buf;

  return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
		  find_exec (file, buf, "PATH", FE_NNF) ?: "",
		  argv, envp);
}

extern "C" int
fexecve (int fd, char * const *argv, char *const *envp)
{
  cygheap_fdget cfd (fd);
  if (cfd < 0)
    {
      syscall_printf ("-1 = fexecve (%d, %p, %p)", fd, argv, envp);
      return -1;
    }

  return spawnve (_P_OVERLAY, cfd->pc.get_win32 (), argv, envp);
}

extern "C" pid_t
sexecve_is_bad ()
{
  set_errno (ENOSYS);
  return 0;
}

EXPORT_ALIAS (execve, _execve)	/* For newlib */