char *git__basename(const char *path) { char *bname = NULL; int len; len = (path ? strlen(path) : 0) + 2; bname = (char *)git__malloc(len); if (bname == NULL) return NULL; if (git__basename_r(bname, len, path) < GIT_SUCCESS) { free(bname); return NULL; } return bname; }
static int guess_repository_dirs(git_repository *repo, const char *repository_path) { char buffer[GIT_PATH_MAX]; const char *path_work_tree = NULL; /* Git directory name */ if (git__basename_r(buffer, sizeof(buffer), repository_path) < 0) return GIT_EINVALIDPATH; if (strcmp(buffer, DOT_GIT) == 0) { /* Path to working dir */ if (git__dirname_r(buffer, sizeof(buffer), repository_path) < 0) return GIT_EINVALIDPATH; path_work_tree = buffer; } return assign_repository_dirs(repo, repository_path, NULL, NULL, path_work_tree); }