Changeset dda2602 in mainline for uspace/srv/sysman/util.c
- Timestamp:
- 2019-08-03T09:41:07Z (6 years ago)
- Children:
- dd5c623
- Parents:
- c0e4fc50
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-08 11:10:06)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:41:07)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/util.c
rc0e4fc50 rdda2602 38 38 * @return NULL on error 39 39 */ 40 char * compose_path(const char *dirname, const char *filename)40 char *util_compose_path(const char *dirname, const char *filename) 41 41 { 42 42 size_t size = str_size(dirname) + str_size(filename) + 2; … … 51 51 return result; 52 52 } 53 54 /** Parse command line 55 * 56 * @param[out] dst pointer to command_t 57 * path and zeroth argument are the equal 58 * 59 * @return true on success 60 * @return false on (low memory) error 61 */ 62 bool util_parse_command(const char *string, void *dst, text_parse_t *parse, 63 size_t lineno) 64 { 65 command_t *command = dst; 66 util_command_deinit(command); 67 68 command->buffer = str_dup(string); 69 if (!command->buffer) { 70 return false; 71 } 72 73 command->argc = 0; 74 char *to_split = command->buffer; 75 char *cur_tok; 76 bool has_path = false; 77 78 while ((cur_tok = str_tok(to_split, " ", &to_split)) && 79 command->argc < MAX_COMMAND_ARGS) { 80 if (!has_path) { 81 command->path = cur_tok; 82 has_path = true; 83 } 84 command->argv[command->argc++] = cur_tok; 85 } 86 command->argv[command->argc] = NULL; 87 88 89 if (command->argc > MAX_COMMAND_ARGS) { 90 text_parse_raise_error(parse, lineno, 91 CONFIGURATION_ELIMIT); 92 return false; 93 } else { 94 return true; 95 } 96 } 97 98 99 void util_command_init(command_t *command) 100 { 101 memset(command, 0, sizeof(*command)); 102 } 103 104 void util_command_deinit(command_t *command) 105 { 106 free(command->buffer); 107 memset(command, 0, sizeof(*command)); 108 }
Note:
See TracChangeset
for help on using the changeset viewer.