Deleted Added
full compact
tuklib_open_stdxxx.c (213700) tuklib_open_stdxxx.c (223935)
1///////////////////////////////////////////////////////////////////////////////
2//
3/// \file tuklib_open_stdxxx.c
4/// \brief Make sure that file descriptors 0, 1, and 2 are open
5//
6// Author: Lasse Collin
7//
8// This file has been put into the public domain.

--- 25 unchanged lines hidden (view full) ---

34 // With stdin, we could use /dev/full so that
35 // writing to stdin would fail. However, /dev/full
36 // is Linux specific, and if the program tries to
37 // write to stdin, there's already a problem anyway.
38 const int fd = open("/dev/null", O_NOCTTY
39 | (i == 0 ? O_WRONLY : O_RDONLY));
40
41 if (fd != i) {
1///////////////////////////////////////////////////////////////////////////////
2//
3/// \file tuklib_open_stdxxx.c
4/// \brief Make sure that file descriptors 0, 1, and 2 are open
5//
6// Author: Lasse Collin
7//
8// This file has been put into the public domain.

--- 25 unchanged lines hidden (view full) ---

34 // With stdin, we could use /dev/full so that
35 // writing to stdin would fail. However, /dev/full
36 // is Linux specific, and if the program tries to
37 // write to stdin, there's already a problem anyway.
38 const int fd = open("/dev/null", O_NOCTTY
39 | (i == 0 ? O_WRONLY : O_RDONLY));
40
41 if (fd != i) {
42 if (fd != -1)
43 (void)close(fd);
44
42 // Something went wrong. Exit with the
43 // exit status we were given. Don't try
44 // to print an error message, since stderr
45 // may very well be non-existent. This
46 // error should be extremely rare.
45 // Something went wrong. Exit with the
46 // exit status we were given. Don't try
47 // to print an error message, since stderr
48 // may very well be non-existent. This
49 // error should be extremely rare.
47 (void)close(fd);
48 exit(err_status);
49 }
50 }
51 }
52#endif
53
54 return;
55}
50 exit(err_status);
51 }
52 }
53 }
54#endif
55
56 return;
57}