Add <sys/auxv.h> and getauxval.
[glibc.git] / sysdeps / unix / sysv / linux / grantpt.c
blob0a3cd472fa2cbfb348e3cc460c5a2ff1fdd3e7b0
1 #include <assert.h>
2 #include <ctype.h>
3 #include <dirent.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <paths.h>
7 #include <stdlib.h>
8 #include <unistd.h>
10 #include <not-cancel.h>
12 #include "pty-private.h"
15 /* Close all file descriptors except the one specified. */
16 static void
17 close_all_fds (void)
19 DIR *dir = __opendir ("/proc/self/fd");
20 if (dir != NULL)
22 struct dirent64 *d;
23 while ((d = __readdir64 (dir)) != NULL)
24 if (isdigit (d->d_name[0]))
26 char *endp;
27 long int fd = strtol (d->d_name, &endp, 10);
28 if (*endp == '\0' && fd != PTY_FILENO && fd != dirfd (dir))
29 close_not_cancel_no_status (fd);
32 __closedir (dir);
34 int nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_RDONLY);
35 assert (nullfd == STDIN_FILENO);
36 nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_WRONLY);
37 assert (nullfd == STDOUT_FILENO);
38 __dup2 (STDOUT_FILENO, STDERR_FILENO);
41 #define CLOSE_ALL_FDS() close_all_fds()
43 #include <sysdeps/unix/grantpt.c>