Rev 3813 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3813 | Rev 4648 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | /* (re)allocates memory to store the current working directory, gets |
51 | /* (re)allocates memory to store the current working directory, gets |
52 | * and updates the current working directory, formats the prompt |
52 | * and updates the current working directory, formats the prompt |
53 | * string */ |
53 | * string */ |
54 | unsigned int cli_set_prompt(cliuser_t *usr) |
54 | unsigned int cli_set_prompt(cliuser_t *usr) |
55 | { |
55 | { |
56 | usr->prompt = (char *) realloc(usr->prompt, PATH_MAX); |
- | |
57 | if (NULL == usr->prompt) { |
- | |
58 | cli_error(CL_ENOMEM, "Can not allocate prompt"); |
- | |
59 | cli_errno = CL_ENOMEM; |
- | |
60 | return 1; |
- | |
61 | } |
- | |
62 | memset(usr->prompt, 0, sizeof(usr->prompt)); |
- | |
63 | - | ||
64 | usr->cwd = (char *) realloc(usr->cwd, PATH_MAX); |
56 | usr->cwd = (char *) realloc(usr->cwd, PATH_MAX); |
65 | if (NULL == usr->cwd) { |
57 | if (NULL == usr->cwd) { |
66 | cli_error(CL_ENOMEM, "Can not allocate cwd"); |
58 | cli_error(CL_ENOMEM, "Can not allocate cwd"); |
67 | cli_errno = CL_ENOMEM; |
59 | cli_errno = CL_ENOMEM; |
68 | return 1; |
60 | return 1; |
69 | } |
61 | } |
70 | memset(usr->cwd, 0, sizeof(usr->cwd)); |
- | |
71 | - | ||
72 | usr->cwd = getcwd(usr->cwd, PATH_MAX - 1); |
62 | if (!getcwd(usr->cwd, PATH_MAX)) |
73 | - | ||
74 | if (NULL == usr->cwd) |
- | |
75 | snprintf(usr->cwd, PATH_MAX, "(unknown)"); |
63 | snprintf(usr->cwd, PATH_MAX, "(unknown)"); |
76 | 64 | ||
- | 65 | if (usr->prompt) |
|
- | 66 | free(usr->prompt); |
|
77 | asprintf(&usr->prompt, "%s # ", usr->cwd); |
67 | asprintf(&usr->prompt, "%s # ", usr->cwd); |
78 | 68 | ||
79 | return 0; |
69 | return 0; |
80 | } |
70 | } |
81 | 71 |