web
Last change
on this file since f6f3e91 was
f6f3e91,
checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago
|
Preserve directory hierarchy (not sure what happened to it)
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | /* |
---|
2 | * Small C program to verify that standard input is not closed but returns EOF |
---|
3 | * on any read and that all file descriptors higher than 2 are closed. |
---|
4 | * |
---|
5 | * Written by Russ Allbery <rra@stanford.edu> |
---|
6 | * Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University |
---|
7 | * |
---|
8 | * See LICENSE for licensing terms. |
---|
9 | */ |
---|
10 | |
---|
11 | #include <config.h> |
---|
12 | #include <portable/system.h> |
---|
13 | |
---|
14 | #include <errno.h> |
---|
15 | |
---|
16 | int |
---|
17 | main(void) |
---|
18 | { |
---|
19 | char buffer; |
---|
20 | ssize_t count; |
---|
21 | int i; |
---|
22 | |
---|
23 | /* First check that standard input is not closed but returns EOF. */ |
---|
24 | count = read(0, &buffer, 1); |
---|
25 | if (count > 0) { |
---|
26 | printf("Read %d bytes\n", (int) count); |
---|
27 | exit(1); |
---|
28 | } else if (count < 0) { |
---|
29 | printf("Failed with error: %s\n", strerror(errno)); |
---|
30 | exit(2); |
---|
31 | } |
---|
32 | |
---|
33 | /* |
---|
34 | * Now, check that all higher file descriptors are closed. (We only go up |
---|
35 | * to 31; it's very unlikely that there will be problems higher than |
---|
36 | * that.) |
---|
37 | */ |
---|
38 | for (i = 3; i < 32; i++) |
---|
39 | if (close(i) >= 0 || errno != EBADF) { |
---|
40 | printf("File descriptor %d was open\n", i); |
---|
41 | exit(3); |
---|
42 | } |
---|
43 | printf("Okay"); |
---|
44 | exit(0); |
---|
45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.