From: Sami Kerola Date: Sat, 24 Nov 2012 11:18:31 +0000 (+0000) Subject: variables: use const where ever possible X-Git-Tag: cronie1.4.10~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=901426268278cbd9b2ac1b2ddcee71145e12757f;p=cronie variables: use const where ever possible Signed-off-by: Sami Kerola --- diff --git a/src/crontab.c b/src/crontab.c index 8123dc7..baec62c 100644 --- a/src/crontab.c +++ b/src/crontab.c @@ -43,18 +43,18 @@ enum opt_t {opt_unknown, opt_list, opt_delete, opt_edit, opt_replace, opt_hostset, opt_hostget}; #if DEBUGGING -static char *Options[] = {"???", "list", "delete", "edit", "replace", "hostset", "hostget"}; +static const char *Options[] = {"???", "list", "delete", "edit", "replace", "hostset", "hostget"}; # ifdef WITH_SELINUX -static char *getoptargs = "u:lerisncx:"; +static const char *getoptargs = "u:lerisncx:"; # else -static char *getoptargs = "u:lerincx:"; +static const char *getoptargs = "u:lerincx:"; # endif #else # ifdef WITH_SELINUX -static char *getoptargs = "u:lerisnc"; +static const char *getoptargs = "u:lerisnc"; # else -static char *getoptargs = "u:lerinc"; +static const char *getoptargs = "u:lerinc"; # endif #endif #ifdef WITH_SELINUX @@ -77,7 +77,7 @@ edit_cmd(void), poke_daemon(void), check_error(const char *), parse_args(int c, char *v[]), die(int); static int replace_cmd(void), hostset_cmd(void), hostget_cmd(void); -static char *host_specific_filename(char *filename, int prefix); +static char *host_specific_filename(const char *filename, int prefix); static char *tmp_path(void); static void usage(const char *msg) { @@ -101,7 +101,7 @@ static void usage(const char *msg) { int main(int argc, char *argv[]) { int exitstatus; - char *n = "-"; /*set the n string to - so we have a valid string to use */ + const char *n = "-"; /*set the n string to - so we have a valid string to use */ if ((ProgramName=strrchr(argv[0], '/')) == NULL) { ProgramName = argv[0]; @@ -400,7 +400,7 @@ static void check_error(const char *msg) { } static char *tmp_path() { - char *tmpdir = NULL; + const char *tmpdir = NULL; if ((getuid() == geteuid()) && (getgid() == getegid())) { tmpdir = getenv("TMPDIR"); @@ -408,7 +408,7 @@ static char *tmp_path() { return tmpdir ? tmpdir : "/tmp"; } -static char *host_specific_filename(char *filename, int prefix) +static char *host_specific_filename(const char *filename, int prefix) { /* * For cluster-wide use, where there is otherwise risk of the same @@ -435,7 +435,8 @@ static char *host_specific_filename(char *filename, int prefix) } static void edit_cmd(void) { - char n[MAX_FNAME], q[MAX_TEMPSTR], *editor; + char n[MAX_FNAME], q[MAX_TEMPSTR]; + const char *editor; FILE *f; int ch = '\0', t; struct stat statbuf; diff --git a/src/database.c b/src/database.c index 09d56fd..52f033c 100644 --- a/src/database.c +++ b/src/database.c @@ -45,7 +45,7 @@ static void process_crontab(const char *, const char *, static int not_a_crontab(DIR_T * dp); /* return 1 if we should skip this file */ -static void max_mtime(char *dir_name, struct stat *max_st); +static void max_mtime(const char *dir_name, struct stat *max_st); /* record max mtime of any file under dir_name in max_st */ static int @@ -599,7 +599,7 @@ static int not_a_crontab(DIR_T * dp) { return (0); } -static void max_mtime(char *dir_name, struct stat *max_st) { +static void max_mtime(const char *dir_name, struct stat *max_st) { DIR *dir; DIR_T *dp; struct stat st; diff --git a/src/env.c b/src/env.c index 2b300fb..61ae74c 100644 --- a/src/env.c +++ b/src/env.c @@ -228,7 +228,7 @@ int load_env(char *envstr, FILE * f) { return (TRUE); } -char *env_get(char *name, char **envp) { +char *env_get(const char *name, char **envp) { int len = strlen(name); char *p, *q; diff --git a/src/funcs.h b/src/funcs.h index aee4a99..e796574 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -51,7 +51,7 @@ int load_database(cron_db *), job_runqueue(void), set_debug_flags(const char *), get_char(FILE *), - get_string(char *, int, FILE *, char *), + get_string(char *, int, FILE *, const char *), swap_uids(void), swap_uids_back(void), load_env(char *, FILE *), @@ -63,10 +63,10 @@ int load_database(cron_db *), size_t strlens(const char *, ...); -char *env_get(char *, char **), +char *env_get(const char *, char **), *arpadate(time_t *), *mkprints(unsigned char *, unsigned int), - *first_word(char *, char *), + *first_word(const char *, const char *), **env_init(void), **env_copy(char **), **env_set(char **, char *); diff --git a/src/misc.c b/src/misc.c index b43cf28..c08827b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -368,7 +368,7 @@ void unget_char(int ch, FILE * file) { * (3) uses get_char() so LineNumber will be accurate * (4) returns EOF or terminating character, whichever */ -int get_string(char *string, int size, FILE * file, char *terms) { +int get_string(char *string, int size, FILE * file, const char *terms) { int ch; while (EOF != (ch = get_char(file)) && !strchr(terms, ch)) { @@ -591,7 +591,7 @@ void log_close(void) { * (1) this routine is fairly slow * (2) it returns a pointer to static storage */ -char *first_word(char *s, char *t) { +char *first_word(const char *s, const char *t) { static char retbuf[2][MAX_TEMPSTR + 1]; /* sure wish C had GC */ static int retsel = 0; char *rb, *rp;