40
40
# include < platform_win32.h>
41
41
#endif
42
42
43
-
44
43
namespace node {
45
44
46
45
using namespace v8 ;
@@ -68,10 +67,41 @@ static Persistent<String> buf_symbol;
68
67
static Persistent<String> oncomplete_sym;
69
68
70
69
71
- #ifdef _LARGEFILE_SOURCE
72
- static inline int IsInt64 (double x) {
73
- return x == static_cast <double >(static_cast <int64_t >(x));
74
- }
70
+ #ifndef _LARGEFILE_SOURCE
71
+ typedef off_t node_off_t ;
72
+ # define ASSERT_OFFSET (a ) \
73
+ STATIC_ASSERT (sizeof (node_off_t ) * CHAR_BIT >= 32); \
74
+ if (!(a)->IsUndefined () && !(a)->IsNull() && !(a)->IsInt32()) { \
75
+ return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
76
+ }
77
+ # define ASSERT_TRUNCATE_LENGTH (a ) \
78
+ if (!(a)->IsUndefined () && !(a)->IsNull() && !(a)->IsUint32()) { \
79
+ return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
80
+ }
81
+ # define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->Int32Value() : -1)
82
+ # define GET_TRUNCATE_LENGTH (a ) ((a)->Uint32Value ())
83
+ #else
84
+ # ifdef _WIN32
85
+ # define NODE_USE_64BIT_UV_FS_API
86
+ typedef int64_t node_off_t ;
87
+ # else
88
+ typedef off_t node_off_t ;
89
+ # endif
90
+ # define ASSERT_OFFSET (a ) \
91
+ STATIC_ASSERT (sizeof (node_off_t ) * CHAR_BIT >= 64); \
92
+ if (!(a)->IsUndefined () && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
93
+ return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
94
+ }
95
+ # define ASSERT_TRUNCATE_LENGTH (a ) \
96
+ if (!(a)->IsUndefined () && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
97
+ return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
98
+ }
99
+ # define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->IntegerValue() : -1)
100
+ # define GET_TRUNCATE_LENGTH (a ) ((a)->IntegerValue ())
101
+
102
+ static inline int IsInt64(double x) {
103
+ return x == static_cast <double >(static_cast <int64_t >(x));
104
+ }
75
105
#endif
76
106
77
107
@@ -470,20 +500,6 @@ static Handle<Value> Rename(const Arguments& args) {
470
500
}
471
501
}
472
502
473
- #ifndef _LARGEFILE_SOURCE
474
- #define ASSERT_TRUNCATE_LENGTH (a ) \
475
- if (!(a)->IsUndefined () && !(a)->IsNull() && !(a)->IsUint32()) { \
476
- return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
477
- }
478
- #define GET_TRUNCATE_LENGTH (a ) ((a)->Uint32Value ())
479
- #else
480
- #define ASSERT_TRUNCATE_LENGTH (a ) \
481
- if (!(a)->IsUndefined () && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
482
- return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
483
- }
484
- #define GET_TRUNCATE_LENGTH (a ) ((a)->IntegerValue ())
485
- #endif
486
-
487
503
static Handle<Value> Truncate (const Arguments& args) {
488
504
HandleScope scope;
489
505
@@ -494,12 +510,20 @@ static Handle<Value> Truncate(const Arguments& args) {
494
510
int fd = args[0 ]->Int32Value ();
495
511
496
512
ASSERT_TRUNCATE_LENGTH (args[1 ]);
497
- off_t len = GET_TRUNCATE_LENGTH (args[1 ]);
513
+ node_off_t len = GET_TRUNCATE_LENGTH (args[1 ]);
498
514
499
515
if (args[2 ]->IsFunction ()) {
516
+ #ifdef NODE_USE_64BIT_UV_FS_API
517
+ ASYNC_CALL (ftruncate64, args[2 ], fd, len)
518
+ #else
500
519
ASYNC_CALL (ftruncate, args[2 ], fd, len)
520
+ #endif
501
521
} else {
522
+ #ifdef NODE_USE_64BIT_UV_FS_API
523
+ SYNC_CALL (ftruncate64, 0 , fd, len)
524
+ #else
502
525
SYNC_CALL (ftruncate, 0 , fd, len)
526
+ #endif
503
527
return Undefined ();
504
528
}
505
529
}
@@ -671,20 +695,6 @@ static Handle<Value> Open(const Arguments& args) {
671
695
}
672
696
}
673
697
674
- #ifndef _LARGEFILE_SOURCE
675
- #define ASSERT_OFFSET (a ) \
676
- if (!(a)->IsUndefined () && !(a)->IsNull() && !(a)->IsInt32()) { \
677
- return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
678
- }
679
- #define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->Int32Value() : -1)
680
- #else
681
- #define ASSERT_OFFSET (a ) \
682
- if (!(a)->IsUndefined () && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
683
- return ThrowException (Exception::TypeError (String::New (" Not an integer" ))); \
684
- }
685
- #define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->IntegerValue() : -1)
686
- #endif
687
-
688
698
// bytesWritten = write(fd, data, position, enc, callback)
689
699
// Wrapper for write(2).
690
700
//
@@ -725,15 +735,23 @@ static Handle<Value> Write(const Arguments& args) {
725
735
}
726
736
727
737
ASSERT_OFFSET (args[4 ]);
728
- off_t pos = GET_OFFSET (args[4 ]);
738
+ node_off_t pos = GET_OFFSET (args[4 ]);
729
739
730
740
char * buf = (char *)buffer_data + off;
731
741
Local<Value> cb = args[5 ];
732
742
733
743
if (cb->IsFunction ()) {
744
+ #ifdef NODE_USE_64BIT_UV_FS_API
745
+ ASYNC_CALL (write64, cb, fd, buf, len, pos)
746
+ #else
734
747
ASYNC_CALL (write, cb, fd, buf, len, pos)
748
+ #endif
735
749
} else {
750
+ #ifdef NODE_USE_64BIT_UV_FS_API
751
+ SYNC_CALL (write64, 0 , fd, buf, len, pos)
752
+ #else
736
753
SYNC_CALL (write, 0 , fd, buf, len, pos)
754
+ #endif
737
755
return scope.Close (Integer::New (SYNC_RESULT));
738
756
}
739
757
}
@@ -762,7 +780,7 @@ static Handle<Value> Read(const Arguments& args) {
762
780
Local<Value> cb;
763
781
764
782
size_t len;
765
- off_t pos;
783
+ node_off_t pos;
766
784
767
785
char * buf = NULL ;
768
786
@@ -794,9 +812,17 @@ static Handle<Value> Read(const Arguments& args) {
794
812
cb = args[5 ];
795
813
796
814
if (cb->IsFunction ()) {
815
+ #ifdef NODE_USE_64BIT_UV_FS_API
816
+ ASYNC_CALL (read64, cb, fd, buf, len, pos);
817
+ #else
797
818
ASYNC_CALL (read, cb, fd, buf, len, pos);
819
+ #endif
798
820
} else {
821
+ #ifdef NODE_USE_64BIT_UV_FS_API
822
+ SYNC_CALL (read64, 0 , fd, buf, len, pos)
823
+ #else
799
824
SYNC_CALL (read, 0 , fd, buf, len, pos)
825
+ #endif
800
826
Local<Integer> bytesRead = Integer::New (SYNC_RESULT);
801
827
return scope.Close (bytesRead);
802
828
}
0 commit comments