Changeset 089385e8 in mainline
- Timestamp:
- 2012-04-07T17:08:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2662a1e9
- Parents:
- 85d2fe2e
- git-author:
- Ketan Singh <> (2012-04-07 17:08:06)
- git-committer:
- Vojtech Horky <vojtechhorky@…> (2012-04-07 17:08:06)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/app/bdsh/cmds/builtins/cd/cd.c ¶
r85d2fe2e r089385e8 63 63 argc = cli_count_args(argv); 64 64 65 /* Handle cd -- -. Override to switch to a directory named '-' */ 66 bool hyphen_override = false; 67 if (argc == 3) { 68 if(!str_cmp(argv[1], "--")) { 69 hyphen_override = true; 70 argc--; 71 } 72 } 73 65 74 /* We don't yet play nice with whitespace, a getopt implementation should 66 75 * protect "quoted\ destination" as a single argument. Its not our job to … … 79 88 } 80 89 81 /* We have the correct # of arguments 82 *TODO: handle tidle (~) expansion? */90 /* We have the correct # of arguments */ 91 // TODO: handle tidle (~) expansion? */ 83 92 84 rc = chdir(argv[1]); 93 /* Handle 'cd -' first. */ 94 if (!str_cmp(argv[1], "-") && !hyphen_override) { 95 char *buffer = (char *) malloc(PATH_MAX); 96 if (!buffer) { 97 cli_error(CL_ENOMEM, "Cannot switch to previous directory"); 98 return CMD_FAILURE; 99 } 100 memset(buffer, 0, PATH_MAX); 101 getprevwd(buffer, PATH_MAX); 102 if (*buffer == '\0') { 103 cli_error(CL_EFAIL, "No previous directory to switch to"); 104 free(buffer); 105 return CMD_FAILURE; 106 } else { 107 rc = chdir(buffer); 108 free(buffer); 109 } 110 } else if (hyphen_override) { 111 /* Handles 'cd -- <dirname>'. 112 * Override for directory named '-'. 113 */ 114 rc = chdir(argv[2]); 115 } else { 116 rc = chdir(argv[1]); 117 } 85 118 86 119 if (rc == 0) { -
TabularUnified uspace/lib/c/generic/vfs/vfs.c ¶
r85d2fe2e r089385e8 58 58 static async_sess_t *vfs_sess = NULL; 59 59 60 /* Current (working) directory. */ 60 61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); 61 62 62 static int cwd_fd = -1; 63 63 static char *cwd_path = NULL; 64 64 static size_t cwd_size = 0; 65 66 /* Previous directory. */ 67 static FIBRIL_MUTEX_INITIALIZE(pwd_mutex); 68 static int pwd_fd = -1; 69 static char *pwd_path = NULL; 70 static size_t pwd_size = 0; 71 65 72 66 73 /** Start an async exchange on the VFS session. … … 751 758 fibril_mutex_lock(&cwd_mutex); 752 759 753 if (cwd_fd >= 0) 754 close(cwd_fd); 755 756 757 if (cwd_path) 758 free(cwd_path); 759 760 761 fibril_mutex_lock(&pwd_mutex); 762 763 if (pwd_fd >= 0) 764 close(pwd_fd); 765 766 767 if (pwd_path) 768 free(pwd_path); 769 770 771 pwd_fd = cwd_fd; 772 pwd_path = cwd_path; 773 pwd_size = cwd_size; 774 775 fibril_mutex_unlock(&pwd_mutex); 776 760 777 cwd_fd = fd; 761 778 cwd_path = abs; … … 781 798 fibril_mutex_unlock(&cwd_mutex); 782 799 800 return buf; 801 } 802 803 804 char *getprevwd(char *buf, size_t size) 805 { 806 if (size == 0) 807 return NULL; 808 809 fibril_mutex_lock(&pwd_mutex); 810 811 if ((pwd_size == 0) || (size < pwd_size + 1)) { 812 fibril_mutex_unlock(&pwd_mutex); 813 return NULL; 814 } 815 816 str_cpy(buf, size, pwd_path); 817 fibril_mutex_unlock(&pwd_mutex); 818 783 819 return buf; 784 820 } -
TabularUnified uspace/lib/c/include/unistd.h ¶
r85d2fe2e r089385e8 74 74 75 75 extern char *getcwd(char *buf, size_t); 76 extern char *getprevwd(char *, size_t); 76 77 extern int rmdir(const char *); 77 78 extern int chdir(const char *);
Note:
See TracChangeset
for help on using the changeset viewer.