@@ -136,9 +136,7 @@ fileio_pipe(struct w32_io* pio[2]) {
136
136
memset (pio_write , 0 , sizeof (struct w32_io ));
137
137
138
138
pio_read -> handle = read_handle ;
139
- pio_read -> internal .state = PIPE_READ_END ;
140
139
pio_write -> handle = write_handle ;
141
- pio_write -> internal .state = PIPE_WRITE_END ;
142
140
143
141
pio [0 ] = pio_read ;
144
142
pio [1 ] = pio_write ;
@@ -281,7 +279,6 @@ fileio_open(const char *pathname, int flags, int mode) {
281
279
return pio ;
282
280
}
283
281
284
-
285
282
VOID CALLBACK ReadCompletionRoutine (
286
283
_In_ DWORD dwErrorCode ,
287
284
_In_ DWORD dwNumberOfBytesTransfered ,
@@ -301,8 +298,8 @@ VOID CALLBACK ReadCompletionRoutine(
301
298
/* initiate an async read */
302
299
int
303
300
fileio_ReadFileEx (struct w32_io * pio ) {
304
- HANDLE h = pio -> handle ;
305
301
debug2 ("ReadFileEx io:%p" , pio );
302
+
306
303
if (pio -> read_details .buf == NULL ){
307
304
pio -> read_details .buf = malloc (READ_BUFFER_SIZE );
308
305
if (!pio -> read_details .buf ) {
@@ -313,11 +310,7 @@ fileio_ReadFileEx(struct w32_io* pio) {
313
310
pio -> read_details .buf_size = READ_BUFFER_SIZE ;
314
311
}
315
312
316
- /* get underlying handle for standard io */
317
- if (pio -> type == STD_IO_FD )
318
- h = GetStdHandle (pio -> std_handle );
319
-
320
- if (ReadFileEx (h , pio -> read_details .buf , pio -> read_details .buf_size ,
313
+ if (ReadFileEx (WINHANDLE (pio ), pio -> read_details .buf , pio -> read_details .buf_size ,
321
314
& pio -> read_overlapped , & ReadCompletionRoutine ))
322
315
pio -> read_details .pending = TRUE;
323
316
else {
@@ -335,11 +328,6 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
335
328
int bytes_copied ;
336
329
337
330
debug3 ("read - io:%p remaining:%d" , pio , pio -> read_details .remaining );
338
- if ((pio -> type == PIPE_FD ) && (pio -> internal .state == PIPE_WRITE_END )) {
339
- debug ("read - ERROR: called on write end of pipe, io:%p" , pio );
340
- errno = EBADF ;
341
- return -1 ;
342
- }
343
331
344
332
/* if read is pending */
345
333
if (pio -> read_details .pending ) {
@@ -357,7 +345,8 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
357
345
358
346
if (fileio_is_io_available (pio , TRUE) == FALSE) {
359
347
if (-1 == fileio_ReadFileEx (pio )) {
360
- if ((pio -> type == PIPE_FD ) && (errno == ERROR_NEGATIVE_SEEK )) {
348
+ if ((FILETYPE (pio ) == FILE_TYPE_PIPE )
349
+ && (errno == ERROR_NEGATIVE_SEEK )) {
361
350
/* write end of the pipe closed */
362
351
debug2 ("read - no more data, io:%p" , pio );
363
352
errno = 0 ;
@@ -433,14 +422,8 @@ VOID CALLBACK WriteCompletionRoutine(
433
422
int
434
423
fileio_write (struct w32_io * pio , const void * buf , unsigned int max ) {
435
424
int bytes_copied ;
436
- HANDLE h = pio -> handle ;
437
425
438
426
debug2 ("write - io:%p" , pio );
439
- if ((pio -> type == PIPE_FD ) && (pio -> internal .state == PIPE_READ_END )) {
440
- debug ("write - ERROR: write called on a read end of pipe, io:%p" , pio );
441
- errno = EBADF ;
442
- return -1 ;
443
- }
444
427
445
428
if (pio -> write_details .pending ) {
446
429
if (w32_io_is_blocking (pio ))
@@ -478,11 +461,7 @@ fileio_write(struct w32_io* pio, const void *buf, unsigned int max) {
478
461
bytes_copied = min (max , pio -> write_details .buf_size );
479
462
memcpy (pio -> write_details .buf , buf , bytes_copied );
480
463
481
- /* get underlying handle for standard io */
482
- if (pio -> type == STD_IO_FD )
483
- h = GetStdHandle (pio -> std_handle );
484
-
485
- if (WriteFileEx (h , pio -> write_details .buf , bytes_copied ,
464
+ if (WriteFileEx (WINHANDLE (pio ), pio -> write_details .buf , bytes_copied ,
486
465
& pio -> write_overlapped , & WriteCompletionRoutine )) {
487
466
pio -> write_details .pending = TRUE;
488
467
pio -> write_details .remaining = bytes_copied ;
@@ -507,8 +486,8 @@ fileio_write(struct w32_io* pio, const void *buf, unsigned int max) {
507
486
}
508
487
else {
509
488
errno = errno_from_Win32LastError ();
510
- /* read end of the pipe closed */
511
- if ((pio -> type == PIPE_FD ) && (errno == ERROR_NEGATIVE_SEEK )) {
489
+ /* read end of the pipe closed ? */
490
+ if ((FILETYPE ( pio ) == FILE_TYPE_PIPE ) && (errno == ERROR_NEGATIVE_SEEK )) {
512
491
debug ("write - ERROR:read end of the pipe closed, io:%p" , pio );
513
492
errno = EPIPE ;
514
493
}
@@ -551,17 +530,6 @@ fileio_lseek(struct w32_io* pio, long offset, int origin) {
551
530
return 0 ;
552
531
}
553
532
554
- /* isatty() implementation */
555
- int
556
- fileio_isatty (struct w32_io * pio ) {
557
- if (GetFileType (pio -> handle ) == FILE_TYPE_CHAR )
558
- return 1 ;
559
- else {
560
- errno = EINVAL ;
561
- return 0 ;
562
- }
563
- }
564
-
565
533
/* fdopen implementation */
566
534
FILE *
567
535
fileio_fdopen (struct w32_io * pio , const char * mode ) {
@@ -617,12 +585,14 @@ fileio_on_select(struct w32_io* pio, BOOL rd) {
617
585
618
586
int
619
587
fileio_close (struct w32_io * pio ) {
588
+
620
589
debug2 ("fileclose - pio:%p" , pio );
621
- CancelIo (pio -> handle );
590
+
591
+ CancelIo (WINHANDLE (pio ));
622
592
//let queued APCs (if any) drain
623
593
SleepEx (0 , TRUE);
624
594
if (pio -> type != STD_IO_FD ) {//STD handles are never explicitly closed
625
- CloseHandle (pio -> handle );
595
+ CloseHandle (WINHANDLE ( pio ) );
626
596
627
597
if (pio -> read_details .buf )
628
598
free (pio -> read_details .buf );
0 commit comments