X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_utils.c;h=1827094044d6205ea57cb0c01c0b2dd933971970;hp=2bb7c2e476e411d174de146823c6fccb8c986d1f;hb=f0c0a80a795d35550f5c473540d4a78b43b883fc;hpb=99be91a0fdb86a6826a0cdcf8bede14b7d01c9a8 diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index 2bb7c2e..1827094 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -1,7 +1,7 @@ /* opkg_utils.c - the opkg package management system Steven M. Ayer - + Copyright (C) 2002 Compaq Computer Corporation This program is free software; you can redistribute it and/or @@ -15,118 +15,60 @@ General Public License for more details. */ -#include "includes.h" -#include #include -#include +#include -#include "opkg_utils.h" -#include "pkg.h" -#include "pkg_hash.h" #include "libbb/libbb.h" +#include "opkg_utils.h" -void print_pkg_status(pkg_t * pkg, FILE * file); - -long unsigned int get_available_blocks(char * filesystem) -{ - struct statfs sfs; - - if(statfs(filesystem, &sfs)){ - fprintf(stderr, "bad statfs\n"); - return 0; - } - /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ - - // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024) - // and here we try to avoid overflow. - if (sfs.f_bsize >= 1024) - return (sfs.f_bavail * (sfs.f_bsize / 1024)); - else if (sfs.f_bsize > 0) - return sfs.f_bavail / (1024 / sfs.f_bsize); - fprintf(stderr, "bad statfs f_bsize == 0\n"); - return 0; -} - -/* something to remove whitespace, a hash pooper */ -char *trim_xstrdup(const char *src) +unsigned long get_available_kbytes(char *filesystem) { - const char *end; - - /* remove it from the front */ - while(src && - isspace(*src) && - *src) - src++; - - end = src + (strlen(src) - 1); + struct statvfs f; - /* and now from the back */ - while((end > src) && - isspace(*end)) - end--; + if (statvfs(filesystem, &f) == -1) { + opkg_perror(ERROR, "Failed to statvfs for %s", filesystem); + return 0; + } + // Actually ((sfs.f_bavail * sfs.f_frsize) / 1024) + // and here we try to avoid overflow. + if (f.f_frsize >= 1024) + return (f.f_bavail * (f.f_frsize / 1024)); + else if (f.f_frsize > 0) + return f.f_bavail / (1024 / f.f_frsize); - end++; + opkg_msg(ERROR, "Unknown block size for target filesystem.\n"); - /* xstrndup will NULL terminate for us */ - return xstrndup(src, end-src); + return 0; } -int line_is_blank(const char *line) +/* something to remove whitespace, a hash pooper */ +char *trim_xstrdup(const char *src) { - const char *s; + const char *end; - for (s = line; *s; s++) { - if (!isspace(*s)) - return 0; - } - return 1; -} + /* remove it from the front */ + while (src && isspace(*src) && *src) + src++; -static struct errlist *error_list_head, *error_list_tail; + end = src + (strlen(src) - 1); -/* - * XXX: this function should not allocate memory as it may be called to - * print an error because we are out of memory. - */ -void push_error_list(char * msg) -{ - struct errlist *e; + /* and now from the back */ + while ((end > src) && isspace(*end)) + end--; - e = xcalloc(1, sizeof(struct errlist)); - e->errmsg = xstrdup(msg); - e->next = NULL; + end++; - if (error_list_head) { - error_list_tail->next = e; - error_list_tail = e; - } else { - error_list_head = error_list_tail = e; - } + /* xstrndup will NULL terminate for us */ + return xstrndup(src, end - src); } -void free_error_list(void) +int line_is_blank(const char *line) { - struct errlist *err, *err_tmp; - - err = error_list_head; - while (err != NULL) { - free(err->errmsg); - err_tmp = err; - err = err->next; - free(err_tmp); - } -} + const char *s; -void print_error_list (void) -{ - struct errlist *err = error_list_head; - - if (err) { - printf ("Collected errors:\n"); - /* Here we print the errors collected and free the list */ - while (err != NULL) { - printf (" * %s", err->errmsg); - err = err->next; - } + for (s = line; *s; s++) { + if (!isspace(*s)) + return 0; } + return 1; }