]> git.ipfire.org Git - thirdparty/bash.git/blame - CWRU/devfd.c
add more overflow handling for printf builtin; start incorporating C23 stdckdint...
[thirdparty/bash.git] / CWRU / devfd.c
CommitLineData
2569d6d5
CR
1#include <unistd.h>
2
3#include <sys/types.h>
4#include <sys/stat.h>
5
6#include <fcntl.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10#if defined (S_IFDIR) && !defined (S_ISDIR)
11#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) /* directory */
12#endif
13
14main(c, v)
15int c;
16char **v;
17{
18 struct stat sb;
19 int r, fd;
20 char fbuf[32];
21
22 r = stat("/dev/fd", &sb);
23 /* test -d /dev/fd */
24 if (r == -1 || S_ISDIR (sb.st_mode) == 0)
25 exit (1);
26 /* test -r /dev/fd/0 */
27 r = access ("/dev/fd/0", R_OK);
28 if (r == -1)
29 exit (1);
30 /* exec 3</dev/null */
31 fd = open("/dev/null", O_RDONLY, 0666);
32 if (fd == -1)
33 exit (2);
39393a5b 34 if (fd != 3 && (dup2(fd, 3) == -1))
2569d6d5
CR
35 exit (1);
36 /* test -r /dev/fd/3 */
37 r = access("/dev/fd/3", R_OK);
38 if (r == -1)
39 exit (1);
40 exit (0);
41}
42
43