- Timestamp:
- Mar 23, 2010 1:29:07 AM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/pipe-posix.cpp
r27613 r27614 49 49 #include <unistd.h> 50 50 #include <sys/poll.h> 51 #include <sys/stat.h> 51 52 #include <signal.h> 52 53 … … 184 185 RTDECL(int) RTPipeFromNative(PRTPIPE phPipe, RTHCINTPTR hNativePipe, uint32_t fFlags) 185 186 { 186 return VERR_NOT_IMPLEMENTED; 187 AssertPtrReturn(phPipe, VERR_INVALID_POINTER); 188 AssertReturn(!(fFlags & ~RTPIPE_N_VALID_MASK), VERR_INVALID_PARAMETER); 189 AssertReturn(!!(fFlags & RTPIPE_N_READ) != !!(fFlags & RTPIPE_N_WRITE), VERR_INVALID_PARAMETER); 190 191 /* 192 * Get and validate the pipe handle info. 193 */ 194 int hNative = (int)hNativePipe; 195 struct stat st; 196 AssertReturn(fstat(hNative, &st) == 0, RTErrConvertFromErrno(errno)); 197 AssertMsgReturn(S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode), ("%#x (%o)\n", st.st_mode, st.st_mode), VERR_INVALID_HANDLE); 198 199 int fFd = fcntl(hNative, F_GETFL, 0); 200 AssertReturn(fFd != -1, VERR_INVALID_HANDLE); 201 AssertMsgReturn((fFd & O_ACCMODE) == (fFlags & RTPIPE_N_READ ? O_RDONLY : O_WRONLY), ("%#x\n", fFd), VERR_INVALID_HANDLE); 202 203 /* 204 * Create the handle. 205 */ 206 RTPIPEINTERNAL *pThis = (RTPIPEINTERNAL *)RTMemAlloc(sizeof(RTPIPEINTERNAL)); 207 if (!pThis) 208 return VERR_NO_MEMORY; 209 210 pThis->u32Magic = RTPIPE_MAGIC; 211 pThis->fd = hNative; 212 pThis->fRead = !!(fFlags & RTPIPE_N_READ); 213 pThis->u32State = fFd & O_NONBLOCK ? 0 : RTPIPE_POSIX_BLOCKING; 214 215 /* 216 * Fix up inheritability and shut up SIGPIPE and we're done. 217 */ 218 if (fcntl(hNative, F_SETFD, fFlags & RTPIPE_N_INHERIT ? 0 : FD_CLOEXEC) == 0) 219 { 220 signal(SIGPIPE, SIG_IGN); 221 *phPipe = pThis; 222 return VINF_SUCCESS; 223 } 224 225 int rc = RTErrConvertFromErrno(errno); 226 RTMemFree(pThis); 227 return rc; 187 228 } 188 229 -
trunk/src/VBox/Runtime/r3/win/pipe-win.cpp
r27613 r27614 437 437 RTDECL(int) RTPipeFromNative(PRTPIPE phPipe, RTHCINTPTR hNativePipe, uint32_t fFlags) 438 438 { 439 AssertPtrReturn(phPipe, VERR_INVALID_POINTER); 439 440 AssertReturn(!(fFlags & ~RTPIPE_N_VALID_MASK), VERR_INVALID_PARAMETER); 440 441 AssertReturn(!!(fFlags & RTPIPE_N_READ) != !!(fFlags & RTPIPE_N_WRITE), VERR_INVALID_PARAMETER);
Note:
See TracChangeset
for help on using the changeset viewer.