diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-04-28 15:57:32 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-04-28 15:57:32 +0300 |
commit | 1b61e468ad75e86bf75d34e78d7f59ca1b5e26a6 (patch) | |
tree | 44b23c839c6069928e50a045092baef858ca91b1 /build/files.c | |
parent | ea60f8ccb7de9302b84f2e8578ece00570756553 (diff) | |
download | librpm-tizen-1b61e468ad75e86bf75d34e78d7f59ca1b5e26a6.tar.gz librpm-tizen-1b61e468ad75e86bf75d34e78d7f59ca1b5e26a6.tar.bz2 librpm-tizen-1b61e468ad75e86bf75d34e78d7f59ca1b5e26a6.zip |
parseForAttr() tweaks
- streamline exit paths a bit
- replace alloca() with xmalloc()
- avoid messing q value while checking for white space
- return rpmRC like the others
Diffstat (limited to 'build/files.c')
-rw-r--r-- | build/files.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/build/files.c b/build/files.c index 865bfd280..fa5a7d6e8 100644 --- a/build/files.c +++ b/build/files.c @@ -464,14 +464,15 @@ exit: * @param fl package file tree walk data * @return 0 on success */ -static int parseForAttr(const char * buf, FileList fl) +static rpmRC parseForAttr(const char * buf, FileList fl) { const char *name; - char *p, *pe, *q; + char *p, *pe, *q = NULL; int x; struct AttrRec_s arbuf; AttrRec ar = &arbuf, ret_ar; specdFlags * specdFlags; + rpmRC rc = RPMRC_FAIL; if ((p = strstr(buf, (name = "%attr"))) != NULL) { ret_ar = &(fl->cur_ar); @@ -480,7 +481,7 @@ static int parseForAttr(const char * buf, FileList fl) ret_ar = &(fl->def_ar); specdFlags = &fl->defSpecdFlags; } else - return 0; + return RPMRC_OK; for (pe = p; (pe-p) < strlen(name); pe++) *pe = ' '; @@ -489,8 +490,7 @@ static int parseForAttr(const char * buf, FileList fl) if (*pe != '(') { rpmlog(RPMLOG_ERR, _("Missing '(' in %s %s\n"), name, pe); - fl->processingFailed = 1; - return RPMRC_FAIL; + goto exit; } /* Bracket %*attr args */ @@ -499,19 +499,18 @@ static int parseForAttr(const char * buf, FileList fl) {}; if (ret_ar == &(fl->def_ar)) { /* %defattr */ - q = pe; - q++; + char *r = pe; + r++; SKIPSPACE(q); - if (*q != '\0') { + if (*r != '\0') { rpmlog(RPMLOG_ERR, - _("Non-white space follows %s(): %s\n"), name, q); - fl->processingFailed = 1; - return RPMRC_FAIL; + _("Non-white space follows %s(): %s\n"), name, r); + goto exit; } } /* Localize. Erase parsed string */ - q = alloca((pe-p) + 1); + q = xmalloc((pe-p) + 1); rstrlcpy(q, p, (pe-p) + 1); while (p <= pe) *p++ = ' '; @@ -542,8 +541,7 @@ static int parseForAttr(const char * buf, FileList fl) if (!(ar->ar_fmodestr && ar->ar_user && ar->ar_group) || *p != '\0') { rpmlog(RPMLOG_ERR, _("Bad syntax: %s(%s)\n"), name, q); - fl->processingFailed = 1; - return RPMRC_FAIL; + goto exit; } /* Do a quick test on the mode argument and adjust for "-" */ @@ -552,8 +550,7 @@ static int parseForAttr(const char * buf, FileList fl) x = sscanf(ar->ar_fmodestr, "%o", &ui); if ((x == 0) || (ar->ar_fmode & ~MYALLPERMS)) { rpmlog(RPMLOG_ERR, _("Bad mode spec: %s(%s)\n"), name, q); - fl->processingFailed = 1; - return RPMRC_FAIL; + goto exit; } ar->ar_fmode = ui; } else @@ -564,8 +561,7 @@ static int parseForAttr(const char * buf, FileList fl) x = sscanf(ar->ar_dmodestr, "%o", &ui); if ((x == 0) || (ar->ar_dmode & ~MYALLPERMS)) { rpmlog(RPMLOG_ERR, _("Bad dirmode spec: %s(%s)\n"), name, q); - fl->processingFailed = 1; - return RPMRC_FAIL; + goto exit; } ar->ar_dmode = ui; } else @@ -581,8 +577,15 @@ static int parseForAttr(const char * buf, FileList fl) /* XXX fix all this */ *specdFlags |= SPECD_UID | SPECD_GID | SPECD_FILEMODE | SPECD_DIRMODE; + rc = RPMRC_OK; + +exit: + free(q); + if (rc != RPMRC_OK) { + fl->processingFailed = 1; + } - return 0; + return rc; } /** |