Maintain stack alignment in ____longjmp_chk on x86_64
[glibc.git] / sysdeps / unix / sysv / linux / grantpt.c
blobf2fc60f83a51686a21f89f7a276c5541603bda6c
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"
11 #include "pty-private.h"
14 /* Close all file descriptors except the one specified. */
15 static void
16 close_all_fds (void)
18 DIR *dir = __opendir ("/proc/self/fd");
19 if (dir != NULL)
21 struct dirent64 *d;
22 while ((d = __readdir64 (dir)) != NULL)
23 if (isdigit (d->d_name[0]))
25 char *endp;
26 long int fd = strtol (d->d_name, &endp, 10);
27 if (*endp == '\0' && fd != PTY_FILENO && fd != dirfd (dir))
28 close_not_cancel_no_status (fd);
31 __closedir (dir);
33 int nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_RDONLY);
34 assert (nullfd == STDIN_FILENO);
35 nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_WRONLY);
36 assert (nullfd == STDOUT_FILENO);
37 __dup2 (STDOUT_FILENO, STDERR_FILENO);
40 #define CLOSE_ALL_FDS() close_all_fds()
42 #include <sysdeps/unix/grantpt.c>