static void add_user_to_group(char **args, const char *path, FILE *(*fopen_func)(const char *fileName, const char *mode)) { char *line; int len = strlen(args[1]); llist_t *plist = NULL; FILE *group_file; group_file = fopen_func(path, "r"); if (!group_file) return; while ((line = xmalloc_fgetline(group_file)) != NULL) { /* Find the group */ if (!strncmp(line, args[1], len) && line[len] == ':' ) { /* Add the new user */ line = xasprintf("%s%s%s", line, last_char_is(line, ':') ? "" : ",", args[0]); } llist_add_to_end(&plist, line); } if (ENABLE_FEATURE_CLEAN_UP) { fclose(group_file); group_file = fopen_func(path, "w"); while ((line = llist_pop(&plist))) { if (group_file) fprintf(group_file, "%s\n", line); free(line); } if (group_file) fclose(group_file); } else { group_file = fopen_func(path, "w"); if (group_file) while ((line = llist_pop(&plist))) fprintf(group_file, "%s\n", line); } }
bb_error_msg("TOKENS: [%s][%s][%s]", t[0], t[1], t[2]); } ... // free parser config_close(p); } ----- CUT ----- */ parser_t* FAST_FUNC config_open2(const char *filename, FILE* FAST_FUNC (*fopen_func)(const char *path)) { FILE* fp; parser_t *parser; fp = fopen_func(filename); if (!fp) return NULL; parser = xzalloc(sizeof(*parser)); parser->fp = fp; return parser; } parser_t* FAST_FUNC config_open(const char *filename) { return config_open2(filename, fopen_or_warn_stdin); } static void config_free_data(parser_t *parser) { free(parser->line);
} ... // free parser config_close(p); } ----- CUT ----- */ static __always_inline parser_t * FAST_FUNC config_open2(const char *filename, FILE* FAST_FUNC (*fopen_func)(const char *path, const char *mode)) { parser_t *parser; FILE* fp; fp = fopen_func(filename, "r"); if (!fp) return NULL; parser = calloc(1, sizeof(*parser)); if (parser) { parser->fp = fp; } return parser; } parser_t attribute_hidden * FAST_FUNC config_open(const char *filename) { return config_open2(filename, fopen_or_warn_stdin); } #ifdef UNUSED
fclose(file); } #endif } #if ENABLE_FEATURE_ADDUSER_TO_GROUP static void add_user_to_group(char **args, const char *path, FILE* FAST_FUNC (*fopen_func)(const char *fileName, const char *mode)) { char *line; int len = strlen(args[1]); llist_t *plist = NULL; FILE *group_file; group_file = fopen_func(path, "r"); if (!group_file) return; while ((line = xmalloc_fgetline(group_file)) != NULL) { /* Find the group */ if (!strncmp(line, args[1], len) && line[len] == ':' ) { /* Add the new user */ line = xasprintf("%s%s%s", line, last_char_is(line, ':') ? "" : ",", args[0]); } llist_add_to_end(&plist, line); }