aboutsummaryrefslogtreecommitdiff
path: root/src/common/open_stdxxx.h
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-09-19 09:47:30 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-09-19 09:47:30 +0300
commite599bba4216c0edb8cc8f40adad3a6dba88685f4 (patch)
treed52c699f599e276ff65302e5854a26998da1a928 /src/common/open_stdxxx.h
parentFix incorrect use of "restrict". (diff)
downloadxz-e599bba4216c0edb8cc8f40adad3a6dba88685f4.tar.xz
Various changes.
Separate a few reusable components from XZ Utils specific code. The reusable code is now in "tuklib" modules. A few more could be separated still, e.g. bswap.h. Fix some bugs in lzmainfo. Fix physmem and cpucores code on OS/2. Thanks to Elbert Pol for help. Add OpenVMS support into physmem. Add a few #ifdefs to ease building XZ Utils on OpenVMS. Thanks to Jouk Jansen for the original patch.
Diffstat (limited to 'src/common/open_stdxxx.h')
-rw-r--r--src/common/open_stdxxx.h49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/common/open_stdxxx.h b/src/common/open_stdxxx.h
deleted file mode 100644
index 22300851..00000000
--- a/src/common/open_stdxxx.h
+++ /dev/null
@@ -1,49 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//
-/// \file open_stdxxx.h
-/// \brief Make sure that file descriptors 0, 1, and 2 are open
-//
-// Author: Lasse Collin
-//
-// This file has been put into the public domain.
-// You can do whatever you want with this file.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef OPEN_STDXXX_H
-#define OPEN_STDXXX_H
-
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-
-static void
-open_stdxxx(int status)
-{
- for (int i = 0; i <= 2; ++i) {
- // We use fcntl() to check if the file descriptor is open.
- if (fcntl(i, F_GETFD) == -1 && errno == EBADF) {
- // With stdin, we could use /dev/full so that
- // writing to stdin would fail. However, /dev/full
- // is Linux specific, and if the program tries to
- // write to stdin, there's already a problem anyway.
- const int fd = open("/dev/null", O_NOCTTY
- | (i == 0 ? O_WRONLY : O_RDONLY));
-
- if (fd != i) {
- // Something went wrong. Exit with the
- // exit status we were given. Don't try
- // to print an error message, since stderr
- // may very well be non-existent. This
- // error should be extremely rare.
- (void)close(fd);
- exit(status);
- }
- }
- }
-
- return;
-}
-
-#endif