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.
23 #include "opkg_utils.h"
26 #include "libbb/libbb.h"
28 void print_pkg_status(pkg_t
* pkg
, FILE * file
);
30 long unsigned int get_available_blocks(char * filesystem
)
34 if(statfs(filesystem
, &sfs
)){
35 fprintf(stderr
, "bad statfs\n");
38 /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
40 // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024)
41 // and here we try to avoid overflow.
42 if (sfs
.f_bsize
>= 1024)
43 return (sfs
.f_bavail
* (sfs
.f_bsize
/ 1024));
44 else if (sfs
.f_bsize
> 0)
45 return sfs
.f_bavail
/ (1024 / sfs
.f_bsize
);
46 fprintf(stderr
, "bad statfs f_bsize == 0\n");
50 /* something to remove whitespace, a hash pooper */
51 char *trim_alloc(const char *src
)
55 /* remove it from the front */
61 end
= src
+ (strlen(src
) - 1);
63 /* and now from the back */
70 /* xstrndup will NULL terminate for us */
71 return xstrndup(src
, end
-src
);
74 int line_is_blank(const char *line
)
78 for (s
= line
; *s
; s
++) {
85 static struct errlist
*error_list_head
, *error_list_tail
;
88 * XXX: this function should not allocate memory as it may be called to
89 * print an error because we are out of memory.
91 void push_error_list(char * msg
)
95 e
= xcalloc(1, sizeof(struct errlist
));
96 e
->errmsg
= xstrdup(msg
);
99 if (error_list_head
) {
100 error_list_tail
->next
= e
;
103 error_list_head
= error_list_tail
= e
;
107 void free_error_list(void)
109 struct errlist
*err
, *err_tmp
;
111 err
= error_list_head
;
112 while (err
!= NULL
) {
120 void print_error_list (void)
122 struct errlist
*err
= error_list_head
;
125 printf ("Collected errors:\n");
126 /* Here we print the errors collected and free the list */
127 while (err
!= NULL
) {
128 printf (" * %s", err
->errmsg
);