1 /* opkg_utils.c - the opkg package management system
5 Copyright (C) 2002 Compaq Computer Corporation
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
19 #include <sys/statvfs.h>
21 #include "libbb/libbb.h"
23 unsigned long get_available_kbytes(char *filesystem)
27 if (statvfs(filesystem, &f) == -1) {
28 opkg_perror(ERROR, "Failed to statvfs for %s", filesystem);
31 // Actually ((sfs.f_bavail * sfs.f_frsize) / 1024)
32 // and here we try to avoid overflow.
33 if (f.f_frsize >= 1024)
34 return (f.f_bavail * (f.f_frsize / 1024));
35 else if (f.f_frsize > 0)
36 return f.f_bavail / (1024 / f.f_frsize);
38 opkg_msg(ERROR, "Unknown block size for target filesystem.\n");
43 /* something to remove whitespace, a hash pooper */
44 char *trim_xstrdup(const char *src)
48 /* remove it from the front */
49 while (src && isspace(*src) && *src)
52 end = src + (strlen(src) - 1);
54 /* and now from the back */
55 while ((end > src) && isspace(*end))
60 /* xstrndup will NULL terminate for us */
61 return xstrndup(src, end - src);
64 int line_is_blank(const char *line)
68 for (s = line; *s; s++) {