MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / cat

Function cat

components/dfs/dfs_v1/src/dfs_file.c:867–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

865FINSH_FUNCTION_EXPORT(rm, remove files or directories);
866
867void cat(const char *filename)
868{
869 struct dfs_file fd;
870 int length = 0;
871 char buffer[81];
872
873 fd_init(&fd);
874 if (dfs_file_open(&fd, filename, O_RDONLY) < 0)
875 {
876 rt_kprintf("Open %s failed\n", filename);
877
878 return;
879 }
880
881 do
882 {
883 rt_memset(buffer, 0x0, sizeof(buffer));
884 length = dfs_file_read(&fd, (void *)buffer, sizeof(buffer) - 1);
885 if (length > 0)
886 {
887 buffer[length] = '\0';
888 rt_device_t out_device = rt_console_get_device();
889 rt_device_write(out_device, 0, (void *)buffer, length);
890 }
891 } while (length > 0);
892 rt_kprintf("\n");
893
894 dfs_file_close(&fd);
895}
896FINSH_FUNCTION_EXPORT(cat, print file);
897
898#ifdef DFS_USING_POSIX

Callers 1

cmd_catFunction · 0.50

Calls 8

fd_initFunction · 0.85
rt_kprintfFunction · 0.85
rt_memsetFunction · 0.85
rt_console_get_deviceFunction · 0.85
rt_device_writeFunction · 0.85
dfs_file_openFunction · 0.70
dfs_file_readFunction · 0.70
dfs_file_closeFunction · 0.70

Tested by

no test coverage detected