diff options
author | jbj <devnull@localhost> | 2001-04-29 01:05:43 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-04-29 01:05:43 +0000 |
commit | 3b5820c4205e440d9aad5c5d626721ee30b12292 (patch) | |
tree | b1f0a694903aef1dd937539e1b06c8b0947fb67c /rpmio | |
parent | 6a0524ed57548de92daa4b6cf8ee9d2ab39d7a42 (diff) | |
download | librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.tar.gz librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.tar.bz2 librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.zip |
- globalize _free(3) wrapper in rpmlib.h, consistent usage throughout.
- internalize locale insensitive ctype(3) in rpmio.h
- boring lclint annotations and fiddles.
CVS patchset: 4721
CVS date: 2001/04/29 01:05:43
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/.lclintrc | 16 | ||||
-rw-r--r-- | rpmio/digest.c | 2 | ||||
-rw-r--r-- | rpmio/macro.c | 18 | ||||
-rw-r--r-- | rpmio/rpmio.c | 28 | ||||
-rw-r--r-- | rpmio/rpmio.h | 21 | ||||
-rw-r--r-- | rpmio/rpmlog.c | 18 | ||||
-rw-r--r-- | rpmio/rpmlog.h | 2 | ||||
-rw-r--r-- | rpmio/strcasecmp.c | 25 | ||||
-rw-r--r-- | rpmio/ugid.c | 77 |
9 files changed, 115 insertions, 92 deletions
diff --git a/rpmio/.lclintrc b/rpmio/.lclintrc index c5e1d3e49..5da960259 100644 --- a/rpmio/.lclintrc +++ b/rpmio/.lclintrc @@ -11,20 +11,20 @@ -unrecogcomments # don't-bother-me-yet parameters --branchstate +-branchstate # ~43 occurences #-immediatetrans --mustfree +-mustfree # alloca is painful #-observertrans #-statictrans # not-yet normal parameters -boolops # w->n --fixedformalarray --null --predboolint # w->n --predboolothers # w->n --retvalint # w->n --type +#-fixedformalarray +-null # ugh +-predboolint # w->n ~144 +#-predboolothers # w->n ~8 +-retvalint # w->n ~48 +-type # ~449 # not-yet -weak paramaters #+boolint diff --git a/rpmio/digest.c b/rpmio/digest.c index 434ce6acf..8fa83dea4 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -9,6 +9,8 @@ typedef unsigned int uint32; typedef unsigned char byte; +/*@access DIGEST_CTX@*/ + /** * MD5/SHA1 digest private data. */ diff --git a/rpmio/macro.c b/rpmio/macro.c index 301c7addf..9fb896507 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -378,7 +378,7 @@ printExpansion(MacroBuf *mb, const char *t, const char *te) #define COPYNAME(_ne, _s, _c) \ { SKIPBLANK(_s,_c); \ - while(((_c) = *(_s)) && (isalnum(_c) || (_c) == '_')) \ + while(((_c) = *(_s)) && (xisalnum(_c) || (_c) == '_')) \ *(_ne)++ = *(_s)++; \ *(_ne) = '\0'; \ } @@ -578,7 +578,7 @@ doDefine(MacroBuf *mb, const char *se, int level, int expandbody) se = s; /* Names must start with alphabetic or _ and be at least 3 chars */ - if (!((c = *n) && (isalpha(c) || c == '_') && (ne - n) > 2)) { + if (!((c = *n) && (xisalpha(c) || c == '_') && (ne - n) > 2)) { rpmError(RPMERR_BADSPEC, _("Macro %%%s has illegal name (%%define)\n"), n); return se; @@ -627,7 +627,7 @@ doUndefine(MacroContext *mc, const char *se) se = s; /* Names must start with alphabetic or _ and be at least 3 chars */ - if (!((c = *n) && (isalpha(c) || c == '_') && (ne - n) > 2)) { + if (!((c = *n) && (xisalpha(c) || c == '_') && (ne - n) > 2)) { rpmError(RPMERR_BADSPEC, _("Macro %%%s has illegal name (%%undefine)\n"), n); return se; @@ -947,7 +947,7 @@ doFoo(MacroBuf *mb, int negate, const char *f, size_t fn, const char *g, size_t } b = be; } else if (STREQ("S", f, fn)) { - for (b = buf; (c = *b) && isdigit(c);) + for (b = buf; (c = *b) && xisdigit(c);) b++; if (!c) { /* digit index */ b++; @@ -955,7 +955,7 @@ doFoo(MacroBuf *mb, int negate, const char *f, size_t fn, const char *g, size_t } else b = buf; } else if (STREQ("P", f, fn)) { - for (b = buf; (c = *b) && isdigit(c);) + for (b = buf; (c = *b) && xisdigit(c);) b++; if (!c) { /* digit index */ b++; @@ -1041,7 +1041,7 @@ expandMacro(MacroBuf *mb) f = se = s; if (*se == '-') se++; - while((c = *se) && (isalnum(c) || c == '_')) + while((c = *se) && (xisalnum(c) || c == '_')) se++; /* Recognize non-alnum macros too */ switch (*se) { @@ -1256,7 +1256,7 @@ expandMacro(MacroBuf *mb) /* Setup args for "%name " macros with opts */ if (me && me->opts != NULL) { - if (grab) { + if (grab != '\0') { se = grabArgs(mb, me, fe, grab); } else { addMacro(mb->mc, "**", NULL, "", mb->depth); @@ -1407,7 +1407,7 @@ rpmInitMacros(MacroContext *mc, const char *macrofiles) if (mc == NULL) mc = &rpmGlobalMacroContext; - for (mfile = m = xstrdup(macrofiles); *mfile; mfile = me) { + for (mfile = m = xstrdup(macrofiles); *mfile != '\0'; mfile = me) { FD_t fd; char buf[BUFSIZ]; @@ -1595,7 +1595,7 @@ char *rpmCleanPath(char * path) /*fprintf(stderr, "*** RCP %s ->\n", path); */ s = t = te = path; - while (*s) { + while (*s != '\0') { /*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-path), path, s); */ switch(*s) { case ':': /* handle url's */ diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index d7edec90e..d9b5606a5 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -93,6 +93,16 @@ static int httpTimeoutSecs = TIMEOUT_SECS; int _ftp_debug = 0; int _rpmio_debug = 0; +/** + * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. + * @param this memory to free + * @retval NULL always + */ +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { + if (this != NULL) free((void *)this); + return NULL; +} + /* =============================================================== */ static /*@observer@*/ const char * fdbg(FD_t fd) @@ -237,8 +247,8 @@ DBGREFS(0, (stderr, "--> fd %p -- %d %s at %s:%u\n", fd, FDNREFS(fd), msg, file DBGREFS(fd, (stderr, "--> fd %p -- %d %s at %s:%u %s\n", fd, fd->nrefs, msg, file, line, fdbg(fd))); if (--fd->nrefs > 0) /*@-refcounttrans@*/ return fd; /*@=refcounttrans@*/ - if (fd->stats) free(fd->stats); - if (fd->digest) free(fd->digest); + fd->stats = _free(fd->stats); + fd->digest = _free(fd->digest); /*@-refcounttrans@*/ free(fd); /*@=refcounttrans@*/ } return NULL; @@ -608,7 +618,7 @@ static int mygethostbyname(const char * host, struct in_addr * address) static int getHostAddress(const char * host, struct in_addr * address) { - if (isdigit(host[0])) { + if (xisdigit(host[0])) { if (! /*@-unrecog@*/ inet_aton(host, address) /*@=unrecog@*/ ) { return FTPERR_BAD_HOST_ADDR; } @@ -798,7 +808,7 @@ fprintf(stderr, "<- %s\n", s); /* FTP: look for "123-" and/or "123 " */ if (strchr("0123456789", *s)) { - if (errorCode[0]) { + if (errorCode[0] != '\0') { if (!strncmp(s, errorCode, sizeof("123")-1) && s[3] == ' ') moretodo = 0; } else { @@ -1027,7 +1037,7 @@ int ftpReq(FD_t data, const char * ftpCmd, const char * ftpArg) } chptr = passReply; - while (*chptr++) { + while (*chptr++ != '\0') { if (*chptr == ',') *chptr = '.'; } @@ -2407,9 +2417,9 @@ static inline void cvtfmode (const char *m, } *stdio = *other = '\0'; - if (end) - *end = (*m ? m : NULL); - if (f) + if (end != NULL) + *end = (*m != '\0' ? m : NULL); + if (f != NULL) *f = flags; } @@ -2474,7 +2484,7 @@ fprintf(stderr, "*** Fdopen fpio fp %p\n", fp); fdPush(fd, fpio, fp, fdno); /* Push fpio onto stack */ } } - } else if (other[0]) { + } else if (other[0] != '\0') { for (end = other; *end && strchr("0123456789fh", *end); end++) ; if (*end == '\0') { diff --git a/rpmio/rpmio.h b/rpmio/rpmio.h index e8896d5ec..40e4d9c8e 100644 --- a/rpmio/rpmio.h +++ b/rpmio/rpmio.h @@ -430,6 +430,27 @@ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length); /*@observer@*/ extern FDIO_t fadio; /*@}*/ +/*@unused@*/ static inline int xislower(int c) {return (c >= 'a' && c <= 'z');} +/*@unused@*/ static inline int xisupper(int c) {return (c >= 'A' && c <= 'Z');} +/*@unused@*/ static inline int xisalpha(int c) { + return (xislower(c) || xisupper(c)); +} +/*@unused@*/ static inline int xisdigit(int c) {return (c >= '0' && c <= '9');} +/*@unused@*/ static inline int xisalnum(int c) { + return (xisalpha(c) || xisdigit(c)); +} +/*@unused@*/ static inline int xisblank(int c) {return (c == ' ' || c == '\t');} +/*@unused@*/ static inline int xisspace(int c) { + return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v'); +} + +/*@unused@*/ static inline int xtolower(int c) { + return ((xisupper(c)) ? (c | ('a' - 'A')) : c); +} +/*@unused@*/ static inline int xtoupper(int c) { + return ((xislower(c)) ? (c & ~('a' - 'A')) : c); +} + /** \ingroup rpmio * Locale insensitive strcasecmp(3). */ diff --git a/rpmio/rpmlog.c b/rpmio/rpmlog.c index 526aae3a6..94e4d1ecb 100644 --- a/rpmio/rpmlog.c +++ b/rpmio/rpmlog.c @@ -112,6 +112,7 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) int mask = RPMLOG_MASK(pri); /*@unused@*/ int fac = RPMLOG_FAC(code); char *msgbuf, *msg; + int freeMsgbuf = 1; int msgnb = BUFSIZ, nb; FILE * msgout = stderr; rpmlogRec rec; @@ -125,10 +126,8 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) /* Allocate a sufficently large buffer for output. */ while (1) { va_list apc; - __va_copy(apc, ap); - /*@-unrecog@*/ - nb = vsnprintf(msgbuf, msgnb, fmt, apc); - /*@=unrecog@*/ + /*@-sysunrecog@*/ __va_copy(apc, ap); /*@=sysunrecog@*/ + /*@-unrecog@*/ nb = vsnprintf(msgbuf, msgnb, fmt, apc); /*@=unrecog@*/ if (nb > -1 && nb < msgnb) break; if (nb > -1) /* glibc 2.1 */ @@ -154,12 +153,10 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) rec->code = code; rec->message = msgbuf; - msgbuf = NULL; + freeMsgbuf = 0; if (_rpmlogCallback) { _rpmlogCallback(); - if (msgbuf) - free(msgbuf); return; /* XXX Preserve legacy rpmError behavior. */ } } @@ -181,15 +178,12 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) break; } - /* Silly FORTRAN-like carriage control. */ - if (*msg == '+') - msg++; - else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri]) + if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri]) fputs(_(rpmlogMsgPrefix[pri]), msgout); fputs(msg, msgout); fflush(msgout); - if (msgbuf) + if (freeMsgbuf) free(msgbuf); if (pri <= RPMLOG_CRIT) exit(EXIT_FAILURE); diff --git a/rpmio/rpmlog.h b/rpmio/rpmlog.h index b259c3531..24c7164d7 100644 --- a/rpmio/rpmlog.h +++ b/rpmio/rpmlog.h @@ -208,7 +208,7 @@ int rpmlogSetMask (int mask); /** * Generate a log message using FMT string and option arguments. */ -void rpmlog (int pri, const char *fmt, ...); +/*@mayexit@*/ /*@printflike@*/ void rpmlog (int pri, const char *fmt, ...); /** * Set rpmlog callback function. diff --git a/rpmio/strcasecmp.c b/rpmio/strcasecmp.c index 4fcb37d60..669522b4a 100644 --- a/rpmio/strcasecmp.c +++ b/rpmio/strcasecmp.c @@ -6,16 +6,11 @@ #include "rpmio.h" #include "debug.h" -static inline unsigned char xtolower(unsigned char c) +int xstrcasecmp(const char * s1, const char * s2) { - return ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c); -} - -int xstrcasecmp(const char *s1, const char *s2) -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; + const char * p1 = s1; + const char * p2 = s2; + char c1, c2; if (p1 == p2) return 0; @@ -29,14 +24,14 @@ int xstrcasecmp(const char *s1, const char *s2) } while (c1 == c2); - return c1 - c2; + return (int)(c1 - c2); } int xstrncasecmp(const char *s1, const char *s2, size_t n) { - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; + const char * p1 = s1; + const char * p2 = s2; + char c1, c2; if (p1 == p2 || n == 0) return 0; @@ -46,8 +41,8 @@ int xstrncasecmp(const char *s1, const char *s2, size_t n) c1 = xtolower (*p1++); c2 = xtolower (*p2++); if (c1 == '\0' || c1 != c2) - return c1 - c2; + break; } while (--n > 0); - return c1 - c2; + return (int)(c1 - c2); } diff --git a/rpmio/ugid.c b/rpmio/ugid.c index 3a529311e..67fbf76e4 100644 --- a/rpmio/ugid.c +++ b/rpmio/ugid.c @@ -15,24 +15,24 @@ int unameToUid(const char * thisUname, uid_t * uid) { - /*@only@*/ static char * lastUname = NULL; - static int lastUnameLen = 0; - static int lastUnameAlloced; +/*@only@*/ static char * lastUname = NULL; + static size_t lastUnameLen = 0; + static size_t lastUnameAlloced; static uid_t lastUid; struct passwd * pwent; - int thisUnameLen; + size_t thisUnameLen; if (!thisUname) { lastUnameLen = 0; return -1; - } else if (!strcmp(thisUname, "root")) { + } else if (strcmp(thisUname, "root") == 0) { *uid = 0; return 0; } thisUnameLen = strlen(thisUname); - if (!lastUname || thisUnameLen != lastUnameLen || - strcmp(thisUname, lastUname)) { + if (lastUname == NULL || thisUnameLen != lastUnameLen || + strcmp(thisUname, lastUname) != 0) { if (lastUnameAlloced < thisUnameLen + 1) { lastUnameAlloced = thisUnameLen + 10; lastUname = xrealloc(lastUname, lastUnameAlloced); /* XXX memory leak */ @@ -40,10 +40,10 @@ int unameToUid(const char * thisUname, uid_t * uid) strcpy(lastUname, thisUname); pwent = getpwnam(thisUname); - if (!pwent) { + if (pwent == NULL) { endpwent(); pwent = getpwnam(thisUname); - if (!pwent) return -1; + if (pwent == NULL) return -1; } lastUid = pwent->pw_uid; @@ -56,24 +56,25 @@ int unameToUid(const char * thisUname, uid_t * uid) int gnameToGid(const char * thisGname, gid_t * gid) { - /*@only@*/ static char * lastGname = NULL; - static int lastGnameLen = 0; - static int lastGnameAlloced; - static uid_t lastGid; - int thisGnameLen; +/*@only@*/ static char * lastGname = NULL; + static size_t lastGnameLen = 0; + static size_t lastGnameAlloced; + static gid_t lastGid; + size_t thisGnameLen; struct group * grent; - if (!thisGname) { + if (thisGname == NULL) { lastGnameLen = 0; return -1; - } else if (!strcmp(thisGname, "root")) { + } else if (strcmp(thisGname, "root") == 0) { *gid = 0; return 0; } thisGnameLen = strlen(thisGname); - if (!lastGname || thisGnameLen != lastGnameLen || - strcmp(thisGname, lastGname)) { + if (lastGname == NULL || thisGnameLen != lastGnameLen || + strcmp(thisGname, lastGname) != 0) + { if (lastGnameAlloced < thisGnameLen + 1) { lastGnameAlloced = thisGnameLen + 10; lastGname = xrealloc(lastGname, lastGnameAlloced); /* XXX memory leak */ @@ -81,10 +82,10 @@ int gnameToGid(const char * thisGname, gid_t * gid) strcpy(lastGname, thisGname); grent = getgrnam(thisGname); - if (!grent) { + if (grent == NULL) { endgrent(); grent = getgrnam(thisGname); - if (!grent) return -1; + if (grent == NULL) return -1; } lastGid = grent->gr_gid; } @@ -96,22 +97,22 @@ int gnameToGid(const char * thisGname, gid_t * gid) char * uidToUname(uid_t uid) { - static int lastUid = -1; - /*@only@*/ static char * lastUname = NULL; - static int lastUnameLen = 0; - struct passwd * pwent; - int len; + static uid_t lastUid = (uid_t) -1; +/*@only@*/ static char * lastUname = NULL; + static size_t lastUnameLen = 0; if (uid == (uid_t) -1) { - lastUid = -1; + lastUid = (uid_t) -1; return NULL; - } else if (!uid) { + } else if (uid == (uid_t) 0) { return "root"; } else if (uid == lastUid) { return lastUname; } else { - pwent = getpwuid(uid); - if (!pwent) return NULL; + struct passwd * pwent = getpwuid(uid); + size_t len; + + if (pwent == NULL) return NULL; lastUid = uid; len = strlen(pwent->pw_name); @@ -127,22 +128,22 @@ char * uidToUname(uid_t uid) char * gidToGname(gid_t gid) { - static int lastGid = -1; - /*@only@*/ static char * lastGname = NULL; - static int lastGnameLen = 0; - struct group * grent; - int len; + static gid_t lastGid = (gid_t) -1; +/*@only@*/ static char * lastGname = NULL; + static size_t lastGnameLen = 0; if (gid == (gid_t) -1) { - lastGid = -1; + lastGid = (gid_t) -1; return NULL; - } else if (!gid) { + } else if (gid == (gid_t) 0) { return "root"; } else if (gid == lastGid) { return lastGname; } else { - grent = getgrgid(gid); - if (!grent) return NULL; + struct group * grent = getgrgid(gid); + size_t len; + + if (grent == NULL) return NULL; lastGid = gid; len = strlen(grent->gr_name); |