author | Michael Krelin <hacker@klever.net> | 2007-07-20 18:56:43 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-20 18:56:43 (UTC) |
commit | 127f43d4e202ba3e63f72add44238c2686dd97f3 (patch) (side-by-side diff) | |
tree | 5543c525155fdb0d925d881094307e4be807c002 | |
parent | 3aae82703bfe70fc273f0611cdc780804df77bb8 (diff) | |
download | cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.zip cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.gz cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.bz2 |
added a chk_non_negative check
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | shared.c | 7 |
2 files changed, 8 insertions, 0 deletions
@@ -112,96 +112,97 @@ extern char *cgit_logo_link; extern char *cgit_module_link; extern char *cgit_agefile; extern char *cgit_virtual_root; extern char *cgit_script_name; extern char *cgit_cache_root; extern char *cgit_repo_group; extern int cgit_nocache; extern int cgit_snapshots; extern int cgit_enable_index_links; extern int cgit_enable_log_filecount; extern int cgit_enable_log_linecount; extern int cgit_max_lock_attempts; extern int cgit_cache_root_ttl; extern int cgit_cache_repo_ttl; extern int cgit_cache_dynamic_ttl; extern int cgit_cache_static_ttl; extern int cgit_cache_max_create_time; extern int cgit_summary_log; extern int cgit_max_msg_len; extern int cgit_max_repodesc_len; extern int cgit_max_commit_count; extern int cgit_query_has_symref; extern int cgit_query_has_sha1; extern char *cgit_querystring; extern char *cgit_query_repo; extern char *cgit_query_page; extern char *cgit_query_search; extern char *cgit_query_head; extern char *cgit_query_sha1; extern char *cgit_query_sha2; extern char *cgit_query_path; extern char *cgit_query_name; extern int cgit_query_ofs; extern int htmlfd; extern int cgit_get_cmd_index(const char *cmd); extern struct repoinfo *cgit_get_repoinfo(const char *url); extern void cgit_global_config_cb(const char *name, const char *value); extern void cgit_repo_config_cb(const char *name, const char *value); extern void cgit_querystring_cb(const char *name, const char *value); extern int chk_zero(int result, char *msg); extern int chk_positive(int result, char *msg); +extern int chk_non_negative(int result, char *msg); extern int hextoint(char c); extern char *trim_end(const char *str, char c); extern void *cgit_free_commitinfo(struct commitinfo *info); extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, linediff_fn fn); extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); extern void html(const char *txt); extern void htmlf(const char *format,...); extern void html_txt(char *txt); extern void html_ntxt(int len, char *txt); extern void html_attr(char *txt); extern void html_hidden(char *name, char *value); extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); extern int html_include(const char *filename); extern int cgit_read_config(const char *filename, configfn fn); extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); extern struct taginfo *cgit_parse_tag(struct tag *tag); extern void cgit_parse_url(const char *url); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); @@ -41,96 +41,103 @@ int cgit_summary_log = 0; int cgit_max_msg_len = 60; int cgit_max_repodesc_len = 60; int cgit_max_commit_count = 50; int cgit_query_has_symref = 0; int cgit_query_has_sha1 = 0; char *cgit_querystring = NULL; char *cgit_query_repo = NULL; char *cgit_query_page = NULL; char *cgit_query_head = NULL; char *cgit_query_search = NULL; char *cgit_query_sha1 = NULL; char *cgit_query_sha2 = NULL; char *cgit_query_path = NULL; char *cgit_query_name = NULL; int cgit_query_ofs = 0; int htmlfd = 0; int cgit_get_cmd_index(const char *cmd) { static char *cmds[] = {"log", "commit", "diff", "tree", "blob", "snapshot", NULL}; int i; for(i = 0; cmds[i]; i++) if (!strcmp(cmd, cmds[i])) return i + 1; return 0; } int chk_zero(int result, char *msg) { if (result != 0) die("%s: %s", msg, strerror(errno)); return result; } int chk_positive(int result, char *msg) { if (result <= 0) die("%s: %s", msg, strerror(errno)); return result; } +int chk_non_negative(int result, char *msg) +{ + if (result < 0) + die("%s: %s",msg, strerror(errno)); + return result; +} + struct repoinfo *add_repo(const char *url) { struct repoinfo *ret; if (++cgit_repolist.count > cgit_repolist.length) { if (cgit_repolist.length == 0) cgit_repolist.length = 8; else cgit_repolist.length *= 2; cgit_repolist.repos = xrealloc(cgit_repolist.repos, cgit_repolist.length * sizeof(struct repoinfo)); } ret = &cgit_repolist.repos[cgit_repolist.count-1]; ret->url = xstrdup(url); ret->name = ret->url; ret->path = NULL; ret->desc = NULL; ret->owner = NULL; ret->group = cgit_repo_group; ret->defbranch = "master"; ret->snapshots = cgit_snapshots; ret->enable_log_filecount = cgit_enable_log_filecount; ret->enable_log_linecount = cgit_enable_log_linecount; ret->module_link = cgit_module_link; ret->readme = NULL; return ret; } struct repoinfo *cgit_get_repoinfo(const char *url) { int i; struct repoinfo *repo; for (i=0; i<cgit_repolist.count; i++) { repo = &cgit_repolist.repos[i]; if (!strcmp(repo->url, url)) return repo; } return NULL; } void cgit_global_config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) cgit_root_title = xstrdup(value); else if (!strcmp(name, "css")) |