flyshell 1.4.3__tar.gz → 1.4.4__tar.gz
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.
- {flyshell-1.4.3/src/flyshell.egg-info → flyshell-1.4.4}/PKG-INFO +1 -1
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/diskops.c +8 -1
- flyshell-1.4.4/c_src/diskops/posix/cat.c +86 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/posix/dir.c +9 -2
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/posix/touch.c +9 -7
- flyshell-1.4.4/c_src/diskops/win32/cat.c +96 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/constants.py +2 -2
- {flyshell-1.4.3 → flyshell-1.4.4/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_diskops_ext.py +24 -1
- flyshell-1.4.3/c_src/diskops/posix/cat.c +0 -58
- flyshell-1.4.3/c_src/diskops/win32/cat.c +0 -70
- {flyshell-1.4.3 → flyshell-1.4.4}/LICENSE +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/MANIFEST.in +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/README.md +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/shared/dir_types.c +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/shared/dir_types.h +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/shared/win32_utf.h +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/win32/dir.c +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/c_src/diskops/win32/touch.c +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/pyproject.toml +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/setup.cfg +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/setup.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/accounts/auth.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/diskops.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/pkg.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/core/console.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/core/data.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/core/directory.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/main.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/native/diskops_handler.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/native/legacy/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/native/legacy/diskops.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/startup/deps.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/startup/env.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell/startup/loader.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell.egg-info/SOURCES.txt +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_auth.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_data.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_deps.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_directory.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_diskops_lgc.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_diskops_old.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_env.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_fs.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_loader.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_pkg.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_security.py +0 -0
- {flyshell-1.4.3 → flyshell-1.4.4}/tests/test_utils.py +0 -0
|
@@ -65,6 +65,7 @@ static PyObject *method_dir(PyObject *self, PyObject *args) {
|
|
|
65
65
|
|
|
66
66
|
PyObject *py_list = PyList_New((Py_ssize_t)dir_list.count);
|
|
67
67
|
if (!py_list) {
|
|
68
|
+
PyErr_Clear();
|
|
68
69
|
free_dir_list(&dir_list);
|
|
69
70
|
return Py_BuildValue("(i[])", (int)ERR_IO);
|
|
70
71
|
}
|
|
@@ -72,7 +73,13 @@ static PyObject *method_dir(PyObject *self, PyObject *args) {
|
|
|
72
73
|
for (size_t i = 0; i < dir_list.count; ++i) {
|
|
73
74
|
PyObject *item = Py_BuildValue("(sO)", dir_list.entries[i].name,
|
|
74
75
|
dir_list.entries[i].is_dir ? Py_True : Py_False);
|
|
75
|
-
|
|
76
|
+
if (!item) {
|
|
77
|
+
PyErr_Clear();
|
|
78
|
+
Py_DECREF(py_list);
|
|
79
|
+
free_dir_list(&dir_list);
|
|
80
|
+
return Py_BuildValue("(i[])", (int)ERR_DECODE);
|
|
81
|
+
}
|
|
82
|
+
PyList_SET_ITEM(py_list, (Py_ssize_t)i, item);
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
free_dir_list(&dir_list);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// c_src/diskops/posix/cat.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
#include <unistd.h>
|
|
9
|
+
|
|
10
|
+
#define CAT_CHUNK_SIZE 32768
|
|
11
|
+
|
|
12
|
+
Result cat(const char *path, char **out_buf, size_t *out_size) {
|
|
13
|
+
if (!path || !out_buf || !out_size) {
|
|
14
|
+
return ERR_INVALID_PATH;
|
|
15
|
+
}
|
|
16
|
+
*out_buf = NULL;
|
|
17
|
+
*out_size = 0;
|
|
18
|
+
|
|
19
|
+
int fd = open(path, O_RDONLY);
|
|
20
|
+
if (fd < 0) {
|
|
21
|
+
return map_posix_errno(errno);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
struct stat st;
|
|
25
|
+
if (fstat(fd, &st) < 0) {
|
|
26
|
+
int err = errno;
|
|
27
|
+
close(fd);
|
|
28
|
+
return map_posix_errno(err);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (S_ISDIR(st.st_mode)) {
|
|
32
|
+
close(fd);
|
|
33
|
+
return ERR_IS_DIR;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
size_t capacity = (st.st_size > 0) ? ((size_t)st.st_size + 1) : CAT_CHUNK_SIZE;
|
|
37
|
+
char *buf = (char *)malloc(capacity);
|
|
38
|
+
if (!buf) {
|
|
39
|
+
close(fd);
|
|
40
|
+
return ERR_IO;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
size_t total_read = 0;
|
|
44
|
+
for (;;) {
|
|
45
|
+
if (total_read + CAT_CHUNK_SIZE + 1 > capacity) {
|
|
46
|
+
size_t new_cap = capacity * 2;
|
|
47
|
+
if (new_cap < total_read + CAT_CHUNK_SIZE + 1) {
|
|
48
|
+
new_cap = total_read + CAT_CHUNK_SIZE + 1;
|
|
49
|
+
}
|
|
50
|
+
char *resized = (char *)realloc(buf, new_cap);
|
|
51
|
+
if (!resized) {
|
|
52
|
+
close(fd);
|
|
53
|
+
free(buf);
|
|
54
|
+
return ERR_IO;
|
|
55
|
+
}
|
|
56
|
+
buf = resized;
|
|
57
|
+
capacity = new_cap;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ssize_t n = read(fd, buf + total_read, CAT_CHUNK_SIZE);
|
|
61
|
+
if (n < 0) {
|
|
62
|
+
if (errno == EINTR) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
int read_err = errno;
|
|
66
|
+
close(fd);
|
|
67
|
+
free(buf);
|
|
68
|
+
return map_posix_errno(read_err);
|
|
69
|
+
}
|
|
70
|
+
if (n == 0) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
total_read += (size_t)n;
|
|
74
|
+
}
|
|
75
|
+
close(fd);
|
|
76
|
+
|
|
77
|
+
if (total_read == 0) {
|
|
78
|
+
free(buf);
|
|
79
|
+
return ERR_EMPTY;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
buf[total_read] = '\0';
|
|
83
|
+
*out_buf = buf;
|
|
84
|
+
*out_size = total_read;
|
|
85
|
+
return SUCCESS;
|
|
86
|
+
}
|
|
@@ -50,7 +50,7 @@ Result list_dir(const char *path, DirList *out_list) {
|
|
|
50
50
|
|
|
51
51
|
bool is_dir = false;
|
|
52
52
|
#ifdef _DIRENT_HAVE_D_TYPE
|
|
53
|
-
if (entry->d_type != DT_UNKNOWN) {
|
|
53
|
+
if (entry->d_type != DT_UNKNOWN && entry->d_type != DT_LNK) {
|
|
54
54
|
is_dir = (entry->d_type == DT_DIR);
|
|
55
55
|
} else
|
|
56
56
|
#endif
|
|
@@ -61,7 +61,14 @@ Result list_dir(const char *path, DirList *out_list) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
char *name_copy = strdup(entry->d_name);
|
|
65
|
+
if (!name_copy) {
|
|
66
|
+
closedir(dir);
|
|
67
|
+
free_dir_list(out_list);
|
|
68
|
+
return ERR_IO;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
out_list->entries[out_list->count].name = name_copy;
|
|
65
72
|
out_list->entries[out_list->count].is_dir = is_dir;
|
|
66
73
|
out_list->count++;
|
|
67
74
|
}
|
|
@@ -15,16 +15,18 @@ Result touch(const char *path) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
struct stat st;
|
|
18
|
-
if (stat(path, &st) == 0) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return map_posix_errno(errno);
|
|
24
|
-
}
|
|
18
|
+
if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
|
|
19
|
+
return ERR_IS_DIR;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (utimensat(AT_FDCWD, path, NULL, 0) == 0) {
|
|
25
23
|
return SUCCESS;
|
|
26
24
|
}
|
|
27
25
|
|
|
26
|
+
if (errno != ENOENT) {
|
|
27
|
+
return map_posix_errno(errno);
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
int fd = open(path, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY, 0666);
|
|
29
31
|
if (fd < 0) {
|
|
30
32
|
return map_posix_errno(errno);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// c_src/diskops/win32/cat.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include "../shared/win32_utf.h"
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <windows.h>
|
|
7
|
+
|
|
8
|
+
#define CAT_CHUNK_SIZE 32768
|
|
9
|
+
|
|
10
|
+
Result cat(const char *path, char **out_buf, size_t *out_size) {
|
|
11
|
+
if (!path || !out_buf || !out_size) {
|
|
12
|
+
return ERR_INVALID_PATH;
|
|
13
|
+
}
|
|
14
|
+
*out_buf = NULL;
|
|
15
|
+
*out_size = 0;
|
|
16
|
+
|
|
17
|
+
wchar_t *wpath = utf8_to_wide(path);
|
|
18
|
+
if (!wpath) {
|
|
19
|
+
return ERR_INVALID_PATH;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
HANDLE hFile =
|
|
23
|
+
CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
24
|
+
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
25
|
+
|
|
26
|
+
if (hFile == INVALID_HANDLE_VALUE) {
|
|
27
|
+
DWORD err = GetLastError();
|
|
28
|
+
if (err == ERROR_ACCESS_DENIED) {
|
|
29
|
+
DWORD attrs = GetFileAttributesW(wpath);
|
|
30
|
+
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
31
|
+
free(wpath);
|
|
32
|
+
return ERR_IS_DIR;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
free(wpath);
|
|
36
|
+
return map_win32_error(err);
|
|
37
|
+
}
|
|
38
|
+
free(wpath);
|
|
39
|
+
|
|
40
|
+
LARGE_INTEGER size;
|
|
41
|
+
size_t capacity = CAT_CHUNK_SIZE;
|
|
42
|
+
if (GetFileSizeEx(hFile, &size) && size.QuadPart > 0) {
|
|
43
|
+
if ((ULONGLONG)size.QuadPart > (ULONGLONG)(SIZE_MAX - 1)) {
|
|
44
|
+
CloseHandle(hFile);
|
|
45
|
+
return ERR_IO;
|
|
46
|
+
}
|
|
47
|
+
capacity = (size_t)size.QuadPart + 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
char *buf = (char *)malloc(capacity);
|
|
51
|
+
if (!buf) {
|
|
52
|
+
CloseHandle(hFile);
|
|
53
|
+
return ERR_IO;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
size_t total_read = 0;
|
|
57
|
+
for (;;) {
|
|
58
|
+
if (total_read + CAT_CHUNK_SIZE + 1 > capacity) {
|
|
59
|
+
size_t new_cap = capacity * 2;
|
|
60
|
+
if (new_cap < total_read + CAT_CHUNK_SIZE + 1) {
|
|
61
|
+
new_cap = total_read + CAT_CHUNK_SIZE + 1;
|
|
62
|
+
}
|
|
63
|
+
char *resized = (char *)realloc(buf, new_cap);
|
|
64
|
+
if (!resized) {
|
|
65
|
+
CloseHandle(hFile);
|
|
66
|
+
free(buf);
|
|
67
|
+
return ERR_IO;
|
|
68
|
+
}
|
|
69
|
+
buf = resized;
|
|
70
|
+
capacity = new_cap;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
DWORD bytes_read = 0;
|
|
74
|
+
if (!ReadFile(hFile, buf + total_read, CAT_CHUNK_SIZE, &bytes_read, NULL)) {
|
|
75
|
+
DWORD read_err = GetLastError();
|
|
76
|
+
CloseHandle(hFile);
|
|
77
|
+
free(buf);
|
|
78
|
+
return map_win32_error(read_err);
|
|
79
|
+
}
|
|
80
|
+
if (bytes_read == 0) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
total_read += (size_t)bytes_read;
|
|
84
|
+
}
|
|
85
|
+
CloseHandle(hFile);
|
|
86
|
+
|
|
87
|
+
if (total_read == 0) {
|
|
88
|
+
free(buf);
|
|
89
|
+
return ERR_EMPTY;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
buf[total_read] = '\0';
|
|
93
|
+
*out_buf = buf;
|
|
94
|
+
*out_size = total_read;
|
|
95
|
+
return SUCCESS;
|
|
96
|
+
}
|
|
@@ -62,7 +62,8 @@ def test_native_cat_errors(tmp_path):
|
|
|
62
62
|
|
|
63
63
|
def test_native_dir_lists_entries_and_handles_errors(tmp_path):
|
|
64
64
|
(tmp_path / "folder_a").mkdir()
|
|
65
|
-
|
|
65
|
+
file_b = tmp_path / "file_b.txt"
|
|
66
|
+
file_b.write_text("hello", encoding="utf-8")
|
|
66
67
|
code, items = bridge._native.dir(str(tmp_path))
|
|
67
68
|
assert code == 0
|
|
68
69
|
assert ("folder_a", True) in items
|
|
@@ -76,3 +77,25 @@ def test_native_dir_lists_entries_and_handles_errors(tmp_path):
|
|
|
76
77
|
exit_code, msg = cmd.execute([str(tmp_path / "does_not_exist")])
|
|
77
78
|
assert exit_code == 1
|
|
78
79
|
assert "File or path not found" in msg
|
|
80
|
+
exit_code, msg = cmd.execute([str(file_b)])
|
|
81
|
+
assert exit_code == 1
|
|
82
|
+
assert "Target is not a directory" in msg
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_native_unicode_paths(tmp_path):
|
|
86
|
+
unicode_dir = tmp_path / "dir_日本語"
|
|
87
|
+
unicode_dir.mkdir()
|
|
88
|
+
unicode_file = unicode_dir / "café_🚀.txt"
|
|
89
|
+
code, _ = bridge._native.touch(str(unicode_file))
|
|
90
|
+
assert code == 0
|
|
91
|
+
assert unicode_file.exists()
|
|
92
|
+
unicode_file.write_text("héllo 🌍\n", encoding="utf-8", newline="\n")
|
|
93
|
+
code, content = bridge._native.cat(str(unicode_file))
|
|
94
|
+
assert code == 0
|
|
95
|
+
assert content == "héllo 🌍\n"
|
|
96
|
+
code, items = bridge._native.dir(str(tmp_path))
|
|
97
|
+
assert code == 0
|
|
98
|
+
assert ("dir_日本語", True) in items
|
|
99
|
+
code, sub_items = bridge._native.dir(str(unicode_dir))
|
|
100
|
+
assert code == 0
|
|
101
|
+
assert ("café_🚀.txt", False) in sub_items
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// c_src/diskops/posix/cat.c
|
|
2
|
-
|
|
3
|
-
#include "../shared/native_errors.h"
|
|
4
|
-
#include <errno.h>
|
|
5
|
-
#include <fcntl.h>
|
|
6
|
-
#include <stdlib.h>
|
|
7
|
-
#include <sys/stat.h>
|
|
8
|
-
#include <unistd.h>
|
|
9
|
-
|
|
10
|
-
Result cat(const char *path, char **out_buf, size_t *out_size) {
|
|
11
|
-
if (!path || !out_buf || !out_size) {
|
|
12
|
-
return ERR_INVALID_PATH;
|
|
13
|
-
}
|
|
14
|
-
*out_buf = NULL;
|
|
15
|
-
*out_size = 0;
|
|
16
|
-
|
|
17
|
-
int fd = open(path, O_RDONLY);
|
|
18
|
-
if (fd < 0) {
|
|
19
|
-
return map_posix_errno(errno);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
struct stat st;
|
|
23
|
-
if (fstat(fd, &st) < 0) {
|
|
24
|
-
int err = errno;
|
|
25
|
-
close(fd);
|
|
26
|
-
return map_posix_errno(err);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (S_ISDIR(st.st_mode)) {
|
|
30
|
-
close(fd);
|
|
31
|
-
return ERR_IS_DIR;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (st.st_size == 0) {
|
|
35
|
-
close(fd);
|
|
36
|
-
return ERR_EMPTY;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
char *buf = (char *)malloc(st.st_size + 1);
|
|
40
|
-
if (!buf) {
|
|
41
|
-
close(fd);
|
|
42
|
-
return ERR_IO;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
ssize_t n = read(fd, buf, st.st_size);
|
|
46
|
-
int read_err = errno;
|
|
47
|
-
close(fd);
|
|
48
|
-
|
|
49
|
-
if (n < 0) {
|
|
50
|
-
free(buf);
|
|
51
|
-
return map_posix_errno(read_err);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
buf[n] = '\0';
|
|
55
|
-
*out_buf = buf;
|
|
56
|
-
*out_size = (size_t)n;
|
|
57
|
-
return SUCCESS;
|
|
58
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// c_src/diskops/win32/cat.c
|
|
2
|
-
|
|
3
|
-
#include "../shared/native_errors.h"
|
|
4
|
-
#include "../shared/win32_utf.h"
|
|
5
|
-
#include <stdlib.h>
|
|
6
|
-
#include <windows.h>
|
|
7
|
-
|
|
8
|
-
Result cat(const char *path, char **out_buf, size_t *out_size) {
|
|
9
|
-
if (!path || !out_buf || !out_size) {
|
|
10
|
-
return ERR_INVALID_PATH;
|
|
11
|
-
}
|
|
12
|
-
*out_buf = NULL;
|
|
13
|
-
*out_size = 0;
|
|
14
|
-
|
|
15
|
-
wchar_t *wpath = utf8_to_wide(path);
|
|
16
|
-
if (!wpath) {
|
|
17
|
-
return ERR_INVALID_PATH;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
HANDLE hFile =
|
|
21
|
-
CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
22
|
-
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
23
|
-
|
|
24
|
-
if (hFile == INVALID_HANDLE_VALUE) {
|
|
25
|
-
DWORD err = GetLastError();
|
|
26
|
-
if (err == ERROR_ACCESS_DENIED) {
|
|
27
|
-
DWORD attrs = GetFileAttributesW(wpath);
|
|
28
|
-
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
29
|
-
free(wpath);
|
|
30
|
-
return ERR_IS_DIR;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
free(wpath);
|
|
34
|
-
return map_win32_error(err);
|
|
35
|
-
}
|
|
36
|
-
free(wpath);
|
|
37
|
-
|
|
38
|
-
LARGE_INTEGER size;
|
|
39
|
-
if (!GetFileSizeEx(hFile, &size)) {
|
|
40
|
-
DWORD err = GetLastError();
|
|
41
|
-
CloseHandle(hFile);
|
|
42
|
-
return map_win32_error(err);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (size.QuadPart == 0) {
|
|
46
|
-
CloseHandle(hFile);
|
|
47
|
-
return ERR_EMPTY;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
char *buf = (char *)malloc(size.QuadPart + 1);
|
|
51
|
-
if (!buf) {
|
|
52
|
-
CloseHandle(hFile);
|
|
53
|
-
return ERR_IO;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
DWORD bytes_read = 0;
|
|
57
|
-
BOOL ok = ReadFile(hFile, buf, (DWORD)size.QuadPart, &bytes_read, NULL);
|
|
58
|
-
DWORD read_err = GetLastError();
|
|
59
|
-
CloseHandle(hFile);
|
|
60
|
-
|
|
61
|
-
if (!ok) {
|
|
62
|
-
free(buf);
|
|
63
|
-
return map_win32_error(read_err);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
buf[bytes_read] = '\0';
|
|
67
|
-
*out_buf = buf;
|
|
68
|
-
*out_size = (size_t)bytes_read;
|
|
69
|
-
return SUCCESS;
|
|
70
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|