Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/common/tuklib_open_stdxxx.c

Issue 12568011: Update XZ Utils to 5.0.4 (third_party) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/xz/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /////////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////////
2 // 2 //
3 /// \file tuklib_open_stdxxx.c 3 /// \file tuklib_open_stdxxx.c
4 /// \brief Make sure that file descriptors 0, 1, and 2 are open 4 /// \brief Make sure that file descriptors 0, 1, and 2 are open
5 // 5 //
6 // Author: Lasse Collin 6 // Author: Lasse Collin
7 // 7 //
8 // This file has been put into the public domain. 8 // This file has been put into the public domain.
9 // You can do whatever you want with this file. 9 // You can do whatever you want with this file.
10 // 10 //
(...skipping 21 matching lines...) Expand all
32 // We use fcntl() to check if the file descriptor is open. 32 // We use fcntl() to check if the file descriptor is open.
33 if (fcntl(i, F_GETFD) == -1 && errno == EBADF) { 33 if (fcntl(i, F_GETFD) == -1 && errno == EBADF) {
34 // With stdin, we could use /dev/full so that 34 // With stdin, we could use /dev/full so that
35 // writing to stdin would fail. However, /dev/full 35 // writing to stdin would fail. However, /dev/full
36 // is Linux specific, and if the program tries to 36 // is Linux specific, and if the program tries to
37 // write to stdin, there's already a problem anyway. 37 // write to stdin, there's already a problem anyway.
38 const int fd = open("/dev/null", O_NOCTTY 38 const int fd = open("/dev/null", O_NOCTTY
39 | (i == 0 ? O_WRONLY : O_RDONLY)); 39 | (i == 0 ? O_WRONLY : O_RDONLY));
40 40
41 if (fd != i) { 41 if (fd != i) {
42 if (fd != -1)
43 (void)close(fd);
44
42 // Something went wrong. Exit with the 45 // Something went wrong. Exit with the
43 // exit status we were given. Don't try 46 // exit status we were given. Don't try
44 // to print an error message, since stderr 47 // to print an error message, since stderr
45 // may very well be non-existent. This 48 // may very well be non-existent. This
46 // error should be extremely rare. 49 // error should be extremely rare.
47 (void)close(fd);
48 exit(err_status); 50 exit(err_status);
49 } 51 }
50 } 52 }
51 } 53 }
52 #endif 54 #endif
53 55
54 return; 56 return;
55 } 57 }
OLDNEW
« README.chromium ('K') | « src/common/sysdefs.h ('k') | src/liblzma/Makefile.am » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698