Changeset d96d9bc in mainline
- Timestamp:
- 2017-04-02T20:38:50Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c23275a
- Parents:
- 1e2e5795
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/builtins/cd/cd.c
r1e2e5795 rd96d9bc 29 29 #include <stdio.h> 30 30 #include <stdlib.h> 31 #include <unistd.h>32 31 #include <str.h> 33 32 #include <errno.h> 33 #include <vfs/vfs.h> 34 34 35 35 #include "util.h" … … 51 51 static bool previous_directory_set = false; 52 52 53 static int chdir_and_remember(const char *new_dir) { 53 static int chdir_and_remember(const char *new_dir) 54 { 54 55 55 char *ok = getcwd(previous_directory_tmp, PATH_MAX);56 previous_directory_valid = ok != NULL;56 int rc = vfs_cwd_get(previous_directory_tmp, PATH_MAX); 57 previous_directory_valid = (rc == EOK); 57 58 previous_directory_set = true; 58 59 59 if (chdir(new_dir) != 0) 60 return errno; 60 rc = vfs_cwd_set(new_dir); 61 if (rc != EOK) 62 return rc; 61 63 62 64 str_cpy(previous_directory, PATH_MAX, previous_directory_tmp); -
uspace/app/bdsh/cmds/modules/ls/ls.c
r1e2e5795 rd96d9bc 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 #include <unistd.h>37 36 #include <dirent.h> 38 37 #include <getopt.h> … … 387 386 388 387 if (argc == 0) { 389 if ( getcwd(de.name, PATH_MAX) == NULL) {388 if (vfs_cwd_get(de.name, PATH_MAX) != EOK) { 390 389 cli_error(CL_EFAIL, "%s: Failed determining working " 391 390 "directory", cmdname); -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
r1e2e5795 rd96d9bc 208 208 209 209 if (follow && (argv[optind] != NULL)) { 210 if ( chdir(argv[optind]) != 0)210 if (vfs_cwd_set(argv[optind]) != EOK) 211 211 printf("%s: Error switching to directory.", cmdname); 212 212 } -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
r1e2e5795 rd96d9bc 30 30 #include <stdlib.h> 31 31 #include <mem.h> 32 #include <vfs/vfs.h> 33 #include <abi/errno.h> 32 34 33 35 #include "config.h" … … 57 59 memset(buff, 0, PATH_MAX); 58 60 59 if ( getcwd(buff, PATH_MAX) == NULL) {61 if (vfs_cwd_get(buff, PATH_MAX) != EOK) { 60 62 cli_error(CL_EFAIL, 61 63 "Unable to determine the current working directory"); -
uspace/app/bdsh/cmds/modules/rm/rm.c
r1e2e5795 rd96d9bc 30 30 #include <stdio.h> 31 31 #include <stdlib.h> 32 #include <unistd.h>33 32 #include <dirent.h> 34 33 #include <getopt.h> … … 110 109 memset(rm->cwd, 0, PATH_MAX); 111 110 112 chdir(".");113 114 if ( NULL == (getcwd(rm->owd, PATH_MAX)))111 vfs_cwd_set("."); 112 113 if (EOK != vfs_cwd_get(rm->owd, PATH_MAX)) 115 114 return 0; 116 115 -
uspace/app/bdsh/util.c
r1e2e5795 rd96d9bc 31 31 #include <stdarg.h> 32 32 #include <stdlib.h> 33 #include <vfs/vfs.h> 34 #include <abi/errno.h> 33 35 34 36 #include "config.h" … … 58 60 return 1; 59 61 } 60 if ( !getcwd(usr->cwd, PATH_MAX))62 if (vfs_cwd_get(usr->cwd, PATH_MAX) != EOK) 61 63 snprintf(usr->cwd, PATH_MAX, "(unknown)"); 62 64 -
uspace/lib/c/generic/libc.c
r1e2e5795 rd96d9bc 116 116 __stdio_init(); 117 117 vfs_root_set(inbox_get("root")); 118 (void) chdir(__pcb->cwd);118 (void) vfs_cwd_set(__pcb->cwd); 119 119 } 120 120 -
uspace/lib/c/generic/loader.c
r1e2e5795 rd96d9bc 124 124 return ENOMEM; 125 125 126 if ( getcwd(cwd, MAX_PATH_LEN + 1) == NULL)126 if (vfs_cwd_get(cwd, MAX_PATH_LEN + 1) != EOK) 127 127 str_cpy(cwd, MAX_PATH_LEN + 1, "/"); 128 128 -
uspace/lib/c/generic/vfs/vfs.c
r1e2e5795 rd96d9bc 808 808 * 809 809 * @param path Path 810 * @return 0 on success. On error returns -1 and sets errno.811 */ 812 int chdir(const char *path)810 * @return EOK on success or a negative error code otherwise. 811 */ 812 int vfs_cwd_set(const char *path) 813 813 { 814 814 size_t abs_size; 815 815 char *abs = vfs_absolutize(path, &abs_size); 816 if (!abs) { 817 errno = ENOMEM; 818 return -1; 819 } 816 if (!abs) 817 return ENOMEM; 820 818 821 819 int fd = vfs_lookup(abs, WALK_DIRECTORY); 822 820 if (fd < 0) { 823 821 free(abs); 824 errno = fd; 825 return -1; 822 return fd; 826 823 } 827 824 … … 839 836 840 837 fibril_mutex_unlock(&cwd_mutex); 841 return 0;838 return EOK; 842 839 } 843 840 … … 846 843 * @param buf Buffer 847 844 * @param size Size of @a buf 848 * @return On success returns @a buf. On failure returns @c NULL and sets errno. 849 */ 850 char *getcwd(char *buf, size_t size) 851 { 852 if (size == 0) { 853 errno = EINVAL; 854 return NULL; 855 } 856 845 * @return EOK on success and a non-negative error code otherwise. 846 */ 847 int vfs_cwd_get(char *buf, size_t size) 848 { 857 849 fibril_mutex_lock(&cwd_mutex); 858 850 859 851 if ((cwd_size == 0) || (size < cwd_size + 1)) { 860 852 fibril_mutex_unlock(&cwd_mutex); 861 errno = ERANGE; 862 return NULL; 853 return ERANGE; 863 854 } 864 855 … … 866 857 fibril_mutex_unlock(&cwd_mutex); 867 858 868 return buf;859 return EOK; 869 860 } 870 861 -
uspace/lib/c/include/unistd.h
r1e2e5795 rd96d9bc 58 58 #define getpagesize() (PAGE_SIZE) 59 59 60 extern char *getcwd(char *, size_t);61 extern int chdir(const char *);62 63 60 extern void exit(int) __attribute__((noreturn)); 64 61 extern int usleep(useconds_t); -
uspace/lib/c/include/vfs/vfs.h
r1e2e5795 rd96d9bc 74 74 75 75 extern char *vfs_absolutize(const char *, size_t *); 76 extern int vfs_cwd_set(const char *path); 77 extern int vfs_cwd_get(char *path, size_t); 76 78 77 79 extern int vfs_fhandle(FILE *, int *); -
uspace/lib/posix/source/unistd.c
r1e2e5795 rd96d9bc 108 108 char *posix_getcwd(char *buf, size_t size) 109 109 { 110 char *p = getcwd(buf, size); 111 112 if (p == NULL) { 113 errno = -errno; 110 int rc = rcerrno(vfs_cwd_get, buf, size); 111 if (rc != EOK) 114 112 return NULL; 115 } 116 117 return p; 113 return buf; 118 114 } 119 115 … … 125 121 int posix_chdir(const char *path) 126 122 { 127 return negerrno(chdir, path); 123 int rc = rcerrno(vfs_cwd_set, path); 124 if (rc != EOK) 125 return -1; 126 return 0; 128 127 } 129 128
Note:
See TracChangeset
for help on using the changeset viewer.