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

Function copyfile

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

Source from the content-addressed store, hash-verified

898#ifdef DFS_USING_POSIX
899#define BUF_SZ 4096
900static void copyfile(const char *src, const char *dst)
901{
902 struct dfs_file fd;
903 struct dfs_file src_fd;
904 rt_uint8_t *block_ptr;
905 rt_int32_t read_bytes;
906
907 block_ptr = (rt_uint8_t *)rt_malloc(BUF_SZ);
908 if (block_ptr == NULL)
909 {
910 rt_kprintf("out of memory\n");
911
912 return;
913 }
914
915 fd_init(&src_fd);
916 if (dfs_file_open(&src_fd, src, O_RDONLY) < 0)
917 {
918 rt_free(block_ptr);
919 rt_kprintf("Read %s failed\n", src);
920
921 return;
922 }
923 fd_init(&fd);
924 if (dfs_file_open(&fd, dst, O_WRONLY | O_CREAT | O_TRUNC) < 0)
925 {
926 rt_free(block_ptr);
927 dfs_file_close(&src_fd);
928
929 rt_kprintf("Write %s failed\n", dst);
930
931 return;
932 }
933
934 do
935 {
936 read_bytes = dfs_file_read(&src_fd, block_ptr, BUF_SZ);
937 if (read_bytes > 0)
938 {
939 int length;
940
941 length = dfs_file_write(&fd, block_ptr, read_bytes);
942 if (length != read_bytes)
943 {
944 /* write failed. */
945 rt_kprintf("Write file data failed, errno=%d\n", length);
946 break;
947 }
948 }
949 }
950 while (read_bytes > 0);
951
952 dfs_file_close(&src_fd);
953 dfs_file_close(&fd);
954 rt_free(block_ptr);
955}
956
957extern int mkdir(const char *path, mode_t mode);

Callers 2

copydirFunction · 0.70
copyFunction · 0.70

Calls 8

rt_mallocFunction · 0.85
rt_kprintfFunction · 0.85
fd_initFunction · 0.85
rt_freeFunction · 0.85
dfs_file_openFunction · 0.70
dfs_file_closeFunction · 0.70
dfs_file_readFunction · 0.70
dfs_file_writeFunction · 0.70

Tested by

no test coverage detected