From 8d66d5fe4a9d7b7b015153edb8f204ac3b89c461 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 14 Dec 2007 15:17:59 +0200 Subject: [PATCH] Bunch of const char* corrections - functions returning string constants as char * etc... --- build/files.c | 2 +- build/pack.c | 2 +- build/parseChangelog.c | 8 +++++--- build/parseScript.c | 2 +- build/spec.c | 2 +- lib/cpio.c | 9 +++++---- lib/getdate.y | 2 +- lib/legacy.c | 2 +- lib/psm.c | 2 +- lib/rpmrc.c | 2 +- python/header-py.c | 5 +++-- rpmdb/header_internal.c | 2 +- rpmio/ugid.c | 4 ++-- rpmio/ugid.h | 4 ++-- tools/javadeps.c | 14 +++++++------- 15 files changed, 33 insertions(+), 29 deletions(-) diff --git a/build/files.c b/build/files.c index dc428a3..290503e 100644 --- a/build/files.c +++ b/build/files.c @@ -920,7 +920,7 @@ static rpmRC parseForSimple(rpmSpec spec, Package pkg, char * buf, } else { /* XXX WATCHOUT: buf is an arg */ { - static char *_docdir_fmt= 0; + static const char *_docdir_fmt = NULL; static int oneshot = 0; const char *ddir, *fmt, *errstr; if (!oneshot) { diff --git a/build/pack.c b/build/pack.c index db62283..d848057 100644 --- a/build/pack.c +++ b/build/pack.c @@ -256,7 +256,7 @@ static rpmRC processScriptFiles(rpmSpec spec, Package pkg) } else { /* This is dumb. When the header supports NULL string */ /* this will go away. */ - char *bull = ""; + const char *bull = ""; (void) headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS, RPM_STRING_ARRAY_TYPE, &bull, 1); } diff --git a/build/parseChangelog.c b/build/parseChangelog.c index e627453..0c53215 100644 --- a/build/parseChangelog.c +++ b/build/parseChangelog.c @@ -41,11 +41,13 @@ void addChangelogEntry(Header h, time_t time, const char *name, const char *text static int dateToTimet(const char * datestr, time_t * secs) { struct tm time; - char * p, * pe, * q, ** idx; + const char ** idx; + char * p, * pe, * q; + char * date = strcpy(alloca(strlen(datestr) + 1), datestr); -static char * days[] = +static const char * days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL }; -static char * months[] = +static const char * months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL }; static char lengths[] = diff --git a/build/parseScript.c b/build/parseScript.c index a4b3224..98c9fb2 100644 --- a/build/parseScript.c +++ b/build/parseScript.c @@ -73,7 +73,7 @@ int parseScript(rpmSpec spec, int parsePart) char *p; const char **progArgv = NULL; int progArgc; - char *partname = NULL; + const char *partname = NULL; rpm_tag_t reqtag = 0; rpm_tag_t tag = 0; int tagflags = 0; diff --git a/build/spec.c b/build/spec.c index 64d2a08..98a9cd4 100644 --- a/build/spec.c +++ b/build/spec.c @@ -246,7 +246,7 @@ int addSource(rpmSpec spec, Package pkg, const char *field, rpm_tag_t tag) { struct Source *p; int flag = 0; - char *name = NULL; + const char *name = NULL; char *nump; const char *fieldp = NULL; char buf[BUFSIZ]; diff --git a/lib/cpio.c b/lib/cpio.c index ef1aa38..31ce96b 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -177,17 +177,18 @@ int cpioHeaderRead(FSM_t fsm, struct stat * st) const char * cpioStrerror(int rc) { static char msg[256]; - char *s; + const char *s; int myerrno = errno; size_t l; strcpy(msg, "cpio: "); switch (rc) { - default: - s = msg + strlen(msg); - sprintf(s, _("(error 0x%x)"), (unsigned)rc); + default: { + char *t = msg + strlen(msg); + sprintf(t, _("(error 0x%x)"), (unsigned)rc); s = NULL; break; + } case CPIOERR_BAD_MAGIC: s = _("Bad magic"); break; case CPIOERR_BAD_HEADER: s = _("Bad/unreadable header");break; diff --git a/lib/getdate.y b/lib/getdate.y index 13dcad2..fae70dc 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -127,7 +127,7 @@ static int yyerror(const char * s); ** An entry in the lexical lookup table. */ typedef struct _TABLE { - char *name; + const char *name; int type; time_t value; } TABLE; diff --git a/lib/legacy.c b/lib/legacy.c index 709a925..735889d 100644 --- a/lib/legacy.c +++ b/lib/legacy.c @@ -178,7 +178,7 @@ void providePackageNVR(Header h) */ if (!hge(h, RPMTAG_PROVIDEVERSION, &pvt, (void **) &providesEVR, NULL)) { for (i = 0; i < providesCount; i++) { - char * vdummy = ""; + const char * vdummy = ""; int32_t fdummy = RPMSENSE_ANY; xx = headerAddOrAppendEntry(h, RPMTAG_PROVIDEVERSION, RPM_STRING_ARRAY_TYPE, &vdummy, 1); diff --git a/lib/psm.c b/lib/psm.c index d54bc49..e37459a 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -400,7 +400,7 @@ exit: return rpmrc; } -static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"; +static const char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"; /** * Return scriptlet name from tag. diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 9dea805..24f7f50 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -697,7 +697,7 @@ static rpmRC doReadRC( FD_t fd, const char * urlfn) */ static rpmRC rpmPlatform(const char * platform) { - char *cpu = NULL, *vendor = NULL, *os = NULL, *gnu = NULL; + const char *cpu = NULL, *vendor = NULL, *os = NULL, *gnu = NULL; uint8_t * b = NULL; ssize_t blen = 0; int init_platform = 0; diff --git a/python/header-py.c b/python/header-py.c index e3f9360..139979d 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -725,7 +725,7 @@ PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds) FD_t fd; int fileno; PyObject * list; - char * kwlist[] = {"fd", NULL}; + const char * kwlist[] = {"fd", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &fileno)) return NULL; @@ -929,7 +929,8 @@ static int compare_values(const char *str1, const char *str2) PyObject * labelCompare (PyObject * self, PyObject * args) { - char *v1, *r1, *e1, *v2, *r2, *e2; + char *v1, *r1, *v2, *r2; + const char *e1, *e2; int rc; if (!PyArg_ParseTuple(args, "(zzz)(zzz)", diff --git a/rpmdb/header_internal.c b/rpmdb/header_internal.c index 15d99f2..22a6b30 100644 --- a/rpmdb/header_internal.c +++ b/rpmdb/header_internal.c @@ -36,7 +36,7 @@ void headerDump(Header h, FILE *f, int flags, indexEntry p; const struct headerTagTableEntry_s * tage; const char * tag; - char * type; + const char * type; /* First write out the length of the index (count of index entries) */ fprintf(f, "Entry count: %d\n", h->indexUsed); diff --git a/rpmio/ugid.c b/rpmio/ugid.c index 32d7387..c256829 100644 --- a/rpmio/ugid.c +++ b/rpmio/ugid.c @@ -109,7 +109,7 @@ static char * lastGname = NULL; return 0; } -char * uidToUname(uid_t uid) +const char * uidToUname(uid_t uid) { static uid_t lastUid = (uid_t) -1; static char * lastUname = NULL; @@ -140,7 +140,7 @@ static char * lastUname = NULL; } } -char * gidToGname(gid_t gid) +const char * gidToGname(gid_t gid) { static gid_t lastGid = (gid_t) -1; static char * lastGname = NULL; diff --git a/rpmio/ugid.h b/rpmio/ugid.h index 0ef5559..d3556ef 100644 --- a/rpmio/ugid.h +++ b/rpmio/ugid.h @@ -19,8 +19,8 @@ int gnameToGid(const char * thisGname, gid_t * gid); /* * Call w/ -1 to flush the cache, returns NULL if the user can't be found. */ -char * uidToUname(uid_t uid); -char * gidToGname(gid_t gid); +const char * uidToUname(uid_t uid); +const char * gidToGname(gid_t gid); #ifdef __cplusplus } diff --git a/tools/javadeps.c b/tools/javadeps.c index 8992ab4..1922ced 100644 --- a/tools/javadeps.c +++ b/tools/javadeps.c @@ -84,10 +84,10 @@ typedef struct { /*---------Global Variables, in all caps---------*/ /*name of this program*/ -char *PROGRAM_NAME=0; +const char *PROGRAM_NAME=0; /*name of the current class file*/ -char *FILE_NAME=0; +const char *FILE_NAME=0; /*the name of the last class file seen*/ char *CLASS_NAME=0; @@ -139,10 +139,10 @@ int SIZE_PRINT_TABLE; void usage (void); void outofmemory(void); -void die(char *format, ...); +void die(const char *format, ...); size_t my_fread(void *ptr, size_t size, size_t nitems, FILE *stream); void check_range(short entryNum, short value, short poolSize); -char *is_lower_equal (char *string, char *pattern); +char *is_lower_equal (char *string, const char *pattern); int findJavaMagic (FILE *fileHandle); int my_strcmp (const void *a, const void *b); void print_table_flush(void); @@ -292,7 +292,7 @@ void outofmemory(void) { } -void die(char *format, ...) { +void die(const char *format, ...) { /* Most errors are fatal. This function throws a fatal error and accepts arguments like printf does*/ @@ -389,7 +389,7 @@ void check_range(short entryNum, short value, short poolSize) { prefix of my strings. */ char -*is_lower_equal (char *string, char *pattern) +*is_lower_equal (char *string, const char *pattern) { while ( (tolower(*string) == *pattern) && @@ -1157,7 +1157,7 @@ void processJavaFile (FILE *fileHandle) { CLASS_NAME=findClassName(fileHandle, &symbolTable); if(ARG_DEPSFORMAT) { - char *prefix_seperator = ": "; + const char *prefix_seperator = ": "; format_class_name = formatClassName(CLASS_NAME, '\0', 0); -- 2.7.4