]> git.ipfire.org Git - thirdparty/bash.git/blame - CWRU/devstdin.c
add more overflow handling for printf builtin; start incorporating C23 stdckdint...
[thirdparty/bash.git] / CWRU / devstdin.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/stdin < /dev/null */
27 fd = open("/dev/null", O_RDONLY, 0666);
28 if (fd == -1)
29 exit (2);
30 if (dup2(fd, 0) == -1)
31 exit (1);
32 r = access("/dev/stdin", R_OK);
33 if (r == -1)
34 exit (1);
35 exit (0);
36}
37
38