source: trunk/libs/newlib/src/newlib/libc/reent/execr.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.2 KB
Line 
1/* Reentrant versions of execution system calls.  These
2   implementations just call the usual system calls.  */
3
4#include <reent.h>
5#include <unistd.h>
6#include <sys/wait.h>
7#include <_syslist.h>
8
9/* Some targets provides their own versions of these functions.  Those
10   targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
11
12#ifdef _REENT_ONLY
13#ifndef REENTRANT_SYSCALLS_PROVIDED
14#define REENTRANT_SYSCALLS_PROVIDED
15#endif
16#endif
17
18/* If NO_EXEC is defined, we don't need these functions.  */
19
20#if defined (REENTRANT_SYSCALLS_PROVIDED) || defined (NO_EXEC)
21
22int _dummy_exec_syscalls = 1;
23
24#else
25
26/* We use the errno variable used by the system dependent layer.  */
27#undef errno
28extern int errno;
29
30/*
31FUNCTION
32        <<_execve_r>>---Reentrant version of execve     
33INDEX
34        _execve_r
35
36SYNOPSIS
37        #include <reent.h>
38        int _execve_r(struct _reent *<[ptr]>, const char *<[name]>,
39                      char *const <[argv]>[], char *const <[env]>[]);
40
41DESCRIPTION
42        This is a reentrant version of <<execve>>.  It
43        takes a pointer to the global data block, which holds
44        <<errno>>.
45*/
46
47int
48_execve_r (struct _reent *ptr,
49     const char *name,
50     char *const argv[],
51     char *const env[])
52{
53  int ret;
54
55  errno = 0;
56  if ((ret = _execve (name, argv, env)) == -1 && errno != 0)
57    ptr->_errno = errno;
58  return ret;
59}
60
61
62/*
63NEWPAGE
64FUNCTION
65        <<_fork_r>>---Reentrant version of fork
66       
67INDEX
68        _fork_r
69
70SYNOPSIS
71        #include <reent.h>
72        int _fork_r(struct _reent *<[ptr]>);
73
74DESCRIPTION
75        This is a reentrant version of <<fork>>.  It
76        takes a pointer to the global data block, which holds
77        <<errno>>.
78*/
79
80#ifndef NO_FORK
81
82int
83_fork_r (struct _reent *ptr)
84{
85  int ret;
86
87  errno = 0;
88  if ((ret = _fork ()) == -1 && errno != 0)
89    ptr->_errno = errno;
90  return ret;
91}
92
93#endif
94
95/*
96NEWPAGE
97FUNCTION
98        <<_wait_r>>---Reentrant version of wait
99       
100INDEX
101        _wait_r
102
103SYNOPSIS
104        #include <reent.h>
105        int _wait_r(struct _reent *<[ptr]>, int *<[status]>);
106
107DESCRIPTION
108        This is a reentrant version of <<wait>>.  It
109        takes a pointer to the global data block, which holds
110        <<errno>>.
111*/
112
113int
114_wait_r (struct _reent *ptr,
115     int *status)
116{
117  int ret;
118
119  errno = 0;
120  if ((ret = _wait (status)) == -1 && errno != 0)
121    ptr->_errno = errno;
122  return ret;
123}
124
125#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
Note: See TracBrowser for help on using the repository browser.