mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-27 13:44:01 +00:00
wav支持2
This commit is contained in:
@@ -3,10 +3,8 @@
|
||||
|
||||
static int ush_cmd_cat(const ush_state *sh, const char *arg) {
|
||||
char path[USH_PATH_MAX];
|
||||
char buf[USH_CAT_MAX + 1ULL];
|
||||
u64 size;
|
||||
u64 req;
|
||||
u64 got;
|
||||
char buf[1024];
|
||||
u64 fd;
|
||||
|
||||
if (arg == (const char *)0 || arg[0] == '\0') {
|
||||
if (ush_pipeline_stdin_text != (const char *)0 && ush_pipeline_stdin_len > 0ULL) {
|
||||
@@ -28,36 +26,38 @@ static int ush_cmd_cat(const ush_state *sh, const char *arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = cleonos_sys_fs_stat_size(path);
|
||||
|
||||
if (size == (u64)-1) {
|
||||
(void)puts("cat: failed to stat file");
|
||||
fd = cleonos_sys_fd_open(path, CLEONOS_O_RDONLY, 0ULL);
|
||||
if (fd == (u64)-1) {
|
||||
(void)puts("cat: open failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size == 0ULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
req = (size < USH_CAT_MAX) ? size : USH_CAT_MAX;
|
||||
got = cleonos_sys_fs_read(path, buf, req);
|
||||
|
||||
if (got == 0ULL) {
|
||||
(void)puts("cat: read failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (got > USH_CAT_MAX) {
|
||||
got = USH_CAT_MAX;
|
||||
}
|
||||
|
||||
buf[got] = '\0';
|
||||
(void)puts(buf);
|
||||
|
||||
if (size > got) {
|
||||
(void)puts("[cat] output truncated");
|
||||
for (;;) {
|
||||
u64 got = cleonos_sys_fd_read(fd, buf, (u64)sizeof(buf));
|
||||
u64 written_total = 0ULL;
|
||||
|
||||
if (got == (u64)-1) {
|
||||
(void)cleonos_sys_fd_close(fd);
|
||||
(void)puts("cat: read failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (got == 0ULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (written_total < got) {
|
||||
u64 written = cleonos_sys_fd_write(1ULL, buf + written_total, got - written_total);
|
||||
if (written == (u64)-1 || written == 0ULL) {
|
||||
(void)cleonos_sys_fd_close(fd);
|
||||
(void)puts("cat: write failed");
|
||||
return 0;
|
||||
}
|
||||
written_total += written;
|
||||
}
|
||||
}
|
||||
|
||||
(void)cleonos_sys_fd_close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user