xbintsc 0.3.13 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/codegen/generator/calls/access.js +13 -0
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +8 -2
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +6 -0
- package/dist/src/codegen/generator/context.js +24 -2
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.js +5 -0
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/driver/compiler.js +15 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/modules.d.ts +1 -1
- package/dist/src/driver/modules.js +235 -25
- package/dist/src/driver/modules.js.map +1 -1
- package/dist/src/extensions/node/fs/fs-ops.d.ts +5 -2
- package/dist/src/extensions/node/fs/fs-ops.js +45 -6
- package/dist/src/extensions/node/fs/fs-ops.js.map +1 -1
- package/dist/src/extensions/node/fs/index.d.ts +6 -2
- package/dist/src/extensions/node/fs/index.js +22 -3
- package/dist/src/extensions/node/fs/index.js.map +1 -1
- package/dist/src/extensions/node/fs-promises/index.d.ts +4 -3
- package/dist/src/extensions/node/fs-promises/index.js +31 -3
- package/dist/src/extensions/node/fs-promises/index.js.map +1 -1
- package/dist/tests/cli/main.test.js +8 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/driver/compiler.test.js +28 -1
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/modules.test.js +91 -4
- package/dist/tests/driver/modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +240 -0
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/compile.test.js +12 -0
- package/dist/tests/e2e/compile.test.js.map +1 -1
- package/dist/tests/e2e/harness.js +11 -8
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/node-modules.test.js +1 -1
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/npm-modules.test.d.ts +9 -0
- package/dist/tests/e2e/npm-modules.test.js +55 -0
- package/dist/tests/e2e/npm-modules.test.js.map +1 -0
- package/dist/tests/e2e/runtime-coverage.test.d.ts +11 -0
- package/dist/tests/e2e/runtime-coverage.test.js +646 -0
- package/dist/tests/e2e/runtime-coverage.test.js.map +1 -0
- package/package.json +1 -1
- package/runtime/ext_node/buffer/parts/prototype.inc +7 -0
- package/runtime/ext_node/buffer/parts/search.inc +8 -4
- package/runtime/ext_node/child_process/child_process.c +5 -0
- package/runtime/ext_node/fs/constants.c +113 -0
- package/runtime/ext_node/fs/copy_ops.c +145 -0
- package/runtime/ext_node/fs/dir.c +101 -0
- package/runtime/ext_node/fs/fd_ops.c +405 -0
- package/runtime/ext_node/fs/fs_common.h +388 -5
- package/runtime/ext_node/fs/fs_ops.c +100 -139
- package/runtime/ext_node/fs/glob.c +232 -0
- package/runtime/ext_node/fs/link_ops.c +91 -0
- package/runtime/ext_node/fs/meta_ops.c +403 -0
- package/runtime/ext_node/fs/promises.c +275 -60
- package/runtime/ext_node/fs/read_file.c +8 -4
- package/runtime/ext_node/fs/watch.c +52 -0
- package/runtime/ext_node/fs/write_file.c +20 -11
- package/runtime/ext_node/stream/stream.c +19 -2
- package/runtime/rt.h +9 -0
- package/runtime/xt_io.c +21 -0
- package/src/codegen/generator/calls/access.ts +15 -0
- package/src/codegen/generator/calls/invocation.ts +8 -2
- package/src/codegen/generator/context.ts +30 -2
- package/src/codegen/generator/expressions/primary.ts +5 -0
- package/src/driver/compiler.ts +16 -3
- package/src/driver/modules.ts +251 -26
- package/src/extensions/node/fs/fs-ops.ts +48 -6
- package/src/extensions/node/fs/index.ts +25 -3
- package/src/extensions/node/fs-promises/index.ts +33 -4
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Node.js `fs` file-descriptor operations for xbintsc.
|
|
3
|
+
*
|
|
4
|
+
* openSync, closeSync, readSync, writeSync, readvSync, writevSync,
|
|
5
|
+
* fstatSync, fsyncSync, fdatasyncSync, ftruncateSync, fchmodSync,
|
|
6
|
+
* fchownSync, futimesSync
|
|
7
|
+
*
|
|
8
|
+
* Buffers are the runtime's plain-object representation; the byte bridge lives
|
|
9
|
+
* in `buffer/parts/prototype.inc` (`xt_node_buffer_length`/`xt_node_buffer_set`).
|
|
10
|
+
* Errors throw Node-shaped `Error` objects (see `fs_common.h`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#include "../node_common.h"
|
|
14
|
+
#include "fs_common.h"
|
|
15
|
+
|
|
16
|
+
#include <fcntl.h>
|
|
17
|
+
#include <sys/stat.h>
|
|
18
|
+
#include <sys/types.h>
|
|
19
|
+
#if !defined(_WIN32)
|
|
20
|
+
#include <sys/time.h>
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#if defined(_WIN32)
|
|
24
|
+
#include <io.h>
|
|
25
|
+
#include <windows.h>
|
|
26
|
+
#define xt_fs_fsync _commit
|
|
27
|
+
#define xt_fs_fdatasync _commit
|
|
28
|
+
#define xt_fs_ftruncate(fd, length) _chsize_s((fd), (long long)(length))
|
|
29
|
+
#else
|
|
30
|
+
#include <unistd.h>
|
|
31
|
+
#define xt_fs_fstat_fn fstat
|
|
32
|
+
#define xt_fs_fsync fsync
|
|
33
|
+
#if defined(__APPLE__)
|
|
34
|
+
#define xt_fs_fdatasync fsync
|
|
35
|
+
#else
|
|
36
|
+
#define xt_fs_fdatasync fdatasync
|
|
37
|
+
#endif
|
|
38
|
+
#define xt_fs_ftruncate(fd, length) ftruncate((fd), (off_t)(length))
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#if defined(_WIN32)
|
|
42
|
+
/* See meta_ops.c: set times through `SetFileTime` so the conversion is exact
|
|
43
|
+
* and does not depend on the CRT's local-time `_utimbuf` ABI. */
|
|
44
|
+
static void xt_fs_unix_to_filetime(double seconds, FILETIME *out) {
|
|
45
|
+
long long ticks = (long long)(seconds * 10000000.0) + 116444736000000000LL;
|
|
46
|
+
unsigned long long value = (unsigned long long)ticks;
|
|
47
|
+
out->dwLowDateTime = (DWORD)value;
|
|
48
|
+
out->dwHighDateTime = (DWORD)(value >> 32);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static int xt_fs_set_file_times(HANDLE handle, double atime, double mtime) {
|
|
52
|
+
FILETIME access_time;
|
|
53
|
+
FILETIME modify_time;
|
|
54
|
+
FILETIME *access_ptr = NULL;
|
|
55
|
+
FILETIME *modify_ptr = NULL;
|
|
56
|
+
if (atime == atime) {
|
|
57
|
+
xt_fs_unix_to_filetime(atime, &access_time);
|
|
58
|
+
access_ptr = &access_time;
|
|
59
|
+
}
|
|
60
|
+
if (mtime == mtime) {
|
|
61
|
+
xt_fs_unix_to_filetime(mtime, &modify_time);
|
|
62
|
+
modify_ptr = &modify_time;
|
|
63
|
+
}
|
|
64
|
+
return SetFileTime(handle, NULL, access_ptr, modify_ptr) ? 0 : -1;
|
|
65
|
+
}
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
/* Bytes backing a string or Buffer value; caller frees. */
|
|
69
|
+
static unsigned char *xt_fs_value_bytes(xt_value value, size_t *outLength) {
|
|
70
|
+
if (xt_node_is_buffer(value)) return xt_node_buffer_bytes(value, outLength);
|
|
71
|
+
xt_value text = xt_to_string(value);
|
|
72
|
+
xt_string *string = xt_as_string(text);
|
|
73
|
+
size_t length = string ? string->length : 0;
|
|
74
|
+
unsigned char *bytes = (unsigned char *)malloc(length ? length : 1);
|
|
75
|
+
if (!bytes) {
|
|
76
|
+
*outLength = 0;
|
|
77
|
+
return NULL;
|
|
78
|
+
}
|
|
79
|
+
if (length > 0) memcpy(bytes, string->data, length);
|
|
80
|
+
*outLength = length;
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ------------------------------------------------------------------------- */
|
|
85
|
+
/* openSync / closeSync */
|
|
86
|
+
/* ------------------------------------------------------------------------- */
|
|
87
|
+
|
|
88
|
+
xt_value xt_node_open(int32_t argc, xt_value *argv) {
|
|
89
|
+
if (argc < 1) return xt_undefined();
|
|
90
|
+
const char *path = xt_node_cstr(argv[0]);
|
|
91
|
+
if (!path) {
|
|
92
|
+
xt_fs_raise_errno(EINVAL, "open", NULL);
|
|
93
|
+
return xt_undefined();
|
|
94
|
+
}
|
|
95
|
+
int flags = argc > 1 ? xt_fs_parse_flags(argv[1]) : (XT_FS_RDONLY | XT_FS_BINARY_FLAG);
|
|
96
|
+
int mode = argc > 2 ? (int)xt_to_number(argv[2]) : 0666;
|
|
97
|
+
#if defined(_WIN32)
|
|
98
|
+
int fd = _open(path, flags, mode);
|
|
99
|
+
#else
|
|
100
|
+
int fd = open(path, flags, mode);
|
|
101
|
+
#endif
|
|
102
|
+
if (fd < 0) {
|
|
103
|
+
xt_fs_raise_path("open", path);
|
|
104
|
+
return xt_undefined();
|
|
105
|
+
}
|
|
106
|
+
return xt_number((double)fd);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
xt_value xt_node_close(int32_t argc, xt_value *argv) {
|
|
110
|
+
if (argc < 1) return xt_undefined();
|
|
111
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
112
|
+
if (XT_FS_CLOSE(fd) != 0) {
|
|
113
|
+
xt_fs_raise_path("close", NULL);
|
|
114
|
+
return xt_undefined();
|
|
115
|
+
}
|
|
116
|
+
return xt_undefined();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ------------------------------------------------------------------------- */
|
|
120
|
+
/* readSync / writeSync */
|
|
121
|
+
/* ------------------------------------------------------------------------- */
|
|
122
|
+
|
|
123
|
+
xt_value xt_node_read(int32_t argc, xt_value *argv) {
|
|
124
|
+
if (argc < 2) return xt_undefined();
|
|
125
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
126
|
+
xt_value buffer = argv[1];
|
|
127
|
+
if (!xt_node_is_buffer(buffer)) {
|
|
128
|
+
xt_fs_raise_errno(EINVAL, "read", NULL);
|
|
129
|
+
return xt_undefined();
|
|
130
|
+
}
|
|
131
|
+
uint32_t bufferLength = xt_node_buffer_length(buffer);
|
|
132
|
+
uint32_t offset = argc > 2 ? (uint32_t)xt_to_number(argv[2]) : 0;
|
|
133
|
+
uint32_t length = argc > 3 ? (uint32_t)xt_to_number(argv[3]) : (bufferLength > offset ? bufferLength - offset : 0);
|
|
134
|
+
int64_t position =
|
|
135
|
+
argc > 4 && !XT_IS_UNDEFINED(argv[4]) && !XT_IS_NULL(argv[4]) ? (int64_t)xt_to_number(argv[4]) : -1;
|
|
136
|
+
if (length == 0) return xt_number(0);
|
|
137
|
+
|
|
138
|
+
unsigned char *temp = (unsigned char *)malloc(length);
|
|
139
|
+
if (!temp) return xt_number(0);
|
|
140
|
+
ssize_t bytesRead = -1;
|
|
141
|
+
if (position >= 0) {
|
|
142
|
+
#if defined(_WIN32)
|
|
143
|
+
_lseeki64(fd, position, SEEK_SET);
|
|
144
|
+
bytesRead = _read(fd, temp, (unsigned int)length);
|
|
145
|
+
#else
|
|
146
|
+
bytesRead = pread(fd, temp, length, (off_t)position);
|
|
147
|
+
#endif
|
|
148
|
+
} else {
|
|
149
|
+
bytesRead = XT_FS_READ(fd, temp, length);
|
|
150
|
+
}
|
|
151
|
+
if (bytesRead < 0) {
|
|
152
|
+
free(temp);
|
|
153
|
+
xt_fs_raise_path("read", NULL);
|
|
154
|
+
return xt_undefined();
|
|
155
|
+
}
|
|
156
|
+
for (ssize_t i = 0; i < bytesRead; i++) xt_node_buffer_set(buffer, offset + (uint32_t)i, temp[i]);
|
|
157
|
+
free(temp);
|
|
158
|
+
return xt_number((double)bytesRead);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
xt_value xt_node_write(int32_t argc, xt_value *argv) {
|
|
162
|
+
if (argc < 2) return xt_undefined();
|
|
163
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
164
|
+
xt_value data = argv[1];
|
|
165
|
+
int isBuffer = xt_node_is_buffer(data);
|
|
166
|
+
size_t length = 0;
|
|
167
|
+
unsigned char *bytes = xt_fs_value_bytes(data, &length);
|
|
168
|
+
if (!bytes) return xt_undefined();
|
|
169
|
+
|
|
170
|
+
uint32_t offset = 0;
|
|
171
|
+
uint32_t writeLength = (uint32_t)length;
|
|
172
|
+
int64_t position = -1;
|
|
173
|
+
if (isBuffer) {
|
|
174
|
+
if (argc > 2) offset = (uint32_t)xt_to_number(argv[2]);
|
|
175
|
+
if (argc > 3 && !XT_IS_UNDEFINED(argv[3]) && !XT_IS_NULL(argv[3])) writeLength = (uint32_t)xt_to_number(argv[3]);
|
|
176
|
+
if (argc > 4 && !XT_IS_UNDEFINED(argv[4]) && !XT_IS_NULL(argv[4])) position = (int64_t)xt_to_number(argv[4]);
|
|
177
|
+
} else {
|
|
178
|
+
if (argc > 2 && !XT_IS_UNDEFINED(argv[2]) && !XT_IS_NULL(argv[2])) position = (int64_t)xt_to_number(argv[2]);
|
|
179
|
+
}
|
|
180
|
+
if (offset > length) offset = (uint32_t)length;
|
|
181
|
+
if (writeLength > length - offset) writeLength = (uint32_t)length - offset;
|
|
182
|
+
if (writeLength == 0) {
|
|
183
|
+
free(bytes);
|
|
184
|
+
return xt_number(0);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
ssize_t written = -1;
|
|
188
|
+
if (position >= 0) {
|
|
189
|
+
#if defined(_WIN32)
|
|
190
|
+
_lseeki64(fd, position, SEEK_SET);
|
|
191
|
+
written = _write(fd, bytes + offset, (unsigned int)writeLength);
|
|
192
|
+
#else
|
|
193
|
+
written = pwrite(fd, bytes + offset, writeLength, (off_t)position);
|
|
194
|
+
#endif
|
|
195
|
+
} else {
|
|
196
|
+
written = XT_FS_WRITE(fd, bytes + offset, writeLength);
|
|
197
|
+
}
|
|
198
|
+
free(bytes);
|
|
199
|
+
if (written < 0) {
|
|
200
|
+
xt_fs_raise_path("write", NULL);
|
|
201
|
+
return xt_undefined();
|
|
202
|
+
}
|
|
203
|
+
return xt_number((double)written);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* ------------------------------------------------------------------------- */
|
|
207
|
+
/* readvSync / writevSync */
|
|
208
|
+
/* ------------------------------------------------------------------------- */
|
|
209
|
+
|
|
210
|
+
xt_value xt_node_readv(int32_t argc, xt_value *argv) {
|
|
211
|
+
if (argc < 2) return xt_undefined();
|
|
212
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
213
|
+
xt_value buffers = argv[1];
|
|
214
|
+
if (!XT_IS_ARRAY(buffers)) {
|
|
215
|
+
xt_fs_raise_errno(EINVAL, "read", NULL);
|
|
216
|
+
return xt_undefined();
|
|
217
|
+
}
|
|
218
|
+
int64_t position =
|
|
219
|
+
argc > 2 && !XT_IS_UNDEFINED(argv[2]) && !XT_IS_NULL(argv[2]) ? (int64_t)xt_to_number(argv[2]) : -1;
|
|
220
|
+
int32_t count = (int32_t)xt_to_number(xt_array_length(buffers));
|
|
221
|
+
int64_t total = 0;
|
|
222
|
+
for (int32_t i = 0; i < count; i++) {
|
|
223
|
+
xt_value buffer = xt_array_get(buffers, xt_number((double)i));
|
|
224
|
+
if (!xt_node_is_buffer(buffer)) continue;
|
|
225
|
+
uint32_t length = xt_node_buffer_length(buffer);
|
|
226
|
+
if (length == 0) continue;
|
|
227
|
+
unsigned char *temp = (unsigned char *)malloc(length);
|
|
228
|
+
if (!temp) break;
|
|
229
|
+
ssize_t bytesRead = -1;
|
|
230
|
+
if (position >= 0) {
|
|
231
|
+
#if defined(_WIN32)
|
|
232
|
+
_lseeki64(fd, position + total, SEEK_SET);
|
|
233
|
+
bytesRead = _read(fd, temp, (unsigned int)length);
|
|
234
|
+
#else
|
|
235
|
+
bytesRead = pread(fd, temp, length, (off_t)(position + total));
|
|
236
|
+
#endif
|
|
237
|
+
} else {
|
|
238
|
+
bytesRead = XT_FS_READ(fd, temp, length);
|
|
239
|
+
}
|
|
240
|
+
if (bytesRead <= 0) {
|
|
241
|
+
free(temp);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
for (ssize_t j = 0; j < bytesRead; j++) xt_node_buffer_set(buffer, (uint32_t)j, temp[j]);
|
|
245
|
+
total += bytesRead;
|
|
246
|
+
free(temp);
|
|
247
|
+
if ((uint32_t)bytesRead < length) break;
|
|
248
|
+
}
|
|
249
|
+
return xt_number((double)total);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
xt_value xt_node_writev(int32_t argc, xt_value *argv) {
|
|
253
|
+
if (argc < 2) return xt_undefined();
|
|
254
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
255
|
+
xt_value buffers = argv[1];
|
|
256
|
+
if (!XT_IS_ARRAY(buffers)) {
|
|
257
|
+
xt_fs_raise_errno(EINVAL, "write", NULL);
|
|
258
|
+
return xt_undefined();
|
|
259
|
+
}
|
|
260
|
+
int64_t position =
|
|
261
|
+
argc > 2 && !XT_IS_UNDEFINED(argv[2]) && !XT_IS_NULL(argv[2]) ? (int64_t)xt_to_number(argv[2]) : -1;
|
|
262
|
+
int32_t count = (int32_t)xt_to_number(xt_array_length(buffers));
|
|
263
|
+
int64_t total = 0;
|
|
264
|
+
for (int32_t i = 0; i < count; i++) {
|
|
265
|
+
xt_value buffer = xt_array_get(buffers, xt_number((double)i));
|
|
266
|
+
if (!xt_node_is_buffer(buffer)) continue;
|
|
267
|
+
size_t length = 0;
|
|
268
|
+
unsigned char *bytes = xt_node_buffer_bytes(buffer, &length);
|
|
269
|
+
if (!bytes || length == 0) {
|
|
270
|
+
free(bytes);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
ssize_t written = -1;
|
|
274
|
+
if (position >= 0) {
|
|
275
|
+
#if defined(_WIN32)
|
|
276
|
+
_lseeki64(fd, position + total, SEEK_SET);
|
|
277
|
+
written = _write(fd, bytes, (unsigned int)length);
|
|
278
|
+
#else
|
|
279
|
+
written = pwrite(fd, bytes, length, (off_t)(position + total));
|
|
280
|
+
#endif
|
|
281
|
+
} else {
|
|
282
|
+
written = XT_FS_WRITE(fd, bytes, length);
|
|
283
|
+
}
|
|
284
|
+
free(bytes);
|
|
285
|
+
if (written < 0) {
|
|
286
|
+
xt_fs_raise_path("write", NULL);
|
|
287
|
+
return xt_undefined();
|
|
288
|
+
}
|
|
289
|
+
total += written;
|
|
290
|
+
if ((size_t)written < length) break;
|
|
291
|
+
}
|
|
292
|
+
return xt_number((double)total);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* ------------------------------------------------------------------------- */
|
|
296
|
+
/* fstatSync / fsyncSync / fdatasyncSync / ftruncateSync */
|
|
297
|
+
/* ------------------------------------------------------------------------- */
|
|
298
|
+
|
|
299
|
+
xt_value xt_node_fstat(int32_t argc, xt_value *argv) {
|
|
300
|
+
if (argc < 1) return xt_undefined();
|
|
301
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
302
|
+
xt_fs_stat_t info;
|
|
303
|
+
if (xt_fs_fstat_fn(fd, &info) != 0) {
|
|
304
|
+
xt_fs_raise_path("fstat", NULL);
|
|
305
|
+
return xt_undefined();
|
|
306
|
+
}
|
|
307
|
+
return xt_node_stat_result(&info);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
xt_value xt_node_fsync(int32_t argc, xt_value *argv) {
|
|
311
|
+
if (argc < 1) return xt_undefined();
|
|
312
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
313
|
+
if (xt_fs_fsync(fd) != 0) {
|
|
314
|
+
xt_fs_raise_path("fsync", NULL);
|
|
315
|
+
return xt_undefined();
|
|
316
|
+
}
|
|
317
|
+
return xt_undefined();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
xt_value xt_node_fdatasync(int32_t argc, xt_value *argv) {
|
|
321
|
+
if (argc < 1) return xt_undefined();
|
|
322
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
323
|
+
if (xt_fs_fdatasync(fd) != 0) {
|
|
324
|
+
xt_fs_raise_path("fdatasync", NULL);
|
|
325
|
+
return xt_undefined();
|
|
326
|
+
}
|
|
327
|
+
return xt_undefined();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
xt_value xt_node_ftruncate(int32_t argc, xt_value *argv) {
|
|
331
|
+
if (argc < 1) return xt_undefined();
|
|
332
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
333
|
+
int64_t length = argc > 1 ? (int64_t)xt_to_number(argv[1]) : 0;
|
|
334
|
+
if (xt_fs_ftruncate(fd, length) != 0) {
|
|
335
|
+
xt_fs_raise_path("ftruncate", NULL);
|
|
336
|
+
return xt_undefined();
|
|
337
|
+
}
|
|
338
|
+
return xt_undefined();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* ------------------------------------------------------------------------- */
|
|
342
|
+
/* fchmodSync / fchownSync / futimesSync */
|
|
343
|
+
/* ------------------------------------------------------------------------- */
|
|
344
|
+
|
|
345
|
+
xt_value xt_node_fchmod(int32_t argc, xt_value *argv) {
|
|
346
|
+
if (argc < 2) return xt_undefined();
|
|
347
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
348
|
+
int mode = (int)xt_to_number(argv[1]);
|
|
349
|
+
#if defined(_WIN32)
|
|
350
|
+
(void)fd;
|
|
351
|
+
(void)mode;
|
|
352
|
+
return xt_undefined();
|
|
353
|
+
#else
|
|
354
|
+
if (fchmod(fd, (mode_t)mode) != 0) {
|
|
355
|
+
xt_fs_raise_path("fchmod", NULL);
|
|
356
|
+
return xt_undefined();
|
|
357
|
+
}
|
|
358
|
+
return xt_undefined();
|
|
359
|
+
#endif
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
xt_value xt_node_fchown(int32_t argc, xt_value *argv) {
|
|
363
|
+
if (argc < 3) return xt_undefined();
|
|
364
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
365
|
+
int uid = (int)xt_to_number(argv[1]);
|
|
366
|
+
int gid = (int)xt_to_number(argv[2]);
|
|
367
|
+
#if defined(_WIN32)
|
|
368
|
+
(void)fd;
|
|
369
|
+
(void)uid;
|
|
370
|
+
(void)gid;
|
|
371
|
+
return xt_undefined();
|
|
372
|
+
#else
|
|
373
|
+
if (fchown(fd, (uid_t)uid, (gid_t)gid) != 0) {
|
|
374
|
+
xt_fs_raise_path("fchown", NULL);
|
|
375
|
+
return xt_undefined();
|
|
376
|
+
}
|
|
377
|
+
return xt_undefined();
|
|
378
|
+
#endif
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
xt_value xt_node_futimes(int32_t argc, xt_value *argv) {
|
|
382
|
+
if (argc < 3) return xt_undefined();
|
|
383
|
+
int fd = (int)xt_to_number(argv[0]);
|
|
384
|
+
double atime = xt_fs_time_seconds(argv[1]);
|
|
385
|
+
double mtime = xt_fs_time_seconds(argv[2]);
|
|
386
|
+
#if defined(_WIN32)
|
|
387
|
+
intptr_t os_handle = _get_osfhandle(fd);
|
|
388
|
+
if (os_handle == -1 || xt_fs_set_file_times((HANDLE)os_handle, atime, mtime) != 0) {
|
|
389
|
+
xt_fs_raise_path("futime", NULL);
|
|
390
|
+
return xt_undefined();
|
|
391
|
+
}
|
|
392
|
+
return xt_undefined();
|
|
393
|
+
#else
|
|
394
|
+
struct timeval times[2];
|
|
395
|
+
times[0].tv_sec = (time_t)atime;
|
|
396
|
+
times[0].tv_usec = (suseconds_t)((atime - (double)times[0].tv_sec) * 1000000.0);
|
|
397
|
+
times[1].tv_sec = (time_t)mtime;
|
|
398
|
+
times[1].tv_usec = (suseconds_t)((mtime - (double)times[1].tv_sec) * 1000000.0);
|
|
399
|
+
if (futimes(fd, times) != 0) {
|
|
400
|
+
xt_fs_raise_path("futimes", NULL);
|
|
401
|
+
return xt_undefined();
|
|
402
|
+
}
|
|
403
|
+
return xt_undefined();
|
|
404
|
+
#endif
|
|
405
|
+
}
|