X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-files.c;h=503a84bdd73940a31c9c37870aecf3d6d94c65b0;hb=3a6e947bef1b2942e24d2fdee1a76dbf3305b508;hp=8840fa90ccfaef8681b66c18a6d072066352ea0a;hpb=9ab266df6642c6e930e03b3024d7c3d53ef88bbc;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-files.c b/src/wgtpkg-files.c index 8840fa9..503a84b 100644 --- a/src/wgtpkg-files.c +++ b/src/wgtpkg-files.c @@ -1,5 +1,7 @@ /* - Copyright 2015 IoT.bzh + Copyright 2015, 2016, 2017 IoT.bzh + + author: José Bollo Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,12 +20,15 @@ #include #include #include -#include #include #include #include +#include +#include -#include "wgtpkg.h" +#include "verbose.h" +#include "wgtpkg-workdir.h" +#include "wgtpkg-files.h" struct fdb { unsigned int count; @@ -53,7 +58,7 @@ static unsigned int what_signature(const char *name) while ('0' <= name[len] && name[len] <= '9') { nid = 10 * id + (unsigned int)(name[len++] - '0'); if (nid < id || nid == UINT_MAX) { - syslog(LOG_WARNING, "number too big for %s", name); + WARNING("number too big for %s", name); return 0; } id = nid; @@ -94,7 +99,7 @@ static struct filedesc *get_filedesc(const char *name, int create) /* allocations */ grow = realloc(allfiles.files, (allfiles.count + 1) * sizeof(struct filedesc *)); if (grow == NULL) { - syslog(LOG_ERR, "realloc failed in get_filedesc"); + ERROR("realloc failed in get_filedesc"); return NULL; } allfiles.files = grow; @@ -102,7 +107,7 @@ static struct filedesc *get_filedesc(const char *name, int create) if (sig) { grow = realloc(allsignatures.files, (allsignatures.count + 1) * sizeof(struct filedesc *)); if (grow == NULL) { - syslog(LOG_ERR, "second realloc failed in get_filedesc"); + ERROR("second realloc failed in get_filedesc"); return NULL; } allsignatures.files = grow; @@ -110,7 +115,7 @@ static struct filedesc *get_filedesc(const char *name, int create) result = malloc(sizeof(struct filedesc) + strlen(name)); if (!result) { - syslog(LOG_ERR, "calloc failed in get_filedesc"); + ERROR("calloc failed in get_filedesc"); return NULL; } @@ -148,7 +153,7 @@ static struct filedesc *file_add(const char *name, enum entrytype type) else if (desc->type == type_unset) desc->type = type; else { - syslog(LOG_ERR, "redeclaration of %s in file_add", name); + ERROR("redeclaration of %s in file_add", name); errno = EEXIST; desc = NULL; } @@ -227,7 +232,7 @@ struct filedesc *create_signature(unsigned int number) len = asprintf(&name, "%s%u%s", distributor_file_prefix, number, distributor_file_suffix); if (len < 0) - syslog(LOG_ERR, "asprintf failed in create_signature"); + ERROR("asprintf failed in create_signature"); else { assert(len > 0); result = file_of_name(name); @@ -247,20 +252,21 @@ void file_clear_flags() allfiles.files[i]->flags &= flag_signature; } -static int fill_files_rec(char name[PATH_MAX], int offset) +static int fill_files_rec(char name[PATH_MAX], unsigned offset) { - int len, err, fd; + int err, fd; + unsigned len; DIR *dir; struct dirent *ent; fd = openat(workdirfd, offset ? name : ".", O_DIRECTORY|O_RDONLY); if (fd < 0) { - syslog(LOG_ERR, "openat %.*s failed in fill_files_rec", offset, name); + ERROR("openat %.*s failed in fill_files_rec", offset, name); return -1; } dir = fdopendir(fd); if (!dir) { - syslog(LOG_ERR, "opendir %.*s failed in fill_files_rec", offset, name); + ERROR("opendir %.*s failed in fill_files_rec", offset, name); close(fd); return -1; } @@ -269,13 +275,13 @@ static int fill_files_rec(char name[PATH_MAX], int offset) ent = readdir(dir); while (ent != NULL) { - len = strlen(ent->d_name); + len = (unsigned)strlen(ent->d_name); if (ent->d_name[0] == '.' && (len == 1 || (ent->d_name[1] == '.' && len == 2))) ; else if (offset + len >= PATH_MAX) { closedir(dir); - syslog(LOG_ERR, "name too long in fill_files_rec"); + ERROR("name too long in fill_files_rec"); errno = ENAMETOOLONG; return -1; } else {