From: Ingo Weinhold Date: Mon, 11 Jul 2011 20:36:06 +0000 (+0000) Subject: Make more C89 and POSIX compliant X-Git-Tag: BASE-SuSE-Code-12_2-Branch~192 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b0d7883a182851bee1f5d67164d747ba00e4d6d;p=platform%2Fupstream%2Flibsolv.git Make more C89 and POSIX compliant --- diff --git a/ext/pool_fileconflicts.c b/ext/pool_fileconflicts.c index b835790..cff0ef9 100644 --- a/ext/pool_fileconflicts.c +++ b/ext/pool_fileconflicts.c @@ -361,8 +361,9 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo /* unify */ for (i = j = 0; i < cbdata.lookat.count; i += 2) { + Id idx; hx = cbdata.lookat.elements[i]; - Id idx = cbdata.lookat.elements[i + 1]; + idx = cbdata.lookat.elements[i + 1]; if (j && hx == cbdata.lookat.elements[j - 2] && idx == cbdata.lookat.elements[j - 1]) continue; cbdata.lookat.elements[j++] = hx; diff --git a/ext/repo_deltainfoxml.c b/ext/repo_deltainfoxml.c index e810b60..775cb01 100644 --- a/ext/repo_deltainfoxml.c +++ b/ext/repo_deltainfoxml.c @@ -552,6 +552,7 @@ repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags) int i, l; struct stateswitch *sw; Repodata *data; + XML_Parser parser; data = repo_add_repodata(repo, flags); @@ -573,7 +574,7 @@ repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags) pd.atemp = 256; pd.ltemp = 0; - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); XML_SetElementHandler(parser, startElement, endElement); XML_SetCharacterDataHandler(parser, characterData); diff --git a/ext/repo_helix.c b/ext/repo_helix.c index a75f693..b7068b2 100644 --- a/ext/repo_helix.c +++ b/ext/repo_helix.c @@ -592,6 +592,7 @@ endElement(void *userData, const char *name) Solvable *s = pd->solvable; Id evr; unsigned int t = 0; + const char *flavor; if (pd->depth != pd->statedepth) { @@ -626,7 +627,7 @@ endElement(void *userData, const char *name) pd->freshens = 0; /* see bugzilla bnc#190163 */ - const char *flavor = findKernelFlavor(pd, s); + flavor = findKernelFlavor(pd, s); if (flavor) { char *cflavor = solv_strdup(flavor); /* make pointer safe */ @@ -815,6 +816,7 @@ repo_add_helix(Repo *repo, FILE *fp, int flags) int i, l; struct stateswitch *sw; unsigned int now; + XML_Parser parser; now = solv_timems(0); data = repo_add_repodata(repo, flags); @@ -842,7 +844,7 @@ repo_add_helix(Repo *repo, FILE *fp, int flags) // set up XML parser - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); /* make parserdata available to XML callbacks */ XML_SetElementHandler(parser, startElement, endElement); XML_SetCharacterDataHandler(parser, characterData); diff --git a/ext/repo_products.c b/ext/repo_products.c index 69edca3..cf76050 100644 --- a/ext/repo_products.c +++ b/ext/repo_products.c @@ -398,6 +398,7 @@ add_code11_product(struct parsedata *pd, FILE *fp) char buf[BUFF_SIZE]; int l; struct stat st; + XML_Parser parser; if (!fstat(fileno(fp), &st)) { @@ -411,7 +412,7 @@ add_code11_product(struct parsedata *pd, FILE *fp) pd->ctime = 0; } - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, pd); XML_SetElementHandler(parser, startElement, endElement); XML_SetCharacterDataHandler(parser, characterData); @@ -475,10 +476,11 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags) while ((entry = readdir(dir))) { int len = strlen(entry->d_name); + FILE *fp; if (len <= 5 || strcmp(entry->d_name + len - 5, ".prod") != 0) continue; fullpath = join2(dirpath, "/", entry->d_name); - FILE *fp = fopen(fullpath, "r"); + fp = fopen(fullpath, "r"); if (!fp) { perror(fullpath); diff --git a/ext/repo_repomdxml.c b/ext/repo_repomdxml.c index 87510dd..7bff1ec 100644 --- a/ext/repo_repomdxml.c +++ b/ext/repo_repomdxml.c @@ -458,6 +458,7 @@ repo_add_repomdxml(Repo *repo, FILE *fp, int flags) char buf[BUFF_SIZE]; int i, l; struct stateswitch *sw; + XML_Parser parser; data = repo_add_repodata(repo, flags); @@ -476,7 +477,7 @@ repo_add_repomdxml(Repo *repo, FILE *fp, int flags) pd.content = malloc(256); pd.acontent = 256; pd.lcontent = 0; - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); pd.parser = &parser; XML_SetElementHandler(parser, startElement, endElement); diff --git a/ext/repo_rpmmd.c b/ext/repo_rpmmd.c index 03bfb04..856f7c8 100644 --- a/ext/repo_rpmmd.c +++ b/ext/repo_rpmmd.c @@ -641,6 +641,7 @@ startElement(void *userData, const char *name, const char **atts) struct stateswitch *sw; const char *str; Id handle = pd->handle; + const char *pkgid; // fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth); @@ -704,7 +705,6 @@ startElement(void *userData, const char *name, const char **atts) a new solvable but just append the attributes to the existing one. */ - const char *pkgid; if ((pkgid = find_attr("pkgid", atts)) != NULL) { // look at the checksum cache @@ -1146,6 +1146,7 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags) struct stateswitch *sw; Repodata *data; unsigned int now; + XML_Parser parser; now = solv_timems(0); data = repo_add_repodata(repo, flags); @@ -1198,7 +1199,7 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags) dataiterator_free(&di); } - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); pd.parser = &parser; XML_SetElementHandler(parser, startElement, endElement); diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index 3f40be5..0e69228 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -120,6 +120,9 @@ add_source(struct parsedata *pd, char *line, Solvable *s, Id handle) Repo *repo = s->repo; Pool *pool = repo->pool; char *sp[5]; + Id name; + Id evr; + Id arch; if (split(line, sp, 5) != 4) { @@ -127,9 +130,9 @@ add_source(struct parsedata *pd, char *line, Solvable *s, Id handle) exit(1); } - Id name = pool_str2id(pool, sp[0], 1); - Id evr = makeevr(pool, join2(sp[1], "-", sp[2])); - Id arch = pool_str2id(pool, sp[3], 1); + name = pool_str2id(pool, sp[0], 1); + evr = makeevr(pool, join2(sp[1], "-", sp[2])); + arch = pool_str2id(pool, sp[3], 1); /* XXX: could record a dep here, depends on where we want to store the data */ if (name == s->name) repodata_set_void(pd->data, handle, SOLVABLE_SOURCENAME); @@ -152,17 +155,20 @@ static void add_dirline(struct parsedata *pd, char *line) { char *sp[6]; + long filesz; + long filenum; + unsigned dirid; if (split(line, sp, 6) != 5) return; pd->dirs = solv_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31); - long filesz = strtol(sp[1], 0, 0); + filesz = strtol(sp[1], 0, 0); filesz += strtol(sp[2], 0, 0); - long filenum = strtol(sp[3], 0, 0); + filenum = strtol(sp[3], 0, 0); filenum += strtol(sp[4], 0, 0); /* hack: we know that there's room for a / */ if (*sp[0] != '/') *--sp[0] = '/'; - unsigned dirid = repodata_str2dir(pd->data, sp[0], 1); + dirid = repodata_str2dir(pd->data, sp[0], 1); #if 0 fprintf(stderr, "%s -> %d\n", sp[0], dirid); #endif diff --git a/ext/repo_updateinfoxml.c b/ext/repo_updateinfoxml.c index 35ea405..1293ad2 100644 --- a/ext/repo_updateinfoxml.c +++ b/ext/repo_updateinfoxml.c @@ -609,6 +609,7 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags) int i, l; struct stateswitch *sw; Repodata *data; + XML_Parser parser; data = repo_add_repodata(repo, flags); @@ -626,7 +627,7 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags) pd.content = malloc(256); pd.acontent = 256; pd.lcontent = 0; - XML_Parser parser = XML_ParserCreate(NULL); + parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); XML_SetElementHandler(parser, startElement, endElement); XML_SetCharacterDataHandler(parser, characterData); diff --git a/ext/repo_write.c b/ext/repo_write.c index 13b632b..0c5628e 100644 --- a/ext/repo_write.c +++ b/ext/repo_write.c @@ -113,13 +113,15 @@ needid_cmp_need_s(const void *ap, const void *bp, void *dp) const NeedId *a = ap; const NeedId *b = bp; Stringpool *spool = dp; + const char *as; + const char *bs; int r; r = b->need - a->need; if (r) return r; - const char *as = spool->stringspace + spool->strings[a->map]; - const char *bs = spool->stringspace + spool->strings[b->map]; + as = spool->stringspace + spool->strings[a->map]; + bs = spool->stringspace + spool->strings[b->map]; return strcmp(as, bs); } @@ -428,6 +430,7 @@ data_addidarray_sort(struct extdata *xd, Pool *pool, NeedId *needid, Id *ids, Id { int len, i; Id lids[64], *sids; + Id id, old; if (!ids) return; @@ -471,7 +474,7 @@ data_addidarray_sort(struct extdata *xd, Pool *pool, NeedId *needid, Id *ids, Id if ((len - i) > 2) solv_sort(sids + i + 1, len - i - 1, sizeof(Id), cmp_ids, 0); - Id id, old = 0; + old = 0; /* The differencing above produces many runs of ones and twos. I tried fairly elaborate schemes to RLE those, but they give only very mediocre @@ -1008,6 +1011,10 @@ repo_write(Repo *repo, FILE *fp, int (*keyfilter)(Repo *repo, Repokey *key, void Id type_constantid = REPOKEY_TYPE_CONSTANTID; + unsigned char *prefixcomp; + unsigned int compsum; + char *old_str; + memset(&cbdata, 0, sizeof(cbdata)); cbdata.repo = repo; @@ -1724,9 +1731,9 @@ fprintf(stderr, "dir %d used %d\n", i, cbdata.dirused ? cbdata.dirused[i] : 1); /* * calculate prefix encoding of the strings */ - unsigned char *prefixcomp = solv_malloc(nstrings); - unsigned int compsum = 0; - char *old_str = ""; + prefixcomp = solv_malloc(nstrings); + compsum = 0; + old_str = ""; prefixcomp[0] = 0; for (i = 1; i < nstrings; i++) diff --git a/src/repodata.c b/src/repodata.c index 5790f30..2a9fcba 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -2502,8 +2502,9 @@ repodata_serialize_key(Repodata *data, struct extdata *newincore, schemaid = 0; for (ida = data->attriddata + val; *ida; ida++) { + Id *kp; sp = schema; - Id *kp = data->xattrs[-*ida]; + kp = data->xattrs[-*ida]; if (!kp) continue; num++; diff --git a/src/repopage.c b/src/repopage.c index f9cd514..0ad5323 100644 --- a/src/repopage.c +++ b/src/repopage.c @@ -21,6 +21,7 @@ #define _XOPEN_SOURCE 500 #include +#include #include #include #include @@ -36,9 +37,9 @@ #define BLOCK_SIZE (65536*1) #if BLOCK_SIZE <= 65536 -typedef __uint16_t Ref; +typedef uint16_t Ref; #else -typedef __uint32_t Ref; +typedef uint32_t Ref; #endif /* @@ -95,9 +96,9 @@ compress_buf(const unsigned char *in, unsigned int in_len, #define HS (65536) Ref htab[HS]; Ref hnext[BLOCK_SIZE]; + unsigned int litofs = 0; memset(htab, -1, sizeof (htab)); memset(hnext, -1, sizeof (hnext)); - unsigned int litofs = 0; while (io + 2 < in_len) { /* Search for a match of the string starting at IN, we have at @@ -228,8 +229,9 @@ match_done: { if (litofs) { + unsigned litlen; litofs--; - unsigned litlen = io - litofs; + litlen = io - litofs; /* fprintf(stderr, "lit: %d\n", litlen); */ while (litlen) { @@ -351,8 +353,9 @@ match_done: io = in_len; if (litofs) { + unsigned litlen; litofs--; - unsigned litlen = io - litofs; + litlen = io - litofs; /* fprintf(stderr, "lit: %d\n", litlen); */ while (litlen) { @@ -608,8 +611,12 @@ repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigne /* Now search for "cheap" space in our store. Space is cheap if it's either free (very cheap) or contains pages we search for anyway. */ + { /* Setup cost array. */ unsigned int cost[store->ncanmap]; + unsigned int best_cost; + unsigned int best; + unsigned int same_cost; for (i = 0; i < store->ncanmap; i++) { unsigned int pnum = store->mapped[i]; @@ -617,8 +624,9 @@ repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigne cost[i] = 0; else { + Attrblobpage *p; pnum--; - Attrblobpage *p = store->pages + pnum; + p = store->pages + pnum; assert(p->mapped_at != -1); if (pnum >= pstart && pnum <= pend) cost[i] = 1; @@ -628,9 +636,9 @@ repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigne } /* And search for cheapest space. */ - unsigned int best_cost = -1; - unsigned int best = 0; - unsigned int same_cost = 0; + best_cost = -1; + best = 0; + same_cost = 0; for (i = 0; i + pend - pstart < store->ncanmap; i++) { unsigned int c = cost[i]; @@ -728,6 +736,7 @@ repopagestore_load_page_range(Repopagestore *store, unsigned int pstart, unsigne store->mapped[pnum] = i + 1; } return store->blob_store + best * REPOPAGE_BLOBSIZE; + } } unsigned int diff --git a/src/rules.c b/src/rules.c index df6a9b6..e90714e 100644 --- a/src/rules.c +++ b/src/rules.c @@ -2107,9 +2107,10 @@ solver_addchoicerules(Solver *solv) MAPSET(&m, p); for (i = 0; i < qi.count; i++) { + Rule *ur; if (!qi.elements[i]) continue; - Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start); + ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start); if (!ur->p) ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start); if (!ur->p) diff --git a/src/sha2.c b/src/sha2.c index 06986f8..0af1c85 100644 --- a/src/sha2.c +++ b/src/sha2.c @@ -36,7 +36,6 @@ #include /* memcpy()/memset() or bcopy()/bzero() */ /* #include */ /* assert() */ #include -#include #include #include #include diff --git a/tools/common_write.c b/tools/common_write.c index 7cd6783..ba45e6f 100644 --- a/tools/common_write.c +++ b/tools/common_write.c @@ -310,8 +310,9 @@ tool_write(Repo *repo, const char *basename, const char *attrname) } if (attrname) { + FILE *fp; test_separate = 1; - FILE *fp = fopen(attrname, "w"); + fp = fopen(attrname, "w"); write_info(repo, fp, keyfilter_attr, 0, info, attrname); fclose(fp); kd.haveexternal = 1; diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index 64a9a79..23ceaa3 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -180,9 +180,10 @@ loadcallback (Pool *pool, Repodata *data, void *vdata) { FILE *fp = 0; int r; + const char *location; printf("LOADCALLBACK\n"); - const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION); + location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION); printf("loc %s\n", location); if (!location || !with_attr) return 0; diff --git a/tools/installcheck.c b/tools/installcheck.c index 558267f..8e1dc09 100644 --- a/tools/installcheck.c +++ b/tools/installcheck.c @@ -49,6 +49,7 @@ main(int argc, char **argv) { Pool *pool; Solver *solv; + Repo *repo; Queue job; Queue rids; Queue cand; @@ -110,7 +111,7 @@ main(int argc, char **argv) perror(argv[i]); exit(1); } - Repo *repo = repo_create(pool, argv[i]); + repo = repo_create(pool, argv[i]); #ifndef DEBIAN if (l >= 8 && !strcmp(argv[i] + l - 8, "packages")) { diff --git a/tools/patchcheck.c b/tools/patchcheck.c index 1414a2b..9ffdcb6 100644 --- a/tools/patchcheck.c +++ b/tools/patchcheck.c @@ -488,6 +488,7 @@ main(int argc, char **argv) Id pid, p, pp; int tests = 0; context_t c; + static const char* langs[] = {"en"}; c.install_available = 0; c.updatestart = 0; @@ -499,7 +500,6 @@ main(int argc, char **argv) arch = argv[1]; pool = pool_create(); pool_setarch(pool, arch); - static const char* langs[] = {"en"}; pool_set_languages(pool, langs, 1); #if 0 @@ -570,8 +570,9 @@ main(int argc, char **argv) for (pid = 1; pid < pool->nsolvables; pid++) { + Solvable *s; c.shown = 0; - Solvable *s = pool->solvables + pid; + s = pool->solvables + pid; if (!s->repo) continue; if (!pool_installable(pool, s)) diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index 20a4b98..9344791 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -67,6 +67,8 @@ main(int argc, char **argv) Id defvendor = 0; int flags = 0; int c; + Pool *pool; + Repo *repo; while ((c = getopt(argc, argv, "hn:c:d:b:q:")) >= 0) { @@ -95,8 +97,8 @@ main(int argc, char **argv) break; } } - Pool *pool = pool_create(); - Repo *repo = repo_create(pool, ""); + pool = pool_create(); + repo = repo_create(pool, ""); repo_add_repodata(repo, 0); @@ -170,8 +172,9 @@ main(int argc, char **argv) if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz")) { + FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); - FILE *fp = solv_xfopen(fnp, 0); + fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); @@ -182,8 +185,9 @@ main(int argc, char **argv) } else if (!strcmp(fn, "packages.DU") || !strcmp(fn, "packages.DU.gz")) { + FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); - FILE *fp = solv_xfopen(fnp, 0); + fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); @@ -213,6 +217,7 @@ main(int argc, char **argv) { char lang[6]; char *p; + FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); p = strrchr(fnp, '.'); if (p && !strcmp(p, ".gz")) @@ -224,7 +229,7 @@ main(int argc, char **argv) continue; strcpy(lang, p + 1); sprintf(fnp, "%s/%s", descrdir, fn); - FILE *fp = solv_xfopen(fnp, 0); + fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn);