Changeset 6c69d19 in mainline for uspace/app/bdsh/exec.c


Ignore:
Timestamp:
2011-07-25T20:34:17Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00c2de63, c936c7f
Parents:
5889fc74 (diff), d542aad (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    r5889fc74 r6c69d19  
    5252static int try_access(const char *);
    5353
     54const char *search_dir[] = { "app", "srv", NULL };
     55
    5456/* work-around for access() */
    5557static int try_access(const char *f)
     
    6971static char *find_command(char *cmd)
    7072{
    71         char *path_tok;
    72         char *path[PATH_MAX];
    73         int n = 0, i = 0;
    74         size_t x = str_size(cmd) + 2;
     73        size_t i;
    7574
    7675        found = (char *)malloc(PATH_MAX);
     
    8180        }
    8281
    83         path_tok = str_dup(PATH);
    84 
    85         /* Extract the PATH env to a path[] array */
    86         path[n] = strtok(path_tok, PATH_DELIM);
    87         while (NULL != path[n]) {
    88                 if ((str_size(path[n]) + x ) > PATH_MAX) {
    89                         cli_error(CL_ENOTSUP,
    90                                 "Segment %d of path is too large, search ends at segment %d",
    91                                 n, n-1);
    92                         break;
    93                 }
    94                 path[++n] = strtok(NULL, PATH_DELIM);
    95         }
    96 
    9782        /* We now have n places to look for the command */
    98         for (i=0; path[i]; i++) {
     83        for (i = 0; search_dir[i] != NULL; i++) {
    9984                memset(found, 0, sizeof(found));
    100                 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);
     85                snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd);
    10186                if (-1 != try_access(found)) {
    102                         free(path_tok);
    10387                        return (char *) found;
    10488                }
     
    10690
    10791        /* We didn't find it, just give it back as-is. */
    108         free(path_tok);
    10992        return (char *) cmd;
    11093}
Note: See TracChangeset for help on using the changeset viewer.