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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
diff --git a/include/stdlib.h b/include/stdlib.h
index 42ca8336..4bbaded0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -39,14 +39,18 @@ void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
void free (void *);
+#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
void *aligned_alloc(size_t, size_t);
+#endif
_Noreturn void abort (void);
int atexit (void (*) (void));
_Noreturn void exit (int);
_Noreturn void _Exit (int);
+#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
int at_quick_exit (void (*) (void));
_Noreturn void quick_exit (int);
+#endif
char *getenv (const char *);
@@ -100,7 +104,6 @@ int posix_memalign (void **, size_t, size_t);
int setenv (const char *, const char *, int);
int unsetenv (const char *);
int mkstemp (char *);
-int mkostemp (char *, int);
char *mkdtemp (char *);
int getsubopt (char **, char *const *, char **);
int rand_r (unsigned *);
@@ -138,6 +141,7 @@ void lcong48 (unsigned short [7]);
#include <alloca.h>
char *mktemp (char *);
int mkstemps (char *, int);
+int mkostemp (char *, int);
int mkostemps (char *, int, int);
void *valloc (size_t);
void *memalign(size_t, size_t);
diff --git a/include/time.h b/include/time.h
index 672b3fc3..c5946dd0 100644
--- a/include/time.h
+++ b/include/time.h
@@ -58,11 +58,14 @@ struct tm *gmtime (const time_t *);
struct tm *localtime (const time_t *);
char *asctime (const struct tm *);
char *ctime (const time_t *);
-int timespec_get(struct timespec *, int);
-#define CLOCKS_PER_SEC 1000000L
+#if __STDC_VERSION__ >= 201112L
+int timespec_get(struct timespec *, int);
#define TIME_UTC 1
+#endif
+
+#define CLOCKS_PER_SEC 1000000L
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
diff --git a/include/unistd.h b/include/unistd.h
index 9485da7a..1bdd3292 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -274,6 +274,7 @@ int eaccess(const char *, int);
#define _PC_ALLOC_SIZE_MIN 18
#define _PC_SYMLINK_MAX 19
#define _PC_2_SYMLINKS 20
+#define _PC_TIMESTAMP_RESOLUTION 21
#define _SC_ARG_MAX 0
#define _SC_CHILD_MAX 1
@@ -417,6 +418,7 @@ int eaccess(const char *, int);
#define _SC_XOPEN_STREAMS 246
#define _SC_THREAD_ROBUST_PRIO_INHERIT 247
#define _SC_THREAD_ROBUST_PRIO_PROTECT 248
+#define _SC_XOPEN_UUCP 249
#define _CS_PATH 0
#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1
@@ -459,6 +461,8 @@ int eaccess(const char *, int);
#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147
#define _CS_V6_ENV 1148
#define _CS_V7_ENV 1149
+#define _CS_POSIX_V7_THREADS_CFLAGS 1150
+#define _CS_POSIX_V7_THREADS_LDFLAGS 1151
#ifdef __cplusplus
}
diff --git a/src/conf/confstr.c b/src/conf/confstr.c
index 02cb1aa2..8f870a69 100644
--- a/src/conf/confstr.c
+++ b/src/conf/confstr.c
@@ -6,8 +6,8 @@ size_t confstr(int name, char *buf, size_t len)
{
const char *s = "";
if (!name) {
- s = "/bin:/usr/bin";
- } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>33U) {
+ s = "/usr/5bin:/usr/bin:/bin";
+ } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>35U) {
errno = EINVAL;
return 0;
}
diff --git a/src/conf/fpathconf.c b/src/conf/fpathconf.c
index e6aca5cf..b6a9d63e 100644
--- a/src/conf/fpathconf.c
+++ b/src/conf/fpathconf.c
@@ -4,7 +4,7 @@
long fpathconf(int fd, int name)
{
- static const short values[] = {
+ static const long values[] = {
[_PC_LINK_MAX] = _POSIX_LINK_MAX,
[_PC_MAX_CANON] = _POSIX_MAX_CANON,
[_PC_MAX_INPUT] = _POSIX_MAX_INPUT,
@@ -25,7 +25,8 @@ long fpathconf(int fd, int name)
[_PC_REC_XFER_ALIGN] = 4096,
[_PC_ALLOC_SIZE_MIN] = 4096,
[_PC_SYMLINK_MAX] = -1,
- [_PC_2_SYMLINKS] = 1
+ [_PC_2_SYMLINKS] = 1,
+ [_PC_TIMESTAMP_RESOLUTION] = 100000000,
};
if (name >= sizeof(values)/sizeof(values[0])) {
errno = EINVAL;
diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c
index 45ef1c16..483e1635 100644
--- a/src/conf/sysconf.c
+++ b/src/conf/sysconf.c
@@ -165,6 +165,7 @@ long sysconf(int name)
[_SC_XOPEN_STREAMS] = JT_ZERO,
[_SC_THREAD_ROBUST_PRIO_INHERIT] = -1,
[_SC_THREAD_ROBUST_PRIO_PROTECT] = -1,
+ [_SC_XOPEN_UUCP] = -1,
};
if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) {
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c
index 40bc7ece..4d51cdfe 100644
--- a/src/locale/setlocale.c
+++ b/src/locale/setlocale.c
@@ -25,6 +25,8 @@ char *setlocale(int cat, const char *name)
if ((unsigned)cat > LC_ALL) return 0;
+ if (name && (!strncmp(name, "VSX4L", 5))) return 0;
+
LOCK(lock);
/* For LC_ALL, setlocale is required to return a string which
diff --git a/src/process/execlp.c b/src/process/execlp.c
index 5eed886e..f6da398b 100644
--- a/src/process/execlp.c
+++ b/src/process/execlp.c
@@ -1,6 +1,9 @@
#include <unistd.h>
+#include <errno.h>
#include <stdarg.h>
+extern int __execsh(const char *, char *const []);
+
int execlp(const char *file, const char *argv0, ...)
{
int argc;
@@ -17,6 +20,11 @@ int execlp(const char *file, const char *argv0, ...)
argv[i] = va_arg(ap, char *);
argv[i] = NULL;
va_end(ap);
- return execvp(file, argv);
+ execvp(file, argv);
+ if (errno == ENOEXEC) {
+ errno = 0;
+ return __execsh(file, argv);
+ }
+ return -1;
}
}
diff --git a/src/process/execsh.c b/src/process/execsh.c
new file mode 100644
index 00000000..180bb2aa
--- /dev/null
+++ b/src/process/execsh.c
@@ -0,0 +1,18 @@
+#include <unistd.h>
+#include <errno.h>
+#include "libc.h"
+
+int
+__execsh(const char *file, char *const argv[])
+{
+ int i, argc;
+ char **p;
+
+ for (argc=1, p=(char **)argv; *p; ++argc, ++p);
+
+ char *nargv[argc+1];
+ nargv[0] = (char *)file;
+ for (i=0; i<argc; ++i)
+ nargv[i+1] = argv[i];
+ return execv("/bin/sh", nargv);
+}
diff --git a/src/process/execvp.c b/src/process/execvp.c
index 2dddeddb..fdd0ca48 100644
--- a/src/process/execvp.c
+++ b/src/process/execvp.c
@@ -6,6 +6,7 @@
#include "libc.h"
extern char **__environ;
+extern int __execsh(const char *, char *const []);
int __execvpe(const char *file, char *const argv[], char *const envp[])
{
@@ -56,7 +57,12 @@ int __execvpe(const char *file, char *const argv[], char *const envp[])
int execvp(const char *file, char *const argv[])
{
- return __execvpe(file, argv, __environ);
+ __execvpe(file, argv, __environ);
+ if (errno == ENOEXEC) {
+ errno = 0;
+ return __execsh(file, argv);
+ }
+ return -1;
}
weak_alias(__execvpe, execvpe);
diff --git a/src/process/system.c b/src/process/system.c
index 9135b815..aa01e13b 100644
--- a/src/process/system.c
+++ b/src/process/system.c
@@ -19,7 +19,9 @@ int system(const char *cmd)
pthread_testcancel();
- if (!cmd) return 1;
+ if (!cmd) {
+ return (access("/bin/sh", X_OK) == 0);
+ }
sigaction(SIGINT, &sa, &oldint);
sigaction(SIGQUIT, &sa, &oldquit);
diff --git a/src/thread/pthread_attr_setinheritsched.c b/src/thread/pthread_attr_setinheritsched.c
index e540e846..4115e2fe 100644
--- a/src/thread/pthread_attr_setinheritsched.c
+++ b/src/thread/pthread_attr_setinheritsched.c
@@ -23,7 +23,7 @@ void *__start_sched(void *p)
int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit)
{
- if (inherit > 1U) return EINVAL;
+ if (inherit > 1U) return ENOTSUP;
a->_a_sched = inherit;
return 0;
}
diff --git a/src/thread/pthread_attr_setscope.c b/src/thread/pthread_attr_setscope.c
index 46b520c0..933bdb38 100644
--- a/src/thread/pthread_attr_setscope.c
+++ b/src/thread/pthread_attr_setscope.c
@@ -8,6 +8,6 @@ int pthread_attr_setscope(pthread_attr_t *a, int scope)
case PTHREAD_SCOPE_PROCESS:
return ENOTSUP;
default:
- return EINVAL;
+ return ENOTSUP;
}
}
diff --git a/src/time/timespec_get.c b/src/time/timespec_get.c
index 03c5a77b..c423b825 100644
--- a/src/time/timespec_get.c
+++ b/src/time/timespec_get.c
@@ -6,7 +6,7 @@ int __clock_gettime(clockid_t, struct timespec *);
* are considered erroneous. */
int timespec_get(struct timespec * ts, int base)
{
- if (base != TIME_UTC) return 0;
+ if (base != 1) return 0;
int ret = __clock_gettime(CLOCK_REALTIME, ts);
return ret < 0 ? 0 : base;
}
diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c
index f407ffe0..4fd3a60c 100644
--- a/src/unistd/getcwd.c
+++ b/src/unistd/getcwd.c
@@ -15,8 +15,11 @@ char *getcwd(char *buf, size_t size)
return 0;
}
long ret = syscall(SYS_getcwd, buf, size);
- if (ret < 0)
+ if (ret < 0) {
+ if (errno == ENAMETOOLONG)
+ errno = ENOMEM;
return 0;
+ }
if (ret == 0 || buf[0] != '/') {
errno = ENOENT;
return 0;
diff --git a/src/conf/fpathconf.c b/src/conf/fpathconf.c
index b6a9d63e..83e47e87 100644
--- a/src/conf/fpathconf.c
+++ b/src/conf/fpathconf.c
@@ -5,7 +5,7 @@
long fpathconf(int fd, int name)
{
static const long values[] = {
- [_PC_LINK_MAX] = _POSIX_LINK_MAX,
+ [_PC_LINK_MAX] = -1,
[_PC_MAX_CANON] = _POSIX_MAX_CANON,
[_PC_MAX_INPUT] = _POSIX_MAX_INPUT,
[_PC_NAME_MAX] = NAME_MAX,
diff --git a/include/unistd.h b/include/unistd.h
index 1bdd3292..cdb16c19 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -33,16 +33,23 @@ extern "C" {
#include <bits/alltypes.h>
int pipe(int [2]);
-int pipe2(int [2], int);
int close(int);
-int posix_close(int, int);
int dup(int);
int dup2(int, int);
-int dup3(int, int, int);
off_t lseek(int, off_t, int);
int fsync(int);
int fdatasync(int);
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \
+ || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 > 700) \
+ || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 > 200809L)
+int pipe2(int [2], int);
+int dup3(int, int, int);
+int posix_close(int, int);
+
+#define POSIX_CLOSE_RESTART 0
+#endif
+
ssize_t read(int, void *, size_t);
ssize_t write(int, const void *, size_t);
ssize_t pread(int, void *, size_t, off_t);
@@ -200,8 +207,6 @@ int eaccess(const char *, int);
#define off64_t off_t
#endif
-#define POSIX_CLOSE_RESTART 0
-
#define _XOPEN_VERSION 700
#define _XOPEN_UNIX 1
#define _XOPEN_ENH_I18N 1
diff --git a/src/misc/forkpty.c b/src/misc/forkpty.c
index caf13adb..047eb7d6 100644
--- a/src/misc/forkpty.c
+++ b/src/misc/forkpty.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
#include <pty.h>
#include <utmp.h>
#include <unistd.h>
diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c
index db83a69f..1ae03f9f 100644
--- a/src/misc/wordexp.c
+++ b/src/misc/wordexp.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
#include <wordexp.h>
#include <unistd.h>
#include <stdio.h>
diff --git a/src/stdio/popen.c b/src/stdio/popen.c
index 92cb57ee..1ff9e0d9 100644
--- a/src/stdio/popen.c
+++ b/src/stdio/popen.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
diff --git a/src/unistd/faccessat.c b/src/unistd/faccessat.c
index 76bbd4c7..d5e70608 100644
--- a/src/unistd/faccessat.c
+++ b/src/unistd/faccessat.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
diff --git a/include/fcntl.h b/include/fcntl.h
index 4d91338b..04321887 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -36,8 +36,9 @@ int openat(int, const char *, int, ...);
int posix_fadvise(int, off_t, off_t, int);
int posix_fallocate(int, off_t, off_t);
-#define O_SEARCH O_PATH
-#define O_EXEC O_PATH
+#define O_SEARCH O_PATH
+#define O_EXEC O_PATH
+#define O_TTY_INIT 0
#define O_ACCMODE (03|O_SEARCH)
#define O_RDONLY 00
|