47#define TEMP_PATH_MAX (PATH_MAX + SHOW_MAX_LEN)
49#define TEMP_PATH_MAX PATH_MAX
52static unsigned int vfs_strnlen(
const char *str,
size_t maxlen)
56 for (p = str; ((maxlen-- != 0) && (*p !=
'\0')); ++p) {}
68 while (*src !=
'\0') {
84 if ((*dest ==
'.') && (*(dest - 1) ==
'/')) {
88 if ((dest != fullpath) && (*dest ==
'/')) {
95 char *dest = fullpath;
100 while (*src !=
'\0') {
102 if (*(src + 1) ==
'/') {
105 }
else if (*(src + 1) ==
'.') {
106 if ((*(src + 2) ==
'/') || (*(src + 2) ==
'\0')) {
109 while ((*src !=
'\0') && (*src !=
'/')) {
123 if ((dest - 1) != fullpath) {
127 while ((dest > fullpath) && (*(dest - 1) !=
'/')) {
151 if (pathname == NULL) {
157 if (filename == NULL) {
166 }
else if (namelen >= PATH_MAX) {
168 return -ENAMETOOLONG;
171 for (name = (
char *)filename + namelen; ((name != filename) && (*name !=
'/')); name--) {
172 if (strlen(name) > NAME_MAX) {
174 return -ENAMETOOLONG;
184 char *fullpath = NULL;
188 if ((namelen > 1) && (filename[0] ==
'.') && (filename[1] ==
'/')) {
192 fullpath = (
char *)
malloc(strlen(directory) + namelen + 2);
193 if (fullpath == NULL) {
201 ret = snprintf_s(fullpath, strlen(directory) + namelen + 2, strlen(directory) + namelen + 1,
202 "%s/%s", directory, filename);
206 set_errno(ENAMETOOLONG);
215 char *fullpath = NULL;
217 if (filename[0] !=
'/') {
221 if (fullpath == NULL) {
227 fullpath = strdup(filename);
229 if (fullpath == NULL) {
234 if (filename[1] ==
'/') {
247 char *fullpath = NULL;
249#ifdef VFS_USING_WORKDIR
252 BOOL dir_flags = (directory == NULL) ? TRUE : FALSE;
260#ifdef VFS_USING_WORKDIR
261 if (directory == NULL)
267 if ((directory == NULL) && (filename[0] !=
'/')) {
268 PRINT_ERR(
"NO_WORKING_DIR\n");
276 if ((filename[0] !=
'/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) {
277#ifdef VFS_USING_WORKDIR
278 if (dir_flags == TRUE)
283 return -ENAMETOOLONG;
287#ifdef VFS_USING_WORKDIR
288 if (dir_flags == TRUE)
293 if (fullpath == NULL) {
299 if (strlen(fullpath) >= PATH_MAX) {
302 return -ENAMETOOLONG;
305 *pathname = fullpath;
312 char *relativeoldpath = NULL;
313 char *fullpath = NULL;
316 ret = get_path_from_fd(dirfd, &relativeoldpath);
322 if (relativeoldpath) {
323 free(relativeoldpath);
330 *pathname = fullpath;
static char * vfs_not_absolute_path(const char *directory, const char *filename, char **pathname, int namelen)
static void str_remove_path_end_slash(char *dest, const char *fullpath)
static char * vfs_normalize_fullpath(const char *directory, const char *filename, char **pathname, int namelen)
static char * str_path(char *path)
static unsigned int vfs_strnlen(const char *str, size_t maxlen)
static char * str_normalize_path(char *fullpath)
int vfs_normalize_path(const char *directory, const char *filename, char **pathname)
int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname)
static int vfs_normalize_path_parame_check(const char *filename, char **pathname)
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
void * malloc(size_t size)
动态分配内存块大小
void free(void *ptr)
释放ptr所指向的内存空间
struct files_struct * files
spinlock_t workdir_lock
工作区目录自旋锁
char workdir[PATH_MAX]
工作区路径,最大 256个字符
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void