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

Function dfs_normalize_path

components/dfs/dfs_v1/src/dfs.c:750–883  ·  view source on GitHub ↗

* this function will normalize a path according to specified parent directory * and file name. * * @param directory the parent path * @param filename the file name * * @return the built full file path (absolute path) */

Source from the content-addressed store, hash-verified

748 * @return the built full file path (absolute path)
749 */
750char *dfs_normalize_path(const char *directory, const char *filename)
751{
752 char *fullpath;
753 char *dst0, *dst, *src;
754
755 /* check parameters */
756 RT_ASSERT(filename != NULL);
757
758#ifdef DFS_USING_WORKDIR
759 if (directory == NULL) /* shall use working directory */
760 {
761#ifdef RT_USING_SMART
762 directory = lwp_getcwd();
763#else
764 directory = &working_directory[0];
765#endif
766 }
767#else
768 if ((directory == NULL) && (filename[0] != '/'))
769 {
770 rt_kprintf(NO_WORKING_DIR);
771
772 return NULL;
773 }
774#endif
775
776 if (filename[0] != '/') /* it's a absolute path, use it directly */
777 {
778 fullpath = (char *)rt_malloc(strlen(directory) + strlen(filename) + 2);
779
780 if (fullpath == NULL)
781 return NULL;
782
783 /* join path and file name */
784 rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2,
785 "%s/%s", directory, filename);
786 }
787 else
788 {
789 fullpath = rt_strdup(filename); /* copy string */
790
791 if (fullpath == NULL)
792 return NULL;
793 }
794
795 src = fullpath;
796 dst = fullpath;
797
798 dst0 = dst;
799 while (1)
800 {
801 char c = *src;
802
803 if (c == '.')
804 {
805 if (!src[1]) src++; /* '.' and ends */
806 else if (src[1] == '/')
807 {

Callers 15

openatFunction · 0.70
chdirFunction · 0.70
fd_is_openFunction · 0.70
dfs_file_is_openFunction · 0.70
dfs_file_openFunction · 0.70
dfs_file_unlinkFunction · 0.70
dfs_file_statFunction · 0.70
dfs_file_renameFunction · 0.70
lsFunction · 0.70
copydirFunction · 0.70
copyFunction · 0.70
dfs_mountFunction · 0.70

Calls 6

lwp_getcwdFunction · 0.85
rt_kprintfFunction · 0.85
rt_mallocFunction · 0.85
rt_snprintfFunction · 0.85
rt_strdupFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected