File tree Expand file tree Collapse file tree
source/kernel/C/shell/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 */
1111
1212#include <commands/commands.h>
13+ #include <filesystems/vfs.h>
14+ #include <basics.h>
15+
16+ #define CAT_BUF_SIZE 512
1317
1418int cmd_cat (int argc , char * * argv )
1519{
1620 if (argc < 2 ) {
1721 printf ("cat: missing file operand" );
1822 return 1 ;
1923 }
20-
21- printf ("%s" , read_file (global_fs , argv [1 ]));
2224
25+ uint8_t buf [CAT_BUF_SIZE ];
26+
27+ for (int i = 1 ; i < argc ; i ++ ) {
28+ vfs_file_t file ;
29+
30+ /* Open file */
31+ if (vfs_open (argv [i ], & file ) != 0 ) {
32+ printf ("cat: %s: No such file or directory\n" , argv [i ]);
33+ continue ;
34+ }
35+
36+ /* Read loop */
37+ while (1 ) {
38+ int r = vfs_read (& file , buf , CAT_BUF_SIZE );
39+ if (r < 0 ) {
40+ printf ("cat: %s: read error" , argv [i ]);
41+ break ;
42+ }
43+
44+ if (r == 0 )
45+ break ; /* EOF */
46+
47+ for (int j = 0 ; j < r ; j ++ )
48+ printfnoln ("%c" , buf [j ]);
49+ }
50+
51+ vfs_close (& file );
52+ }
53+
54+ print ("\n" );
2355 return 0 ;
2456}
You can’t perform that action at this time.
0 commit comments