@@ -556,9 +556,14 @@ void fs__read(uv_fs_t* req) {
556
556
DWORD error ;
557
557
int result ;
558
558
unsigned int index ;
559
+ LARGE_INTEGER original_position ;
560
+ LARGE_INTEGER zero_offset ;
561
+ int restore_position ;
559
562
560
563
VERIFY_FD (fd , req );
561
564
565
+ zero_offset .QuadPart = 0 ;
566
+ restore_position = 0 ;
562
567
handle = uv__get_osfhandle (fd );
563
568
564
569
if (handle == INVALID_HANDLE_VALUE ) {
@@ -569,6 +574,10 @@ void fs__read(uv_fs_t* req) {
569
574
if (offset != -1 ) {
570
575
memset (& overlapped , 0 , sizeof overlapped );
571
576
overlapped_ptr = & overlapped ;
577
+ if (SetFilePointerEx (handle , zero_offset , & original_position ,
578
+ FILE_CURRENT )) {
579
+ restore_position = 1 ;
580
+ }
572
581
} else {
573
582
overlapped_ptr = NULL ;
574
583
}
@@ -593,6 +602,9 @@ void fs__read(uv_fs_t* req) {
593
602
++ index ;
594
603
} while (result && index < req -> fs .info .nbufs );
595
604
605
+ if (restore_position )
606
+ SetFilePointerEx (handle , original_position , NULL , FILE_BEGIN );
607
+
596
608
if (result || bytes > 0 ) {
597
609
SET_REQ_RESULT (req , bytes );
598
610
} else {
@@ -615,9 +627,14 @@ void fs__write(uv_fs_t* req) {
615
627
DWORD bytes ;
616
628
int result ;
617
629
unsigned int index ;
630
+ LARGE_INTEGER original_position ;
631
+ LARGE_INTEGER zero_offset ;
632
+ int restore_position ;
618
633
619
634
VERIFY_FD (fd , req );
620
635
636
+ zero_offset .QuadPart = 0 ;
637
+ restore_position = 0 ;
621
638
handle = uv__get_osfhandle (fd );
622
639
if (handle == INVALID_HANDLE_VALUE ) {
623
640
SET_REQ_WIN32_ERROR (req , ERROR_INVALID_HANDLE );
@@ -627,6 +644,10 @@ void fs__write(uv_fs_t* req) {
627
644
if (offset != -1 ) {
628
645
memset (& overlapped , 0 , sizeof overlapped );
629
646
overlapped_ptr = & overlapped ;
647
+ if (SetFilePointerEx (handle , zero_offset , & original_position ,
648
+ FILE_CURRENT )) {
649
+ restore_position = 1 ;
650
+ }
630
651
} else {
631
652
overlapped_ptr = NULL ;
632
653
}
@@ -651,6 +672,9 @@ void fs__write(uv_fs_t* req) {
651
672
++ index ;
652
673
} while (result && index < req -> fs .info .nbufs );
653
674
675
+ if (restore_position )
676
+ SetFilePointerEx (handle , original_position , NULL , FILE_BEGIN );
677
+
654
678
if (result || bytes > 0 ) {
655
679
SET_REQ_RESULT (req , bytes );
656
680
} else {
0 commit comments