5 #include "system_dependencies.h"
12 command_cat(int argc
, const char* const* argv
)
16 if (argc
< 2 || strcmp(argv
[1], "--help") == 0) {
18 "Usage: %s [ -n ] [FILE]...\n"
19 "\t -n\tNumber of bytes to read\n",
25 if (argc
> 3 && strcmp(argv
[1], "-n") == 0) {
27 numBytes
= strtol(argv
[2], NULL
, 10);
30 const char* const* files
= argv
+ fileStart
;
31 for (; *files
; files
++) {
32 const char* file
= *files
;
33 int fd
= _kern_open(-1, file
, O_RDONLY
, O_RDONLY
);
35 fssh_dprintf("Error: %s\n", fssh_strerror(fd
));
36 return FSSH_B_BAD_VALUE
;
39 char buffer
[numBytes
+ 1];
41 fssh_dprintf("Error: No memory\n");
43 return FSSH_B_NO_MEMORY
;
46 if (_kern_read(fd
, 0, buffer
, numBytes
) != numBytes
) {
47 fssh_dprintf("Error: fail to read, length: %i\n", numBytes
);
49 return FSSH_B_BAD_VALUE
;
53 buffer
[numBytes
] = '\0';
54 printf("%s\n", buffer
);
61 } // namespace FSShell