diff --git a/fs/dirent/fs_opendir.c b/fs/dirent/fs_opendir.c index 9082aa48c0..687cc12b7e 100644 --- a/fs/dirent/fs_opendir.c +++ b/fs/dirent/fs_opendir.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -217,52 +216,8 @@ FAR DIR *opendir(FAR const char *path) #ifndef CONFIG_DISABLE_MOUNTPOINT FAR const char *relpath = NULL; #endif - FAR char *alloc = NULL; - int len; int ret; - /* Strip off any trailing whitespace or '/' characters. In this case we - * must make a copy of the user string so we can chop off bytes on the - * 'right' without modifying the user's const string. - */ - - if (path != NULL) - { - /* Length of the string excludes NUL terminator */ - - len = strlen(path); - - /* Check for whitespace or a dangling '/' at the end of the string. - * But don't muck with the string any further if it has been reduced - * to "/" - */ - - while (len > 0 && strcmp(path, "/") != 0 && - (isspace(path[len - 1]) || path[len - 1] == '/')) - { - /* Have we already allocated memory for the modified string? */ - - if (alloc == NULL) - { - alloc = strdup(path); /* Allocates one too many bytes */ - if (alloc == NULL) - { - ret = ENOMEM; - goto errout; - } - - /* Use the cloned, writable string instead of the user string */ - - path = alloc; - } - - /* Chop off the final character */ - - len--; - alloc[len] = '\0'; - } - } - /* If we are given 'nothing' then we will interpret this as * request for the root inode. */ @@ -273,7 +228,7 @@ FAR DIR *opendir(FAR const char *path) if (ret < 0) { ret = -ret; - goto errout_with_alloc; + goto errout; } /* We don't know what to do with relative paths */ @@ -375,14 +330,6 @@ FAR DIR *opendir(FAR const char *path) RELEASE_SEARCH(&desc); inode_semgive(); - - /* Free any allocated string memory */ - - if (alloc != NULL) - { - kmm_free(alloc); - } - return ((FAR DIR *)dir); /* Nasty goto's make error handling simpler */ @@ -394,15 +341,6 @@ errout_with_semaphore: RELEASE_SEARCH(&desc); inode_semgive(); -errout_with_alloc: - - /* Free any allocated string memory */ - - if (alloc != NULL) - { - kmm_free(alloc); - } - errout: set_errno(ret); return NULL;