this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

popen() and pclose()

+45 -1
+41 -1
src/libSystem/libc/stdio.cpp
··· 3 3 #include "errno.h" 4 4 #include "common/path.h" 5 5 #include "common/auto.h" 6 + #include "trace.h" 6 7 #include "darwin_errno_codes.h" 7 8 #include <cstdio> 8 9 #include <cstdlib> ··· 13 14 #include <sys/types.h> 14 15 #include <sys/stat.h> 15 16 #include <fcntl.h> 17 + #include <limits.h> 18 + #include <typeinfo> 16 19 #include "log.h" 20 + 21 + extern char g_sysroot[PATH_MAX]; 17 22 18 23 //extern "C" 19 24 //{ ··· 35 40 fp->_file = fileno(linux_fp); 36 41 fp->_lbfsize = 0; 37 42 fp->linux_fp = linux_fp; 43 + 38 44 return fp; 39 45 } 40 46 ··· 48 54 49 55 __darwin_FILE* __darwin_fopen(const char* path, const char* mode) 50 56 { 51 - path = translatePathCI(path); 57 + TRACE2(path, mode); 58 + if (!strchr(mode, 'w') && g_sysroot[0]) 59 + { 60 + const char* prefixed; 61 + std::string lpath = g_sysroot; 62 + lpath += '/'; 63 + lpath += path; 64 + 65 + prefixed = translatePathCI(lpath.c_str()); 66 + if (::access(prefixed, F_OK) == 0) 67 + path = prefixed; 68 + else 69 + path = translatePathCI(path); 70 + } 71 + else 72 + path = translatePathCI(path); 52 73 53 74 if (!strchr(mode, 'x')) 54 75 return InitDarwinFILE(fopen(path, mode)); ··· 74 95 } 75 96 } 76 97 98 + __darwin_FILE* __darwin_popen(const char* command, const char* type) 99 + { 100 + return InitDarwinFILE(popen(command, type)); // translatePathCI? 101 + } 102 + 103 + int __darwin_pclose(__darwin_FILE* stream) 104 + { 105 + int r = pclose(stream->linux_fp); 106 + delete stream; 107 + if (r == -1) 108 + errnoOut(); 109 + return r; 110 + } 111 + 77 112 __darwin_FILE* __darwin_fdopen(int fd, const char* mode) 78 113 { 79 114 return InitDarwinFILE(fdopen(fd, mode)); ··· 88 123 { 89 124 int r = fclose(fp->linux_fp); 90 125 delete fp; 126 + 127 + if (r == -1) 128 + errnoOut(); 129 + 91 130 return r; 92 131 } 93 132 ··· 133 172 134 173 char* __darwin_fgets(char* s, int size, __darwin_FILE* fp) 135 174 { 175 + std::cout << typeid(fp).name() << " ptr: " << fp << std::endl; 136 176 return fgets(s, size, fp->linux_fp); 137 177 } 138 178
+4
src/libSystem/libc/stdio.h
··· 87 87 int __darwin_feof(__darwin_FILE *stream); 88 88 void __darwin_clearerr(__darwin_FILE *stream); 89 89 90 + // pipes 91 + __darwin_FILE* __darwin_popen(const char* command, const char* type); 92 + int __darwin_pclose(__darwin_FILE* stream); 93 + 90 94 int __darwin_fgetpos(__darwin_FILE *stream, fpos_t *pos); 91 95 int __darwin_fsetpos(__darwin_FILE *stream, fpos_t *pos); 92 96 int __darwin_fpurge(__darwin_FILE *stream);