2 // compat.cpp -- compatibilty layer to make bacula-fd run
3 // natively under windows
5 // Copyright (C)2004 Raider Solutions, Inc
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of
10 // the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public
18 // License along with this program; if not, write to the Free
19 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 // MA 02111-1307, USA.
22 // Author : Christopher S. Hull
23 // Created On : Sat Jan 31 15:55:00 2004
24 // Last Modified By: Christopher S. Hull
25 // Last Modified On: Mon Feb 9 17:22:31 2004
34 extern void d_msg(const char *file, int line, int level, const char *fmt,...);
35 extern DWORD g_platform_id;
39 cygwin_conv_to_win32_path(const char *name, char *win32_name)
41 const char *fname = name;
43 /* Check for Unix separator and convert to Win32 */
45 *win32_name++ = '\\'; /* convert char */
46 /* If Win32 separated that is "quoted", remove quote */
47 } else if (*name == '\\' && name[1] == '\\') {
49 name++; /* skip first \ */
51 *win32_name++ = *name; /* copy character */
55 /* Strip any trailing slash, if we stored something */
56 if (*fname != 0 && win32_name[-1] == '\\') {
65 open(const char *file, int flags, int mode)
72 const char *remap = file;
74 if (flags & O_WRONLY) access = GENERIC_WRITE;
75 else if (flags & O_RDWR) access = GENERIC_READ|GENERIC_WRITE;
76 else access = GENERIC_READ;
78 if (flags & O_CREAT) create = CREATE_NEW;
79 else create = OPEN_EXISTING;
81 if (flags & O_TRUNC) create = TRUNCATE_EXISTING;
83 if (!(flags & O_EXCL))
84 shareMode = FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE;
88 printf("open...APPEND not implemented yet.");
92 foo = CreateFile(file, access, shareMode, NULL, create, msflags, NULL);
93 if (INVALID_HANDLE_VALUE == foo)
104 if (!CloseHandle((HANDLE)fd))
111 write(int fd, const void *data, int32_t len)
115 status = WriteFile((HANDLE)fd, data, len, &bwrite, NULL);
116 if (status) return bwrite;
122 read(int fd, void *data, int32_t len)
127 status = ReadFile((HANDLE)fd, data, len, &bread, NULL);
128 if (status) return bread;
140 chmod(const char *, mode_t)
146 chown(const char *k, uid_t, gid_t)
152 lchown(const char *k, uid_t, gid_t)
158 utime(const char *, struct utimbuf *)
171 srandom(unsigned int seed)
175 // /////////////////////////////////////////////////////////////////
176 // convert from Windows concept of time to Unix concept of time
177 // /////////////////////////////////////////////////////////////////
179 cvt(const FILETIME &time)
181 uint64_t mstime = time.dwHighDateTime;
183 mstime |= time.dwLowDateTime;
185 mstime /= 10000000; // convert to seconds.
186 mstime -= 3234336I64*3600I64; // difference between jan 1, 1601
189 return (time_t) (mstime & 0xffffffff);
197 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
198 FORMAT_MESSAGE_FROM_SYSTEM |
199 FORMAT_MESSAGE_IGNORE_INSERTS,
202 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default lang
207 return (const char *) lpMsgBuf;
211 statDir(const char *file, struct stat *sb)
213 WIN32_FIND_DATA info; // window's file info
214 sb->st_mode |= S_IFDIR;
216 if (file[1] == ':' && file[2] == 0)
218 d_msg(__FILE__, __LINE__, 99, "faking ROOT attrs(%s).\n", file);
219 sb->st_mode |= S_IREAD|S_IEXEC|S_IWRITE;
225 HANDLE h = FindFirstFile(file, &info);
227 if (h == INVALID_HANDLE_VALUE) {
228 const char *err = errorString();
229 d_msg(__FILE__, __LINE__, 99, "FindFirstFile(%s):%s\n", file, err);
230 LocalFree((void *)err);
231 errno = GetLastError();
235 sb->st_mode |= (S_IREAD | S_IEXEC);
236 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
237 sb->st_mode |= S_IWRITE;
239 if (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
240 sb->st_mode |= S_IRGRP;
241 if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
242 sb->st_mode |= S_IROTH;
243 sb->st_size = info.nFileSizeHigh;
245 sb->st_size |= info.nFileSizeLow;
246 sb->st_blksize = 4096;
247 sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096;
248 sb->st_atime = cvt(info.ftLastAccessTime);
249 sb->st_mtime = cvt(info.ftLastWriteTime);
250 sb->st_ctime = cvt(info.ftCreationTime);
256 stat2(const char *file, struct stat *sb)
258 BY_HANDLE_FILE_INFORMATION info;
262 cygwin_conv_to_win32_path(file, tmpbuf);
264 DWORD attr = GetFileAttributes(tmpbuf);
267 const char *err = errorString();
268 d_msg(__FILE__, __LINE__, 99,
269 "GetFileAttrubtes(%s): %s\n", tmpbuf, err);
270 LocalFree((void *)err);
271 errno = GetLastError();
275 if (attr & FILE_ATTRIBUTE_DIRECTORY)
276 return statDir(tmpbuf, sb);
278 sb->st_mode |= S_IFREG;
280 h = CreateFile(tmpbuf, GENERIC_READ,
281 FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
283 if (h == INVALID_HANDLE_VALUE) {
284 const char *err = errorString();
285 d_msg(__FILE__, __LINE__, 99,
286 "Cannot open file for stat (%s):%s\n", tmpbuf, err);
287 LocalFree((void *)err);
289 errno = GetLastError();
293 if (!GetFileInformationByHandle(h, &info)) {
294 const char *err = errorString();
295 d_msg(__FILE__, __LINE__, 99,
296 "GetfileInformationByHandle(%s): %s\n", tmpbuf, err);
297 LocalFree((void *)err);
299 errno = GetLastError();
303 sb->st_dev = info.dwVolumeSerialNumber;
304 sb->st_ino = info.nFileIndexHigh;
306 sb->st_ino |= info.nFileIndexLow;
307 sb->st_nlink = (short)info.nNumberOfLinks;
308 sb->st_mode |= (S_IREAD | S_IEXEC);
309 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
310 sb->st_mode |= S_IWRITE;
312 if (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
313 sb->st_mode |= S_IRGRP;
314 if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
315 sb->st_mode |= S_IROTH;
316 sb->st_size = info.nFileSizeHigh;
318 sb->st_size |= info.nFileSizeLow;
319 sb->st_blksize = 4096;
320 sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096;
321 sb->st_atime = cvt(info.ftLastAccessTime);
322 sb->st_mtime = cvt(info.ftLastWriteTime);
323 sb->st_ctime = cvt(info.ftCreationTime);
331 stat(const char *file, struct stat *sb)
333 WIN32_FILE_ATTRIBUTE_DATA data;
336 memset(sb, 0, sizeof(*sb));
338 if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS)
339 return stat2(file, sb);
341 if (!GetFileAttributesEx(file, GetFileExInfoStandard, &data))
342 return stat2(file, sb);
344 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
345 sb->st_mode |= S_IFDIR;
347 sb->st_mode |= S_IFREG;
350 sb->st_mode |= (S_IREAD | S_IEXEC);
351 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
352 sb->st_mode |= S_IWRITE;
354 if (data.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
355 sb->st_mode |= S_IRGRP;
356 if (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
357 sb->st_mode |= S_IROTH;
358 sb->st_size = data.nFileSizeHigh;
360 sb->st_size |= data.nFileSizeLow;
361 sb->st_blksize = 4096;
362 sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096;
363 sb->st_atime = cvt(data.ftLastAccessTime);
364 sb->st_mtime = cvt(data.ftLastWriteTime);
365 sb->st_ctime = cvt(data.ftCreationTime);
370 lstat(const char *file, struct stat *sb)
372 return stat(file, sb);
388 execvp(const char *, char *[]) {
411 waitpid(int, int*, int)
417 readlink(const char *, char *, int)
423 lseek(int fd, int offset, int whence)
431 method = FILE_CURRENT;
440 return SetFilePointer((HANDLE)fd, (DWORD)offset, NULL, method);
444 strcasecmp(const char *s1, const char *s2)
446 register int ch1, ch2;
449 return 0; /* strings are equal if same object. */
460 } while (ch1 != 0 && tolower(ch1) == tolower(ch2));
466 strncasecmp(const char *s1, const char *s2, int len)
468 register int ch1, ch2;
471 return 0; /* strings are equal if same object. */
482 } while (len-- && ch1 != 0 && tolower(ch1) == tolower(ch2));
488 gettimeofday(struct timeval *tv, struct timezone *)
494 if (tv == NULL) return -1;
495 if (!SystemTimeToFileTime(&now, &tmp)) return -1;
497 int64_t _100nsec = tmp.dwHighDateTime;
499 _100nsec |= tmp.dwLowDateTime;
500 _100nsec -= (3234336I64*3600I64 * 10000000I64);
501 tv->tv_sec =(long) (_100nsec / 10000000);
502 tv->tv_usec = (long) ((_100nsec % 10000000)/10);
508 syslog(int, const char *, const char *)
526 // implement opendir/readdir/closedir on top of window's API
529 WIN32_FIND_DATA data; // window's file info
530 const char *spec; // the directory we're traversing
531 HANDLE dirh; // the search handle
532 BOOL valid; // the info in data field is valid
533 UINT32 offset; // pseudo offset for d_off
537 opendir(const char *path)
539 int max_len = strlen(path) + 16;
541 if (path == NULL) return NULL;
543 rval = (_dir *)malloc(sizeof(_dir));
544 if (rval == NULL) return NULL;
545 char *tspec = (char *)malloc(max_len);
546 if (tspec == NULL) goto err1;
548 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
549 // allow path to be 32767 bytes
555 cygwin_conv_to_win32_path(path, tspec+4);
557 cygwin_conv_to_win32_path(path, tspec);
559 strncat(tspec, "\\*", max_len);
562 rval->dirh = FindFirstFile(rval->spec, &rval->data);
563 d_msg(__FILE__, __LINE__,
564 99, "opendir(%s)\n\tspec=%s,\n\tFindFirstFile returns %d\n",
565 path, rval->spec, rval->dirh);
568 if (rval->dirh == INVALID_HANDLE_VALUE)
571 d_msg(__FILE__, __LINE__,
572 99, "\tFirstFile=%s\n", rval->data.cFileName);
575 free((void *)rval->spec);
584 _dir *dp = (_dir *)dirp;
586 free((void *)dp->spec);
592 typedef struct _WIN32_FIND_DATA {
593 DWORD dwFileAttributes;
594 FILETIME ftCreationTime;
595 FILETIME ftLastAccessTime;
596 FILETIME ftLastWriteTime;
601 TCHAR cFileName[MAX_PATH];
602 TCHAR cAlternateFileName[14];
603 } WIN32_FIND_DATA, *PWIN32_FIND_DATA;
607 copyin(struct dirent &dp, const char *fname)
611 char *cp = dp.d_name;
620 readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
623 _dir *dp = (_dir *)dirp;
625 entry->d_off = dp->offset;
626 dp->offset += copyin(*entry, dp->data.cFileName);
627 *result = entry; /* return entry address */
628 d_msg(__FILE__, __LINE__,
629 99, "readdir_r(%p, { d_name=\"%s\", d_reclen=%d, d_off=%d\n",
630 dirp, entry->d_name, entry->d_reclen, entry->d_off);
632 // d_msg(__FILE__, __LINE__, 99, "readdir_r !valid\n");
635 dp->valid = FindNextFile(dp->dirh, &dp->data);
641 inet_aton(const char *a, struct in_addr *inp)
645 uint32_t acc = 0, tmp = 0;
647 if (!isdigit(*a)) return 0;
650 tmp = (tmp * 10) + (*cp -'0');
651 else if (*cp == '.') {
652 if (tmp > 255) return 0;
653 acc = (acc << 8) + tmp;
659 if (dotc != 3) return 0;
665 nanosleep(const struct timespec *req, struct timespec *rem)
668 rem->tv_sec = rem->tv_nsec = 0;
669 Sleep((req->tv_sec * 1000) + (req->tv_nsec/100000));
674 init_signals(void terminate(int sig))
680 init_stack_dump(void)
687 pathconf(const char *path, int name)
691 if (strncmp(path, "\\\\?\\", 4) == 0)
703 WORD wVersionRequested = MAKEWORD( 1, 1);
706 int err = WSAStartup(wVersionRequested, &wsaData);
711 printf("Can not start Windows Sockets\n");
720 win32_chdir(const char *dir)
722 if (0 == SetCurrentDirectory(dir)) return -1;
727 win32_getcwd(char *buf, int maxlen)
729 int n = GetCurrentDirectory(maxlen, buf);
731 if (n == 0 || n > maxlen) return NULL;
733 if (n+1 > maxlen) return NULL;
742 #include "mswinver.h"
744 char WIN_VERSION_LONG[64];
745 char WIN_VERSION[32];
752 static winver INIT; // cause constructor to be called before main()
759 const char *version = "";
760 const char *platform = "";
761 OSVERSIONINFO osvinfo;
762 osvinfo.dwOSVersionInfoSize = sizeof(osvinfo);
764 // Get the current OS version
765 if (!GetVersionEx(&osvinfo)) {
767 platform = "Unknown";
770 switch (_mkversion(osvinfo.dwPlatformId, osvinfo.dwMajorVersion, osvinfo.dwMinorVersion))
772 case MS_WINDOWS_95: (version = "Windows 95"); break;
773 case MS_WINDOWS_98: (version = "Windows 98"); break;
774 case MS_WINDOWS_ME: (version = "Windows ME"); break;
775 case MS_WINDOWS_NT4:(version = "Windows NT 4.0"); platform = "NT"; break;
776 case MS_WINDOWS_2K: (version = "Windows 2000");platform = "NT"; break;
777 case MS_WINDOWS_XP: (version = "Windows XP");platform = "NT"; break;
778 case MS_WINDOWS_S2003: (version = "Windows Server 2003");platform = "NT"; break;
779 default: version = "Windows ??"; break;
782 bstrncpy(WIN_VERSION_LONG, version, sizeof(WIN_VERSION_LONG));
783 snprintf(WIN_VERSION, sizeof(WIN_VERSION), "%s %d.%d.%d",
784 platform, osvinfo.dwMajorVersion, osvinfo.dwMinorVersion, osvinfo.dwBuildNumber);
787 BPIPE *b = open_bpipe("ls -l", 10, "r");
789 while (!feof(b->rfd)) {
790 fgets(buf, sizeof(buf), b->rfd);
796 BOOL CreateChildProcess(VOID);
797 VOID WriteToPipe(VOID);
798 VOID ReadFromPipe(VOID);
799 VOID ErrorExit(LPTSTR);
800 VOID ErrMsg(LPTSTR, BOOL);
804 getArgv0(const char *cmdline)
806 const char *cp = cmdline;
808 while (*cp && !isspace(*cp)) cp++;
810 int len = cp - cmdline;
811 char *rval = (char *)malloc(len+1);
823 CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err)
825 PROCESS_INFORMATION piProcInfo;
826 STARTUPINFO siStartInfo;
827 BOOL bFuncRetn = FALSE;
829 // Set up members of the PROCESS_INFORMATION structure.
831 ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
833 // Set up members of the STARTUPINFO structure.
835 ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
836 siStartInfo.cb = sizeof(STARTUPINFO);
837 // setup new process to use supplied handles for stdin,stdout,stderr
838 // if supplied handles are not used the send a copy of our STD_HANDLE
840 siStartInfo.dwFlags = STARTF_USESTDHANDLES;
842 if (in != INVALID_HANDLE_VALUE)
843 siStartInfo.hStdInput = in;
845 siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
847 if (out != INVALID_HANDLE_VALUE)
848 siStartInfo.hStdOutput = out;
850 siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
851 if (err != INVALID_HANDLE_VALUE)
852 siStartInfo.hStdError = err;
854 siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
855 // Create the child process.
859 // retrive the first compont of the command line which should be the
861 const char *exeName = getArgv0(cmdline);
862 // check to see if absolute path was passed to us already?
863 if (exeName[1] != ':'
864 || (strchr(cmdline, '/') == NULL
865 && strchr(cmdline, '\\') == NULL))
867 // only command name so perform search of PATH to find
869 DWORD rval = SearchPath(NULL,
876 return INVALID_HANDLE_VALUE;
877 if (rval > sizeof(exeFile))
878 return INVALID_HANDLE_VALUE;
882 strcpy(exeFile, exeName);
884 // exeFile now has absolute path to program to execute.
885 free((void *)exeName);
886 // copy original command line to pass to create process
887 strcpy(cmdLine, cmdline);
888 // try to execute program
889 bFuncRetn = CreateProcess(exeFile,
890 cmdLine, // command line
891 NULL, // process security attributes
892 NULL, // primary thread security attributes
893 TRUE, // handles are inherited
895 NULL, // use parent's environment
896 NULL, // use parent's current directory
897 &siStartInfo, // STARTUPINFO pointer
898 &piProcInfo); // receives PROCESS_INFORMATION
900 if (bFuncRetn == 0) {
901 ErrorExit("CreateProcess failed\n");
902 return INVALID_HANDLE_VALUE;
904 // we don't need a handle on the process primary thread so we close
906 CloseHandle(piProcInfo.hThread);
908 return piProcInfo.hProcess;
913 ErrorExit (LPTSTR lpszMessage)
915 d_msg(__FILE__, __LINE__, 0, "%s", lpszMessage);
920 typedef struct s_bpipe {
931 CloseIfValid(HANDLE handle)
933 if (handle != INVALID_HANDLE_VALUE)
936 // include <io.h> causes to many conflicts with some of
937 // the fuctions we define here.
939 int __cdecl _open_osfhandle(long, int);
943 open_bpipe(char *prog, int wait, const char *mode)
945 HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
946 hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup,
949 SECURITY_ATTRIBUTES saAttr;
953 hChildStdinRd = hChildStdinWr = hChildStdinWrDup =
954 hChildStdoutRd = hChildStdoutWr = hChildStdoutRdDup =
955 hInputFile = INVALID_HANDLE_VALUE;
957 BPIPE *bpipe = (BPIPE *)malloc(sizeof(BPIPE));
958 memset((void *)bpipe, 0, sizeof(BPIPE));
960 int mode_read = (mode[0] == 'r');
961 int mode_write = (mode[0] == 'w' || mode[1] == 'w');
964 // Set the bInheritHandle flag so pipe handles are inherited.
966 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
967 saAttr.bInheritHandle = TRUE;
968 saAttr.lpSecurityDescriptor = NULL;
972 // Create a pipe for the child process's STDOUT.
973 if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) {
974 ErrorExit("Stdout pipe creation failed\n");
977 // Create noninheritable read handle and close the inheritable read
980 fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
981 GetCurrentProcess(), &hChildStdoutRdDup , 0,
983 DUPLICATE_SAME_ACCESS);
985 ErrorExit("DuplicateHandle failed");
989 CloseHandle(hChildStdoutRd);
994 // Create a pipe for the child process's STDIN.
996 if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) {
997 ErrorExit("Stdin pipe creation failed\n");
1001 // Duplicate the write handle to the pipe so it is not inherited.
1002 fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
1003 GetCurrentProcess(), &hChildStdinWrDup,
1005 FALSE, // not inherited
1006 DUPLICATE_SAME_ACCESS);
1008 ErrorExit("DuplicateHandle failed");
1012 CloseHandle(hChildStdinWr);
1014 // spawn program with redirected handles as appropriate
1015 bpipe->worker_pid = (pid_t)
1016 CreateChildProcess(prog, // commandline
1017 hChildStdinRd, // stdin HANDLE
1018 hChildStdoutWr, // stdout HANDLE
1019 hChildStdoutWr);// stderr HANDLE
1021 if ((HANDLE) bpipe->worker_pid == INVALID_HANDLE_VALUE)
1025 bpipe->worker_stime = time(NULL);
1028 CloseHandle(hChildStdoutWr); // close our write side so when
1029 // process terminates we can
1031 // ugly but convert WIN32 HANDLE to FILE*
1032 int rfd = _open_osfhandle((long)hChildStdoutRdDup, O_RDONLY);
1033 bpipe->rfd = _fdopen(rfd, "r");
1036 CloseHandle(hChildStdinRd); // close our read side so as not
1037 // to interfre with child's copy
1038 // ugly but convert WIN32 HANDLE to FILE*
1039 int wfd = _open_osfhandle((long)hChildStdinWrDup, O_WRONLY);
1040 bpipe->wfd = _fdopen(wfd, "w");
1044 bpipe->timer_id = start_child_timer(bpipe->worker_pid, wait);
1051 CloseIfValid(hChildStdoutRd);
1052 CloseIfValid(hChildStdoutRdDup);
1053 CloseIfValid(hChildStdinWr);
1054 CloseIfValid(hChildStdinWrDup);
1056 free((void *) bpipe);
1062 kill(int pid, int signal)
1065 if (!TerminateProcess((HANDLE)pid, (UINT) signal))
1067 CloseHandle((HANDLE)pid);
1072 close_bpipe(BPIPE *bpipe)
1075 if (bpipe->rfd) fclose(bpipe->rfd);
1076 if (bpipe->wfd) fclose(bpipe->wfd);
1079 int remaining_wait = bpipe->wait;
1083 if (!GetExitCodeProcess((HANDLE)bpipe->worker_pid, &exitCode))
1085 const char *err = errorString();
1086 rval = GetLastError();
1087 d_msg(__FILE__, __LINE__, 0,
1088 "GetExitCode error %s\n", err);
1089 LocalFree((void *)err);
1093 if (exitCode == STILL_ACTIVE) {
1094 bmicrosleep(1, 0); /* wait one second */
1098 } while(remaining_wait);
1101 if (bpipe->timer_id) {
1102 stop_child_timer(bpipe->timer_id);
1104 free((void *)bpipe);
1109 close_wpipe(BPIPE *bpipe)
1115 if (fclose(bpipe->wfd) != 0) {