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

Function cat

components/dfs/dfs_v2/src/dfs_file.c:2711–2749  ·  view source on GitHub ↗

* @brief Display file contents to standard output * * This function reads and prints the contents of the specified file to the console. * It handles both text and binary files by reading in chunks and printing the output. * * @param[in] filename Path to the file to be displayed */

Source from the content-addressed store, hash-verified

2709 * @param[in] filename Path to the file to be displayed
2710 */
2711void cat(const char *filename)
2712{
2713 int length = 0;
2714 char buffer[81];
2715 struct dfs_file file;
2716
2717 if (filename && dfs_file_isdir(filename) == 0)
2718 {
2719 rt_kprintf("cat: %s Is a directory\n", filename);
2720 return;
2721 }
2722
2723 dfs_file_init(&file);
2724
2725 DLOG(msg, "dfs", "dfs_file", DLOG_MSG, "dfs_file_open(%s, O_RDONLY, 0)", filename);
2726 if (dfs_file_open(&file, filename, O_RDONLY, 0) < 0)
2727 {
2728 rt_kprintf("Open %s failed\n", filename);
2729 dfs_file_deinit(&file);
2730 return;
2731 }
2732
2733 do
2734 {
2735 rt_memset(buffer, 0x0, sizeof(buffer));
2736 DLOG(msg, "dfs", "dfs_file", DLOG_MSG, "dfs_file_read(fd, buffer, %d)", sizeof(buffer) - 1);
2737 length = dfs_file_read(&file, (void *)buffer, sizeof(buffer) - 1);
2738 if (length > 0)
2739 {
2740 buffer[length] = '\0';
2741 rt_kprintf("%s", buffer);
2742 }
2743 } while (length > 0);
2744 rt_kprintf("\n");
2745
2746 DLOG(msg, "dfs", "dfs_file", DLOG_MSG, "dfs_file_close()");
2747 dfs_file_close(&file);
2748 dfs_file_deinit(&file);
2749}
2750
2751#define BUF_SZ 4096
2752/**

Callers

nothing calls this directly

Calls 8

dfs_file_isdirFunction · 0.85
rt_kprintfFunction · 0.85
dfs_file_initFunction · 0.85
dfs_file_deinitFunction · 0.85
rt_memsetFunction · 0.85
dfs_file_openFunction · 0.70
dfs_file_readFunction · 0.70
dfs_file_closeFunction · 0.70

Tested by

no test coverage detected