diff options
| author | Ton Voon <ton.voon@opsera.com> | 2010-06-21 13:50:34 +0100 | 
|---|---|---|
| committer | Ton Voon <ton.voon@opsera.com> | 2010-06-21 13:50:34 +0100 | 
| commit | aab4e991d4e4213249058dd073543551c9c88c35 (patch) | |
| tree | efc8cfb750476203fed0c3fc2d04fb1b274e8a81 /gl/error.c | |
| parent | 29cf8ff2fea1a8f0e1f56b9f8a07fd7ee68c1770 (diff) | |
| download | monitoring-plugins-aab4e991d4e4213249058dd073543551c9c88c35.tar.gz | |
Sync with the latest Gnulib code (86ba51d)
Signed-off-by: Ton Voon <ton.voon@opsera.com>
Diffstat (limited to 'gl/error.c')
| -rw-r--r-- | gl/error.c | 32 | 
1 files changed, 30 insertions, 2 deletions
| @@ -88,6 +88,15 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
| 88 | # include <fcntl.h> | 88 | # include <fcntl.h> | 
| 89 | # include <unistd.h> | 89 | # include <unistd.h> | 
| 90 | 90 | ||
| 91 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 92 | /* Get declarations of the Win32 API functions. */ | ||
| 93 | # define WIN32_LEAN_AND_MEAN | ||
| 94 | # include <windows.h> | ||
| 95 | # endif | ||
| 96 | |||
| 97 | /* The gnulib override of fcntl is not needed in this file. */ | ||
| 98 | # undef fcntl | ||
| 99 | |||
| 91 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P | 100 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P | 
| 92 | # ifndef HAVE_DECL_STRERROR_R | 101 | # ifndef HAVE_DECL_STRERROR_R | 
| 93 | "this configure-time declaration test was not run" | 102 | "this configure-time declaration test was not run" | 
| @@ -104,10 +113,29 @@ extern char *program_name; | |||
| 104 | # endif /* HAVE_STRERROR_R || defined strerror_r */ | 113 | # endif /* HAVE_STRERROR_R || defined strerror_r */ | 
| 105 | #endif /* not _LIBC */ | 114 | #endif /* not _LIBC */ | 
| 106 | 115 | ||
| 116 | #if !_LIBC | ||
| 117 | /* Return non-zero if FD is open. */ | ||
| 118 | static inline int | ||
| 119 | is_open (int fd) | ||
| 120 | { | ||
| 121 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 122 | /* On Win32: The initial state of unassigned standard file descriptors is | ||
| 123 | that they are open but point to an INVALID_HANDLE_VALUE. There is no | ||
| 124 | fcntl, and the gnulib replacement fcntl does not support F_GETFL. */ | ||
| 125 | return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; | ||
| 126 | # else | ||
| 127 | # ifndef F_GETFL | ||
| 128 | # error Please port fcntl to your platform | ||
| 129 | # endif | ||
| 130 | return 0 <= fcntl (fd, F_GETFL); | ||
| 131 | # endif | ||
| 132 | } | ||
| 133 | #endif | ||
| 134 | |||
| 107 | static inline void | 135 | static inline void | 
| 108 | flush_stdout (void) | 136 | flush_stdout (void) | 
| 109 | { | 137 | { | 
| 110 | #if !_LIBC && defined F_GETFL | 138 | #if !_LIBC | 
| 111 | int stdout_fd; | 139 | int stdout_fd; | 
| 112 | 140 | ||
| 113 | # if GNULIB_FREOPEN_SAFER | 141 | # if GNULIB_FREOPEN_SAFER | 
| @@ -124,7 +152,7 @@ flush_stdout (void) | |||
| 124 | /* POSIX states that fflush (stdout) after fclose is unspecified; it | 152 | /* POSIX states that fflush (stdout) after fclose is unspecified; it | 
| 125 | is safe in glibc, but not on all other platforms. fflush (NULL) | 153 | is safe in glibc, but not on all other platforms. fflush (NULL) | 
| 126 | is always defined, but too draconian. */ | 154 | is always defined, but too draconian. */ | 
| 127 | if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL)) | 155 | if (0 <= stdout_fd && is_open (stdout_fd)) | 
| 128 | #endif | 156 | #endif | 
| 129 | fflush (stdout); | 157 | fflush (stdout); | 
| 130 | } | 158 | } | 
