static void scan_path(const char *base, const char *path, repo_config_fn fn) { DIR *dir = opendir(path); struct dirent *ent; struct strbuf pathbuf = STRBUF_INIT; size_t pathlen = strlen(path); struct stat st; if (!dir) { fprintf(stderr, "Error opening directory %s: %s (%d)\n", path, strerror(errno), errno); return; } strbuf_add(&pathbuf, path, strlen(path)); if (is_git_dir(pathbuf.buf)) { add_repo(base, &pathbuf, fn); goto end; } strbuf_addstr(&pathbuf, "/.git"); if (is_git_dir(pathbuf.buf)) { add_repo(base, &pathbuf, fn); goto end; } /* * Add one because we don't want to lose the trailing '/' when we * reset the length of pathbuf in the loop below. */ pathlen++; while ((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') { if (ent->d_name[1] == '\0') continue; if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') continue; if (!ctx.cfg.scan_hidden_path) continue; } strbuf_setlen(&pathbuf, pathlen); strbuf_addstr(&pathbuf, ent->d_name); if (stat(pathbuf.buf, &st)) { fprintf(stderr, "Error checking path %s: %s (%d)\n", pathbuf.buf, strerror(errno), errno); continue; } if (S_ISDIR(st.st_mode)) scan_path(base, pathbuf.buf, fn); } end: strbuf_release(&pathbuf); closedir(dir); }
static void scan_path(const char *base, const char *path, repo_config_fn fn) { DIR *dir = opendir(path); struct dirent *ent; char *buf; struct stat st; if (!dir) { fprintf(stderr, "Error opening directory %s: %s (%d)\n", path, strerror(errno), errno); return; } if (is_git_dir(path)) { add_repo(base, path, fn); goto end; } if (is_git_dir(fmt("%s/.git", path))) { add_repo(base, fmt("%s/.git", path), fn); goto end; } while ((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') { if (ent->d_name[1] == '\0') continue; if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') continue; if (!ctx.cfg.scan_hidden_path) continue; } buf = malloc(strlen(path) + strlen(ent->d_name) + 2); if (!buf) { fprintf(stderr, "Alloc error on %s: %s (%d)\n", path, strerror(errno), errno); exit(1); } sprintf(buf, "%s/%s", path, ent->d_name); if (stat(buf, &st)) { fprintf(stderr, "Error checking path %s: %s (%d)\n", buf, strerror(errno), errno); free(buf); continue; } if (S_ISDIR(st.st_mode)) scan_path(base, buf, fn); free(buf); } end: closedir(dir); }
static void walk_repo_obj(const ucl_object_t *obj, const char *file, pkg_init_flags flags) { const ucl_object_t *cur; ucl_object_iter_t it = NULL; struct pkg_repo *r; const char *key; while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); pkg_debug(1, "PkgConfig: parsing key '%s'", key); r = pkg_repo_find(key); if (r != NULL) pkg_debug(1, "PkgConfig: overwriting repository %s", key); if (cur->type == UCL_OBJECT) add_repo(cur, r, key, flags); else pkg_emit_error("Ignoring bad configuration entry in %s: %s", file, ucl_object_emit(cur, UCL_EMIT_YAML)); } }
void create_car(Repo* repo, char licenta[], char model[], char categorie[], int inchiriat) { Car* car = malloc(sizeof(Car)); car->licenta = malloc(sizeof(char) * (strlen(licenta) + 1)); //(*car).licenta strcpy(car->licenta, licenta); car->model = malloc(sizeof(char) * (strlen(model) + 1)); strcpy(car->model, model); car->categorie = malloc(sizeof(char) * (strlen(categorie) + 1)); strcpy(car->categorie, categorie); car->inchiriat = malloc(sizeof(int)); car->inchiriat = inchiriat; //printf("%s",car->licenta); add_repo(repo, car); //free??? }