Rev 3346 | Rev 3372 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3346 | Rev 3366 | ||
---|---|---|---|
Line 63... | Line 63... | ||
63 | 63 | ||
64 | /* Returns the full path of "cmd" if cmd is found, else just hand back |
64 | /* Returns the full path of "cmd" if cmd is found, else just hand back |
65 | * cmd as it was presented */ |
65 | * cmd as it was presented */ |
66 | char *find_command(char *cmd) |
66 | char *find_command(char *cmd) |
67 | { |
67 | { |
68 | char *path_orig, *path_tok; |
68 | char *path_tok; |
69 | char *path[PATH_MAX]; |
69 | char *path[PATH_MAX]; |
70 | int n = 0, i = 0; |
70 | int n = 0, i = 0; |
71 | size_t x = strlen(cmd) + 2; |
71 | size_t x = strlen(cmd) + 2; |
72 | 72 | ||
73 | found = (char *)malloc(PATH_MAX); |
73 | found = (char *)malloc(PATH_MAX); |
74 | 74 | ||
75 | /* The user has specified a full or relative path, just give it back. */ |
75 | /* The user has specified a full or relative path, just give it back. */ |
76 | if (-1 != try_access(cmd)) { |
76 | if (-1 != try_access(cmd)) { |
77 | return (char *) cmd; |
77 | return (char *) cmd; |
78 | } |
78 | } |
79 | path_orig = PATH; |
- | |
- | 79 | ||
80 | path_tok = cli_strdup(path_orig); |
80 | path_tok = cli_strdup(PATH); |
81 | 81 | ||
82 | /* Extract the PATH env to a path[] array */ |
82 | /* Extract the PATH env to a path[] array */ |
83 | path[n] = cli_strtok(path_tok, PATH_DELIM); |
83 | path[n] = cli_strtok(path_tok, PATH_DELIM); |
84 | while (NULL != path[n]) { |
84 | while (NULL != path[n]) { |
85 | if ((strlen(path[n]) + x ) > PATH_MAX) { |
85 | if ((strlen(path[n]) + x ) > PATH_MAX) { |