Ignore:
Timestamp:
2012-04-07T17:08:06Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
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)
Message:

Change to previous directory with `cd -' in bdsh

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    r85d2fe2e r089385e8  
    6363        argc = cli_count_args(argv);
    6464
     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
    6574        /* We don't yet play nice with whitespace, a getopt implementation should
    6675         * protect "quoted\ destination" as a single argument. Its not our job to
     
    7988        }
    8089
    81         /* We have the correct # of arguments
    82      * TODO: handle tidle (~) expansion? */
     90        /* We have the correct # of arguments */
     91        // TODO: handle tidle (~) expansion? */
    8392
    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        }
    85118
    86119        if (rc == 0) {
Note: See TracChangeset for help on using the changeset viewer.