1 /* opkg_utils.c - the itsy 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"
27 void print_pkg_status(pkg_t * pkg, FILE * file);
29 int get_available_blocks(char * filesystem)
33 if(statfs(filesystem, &sfs)){
34 fprintf(stderr, "bad statfs\n");
37 /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
38 return ((sfs.f_bavail * sfs.f_bsize) / 1024);
41 char **read_raw_pkgs_from_file(const char *file_name)
46 if(!(fp = fopen(file_name, "r"))){
47 fprintf(stderr, "can't get %s open for read\n", file_name);
51 ret = read_raw_pkgs_from_stream(fp);
58 char **read_raw_pkgs_from_stream(FILE *fp)
60 char **raw = NULL, *buf, *scout;
66 while (fgets(buf, size, fp)) {
67 while (strlen (buf) == (size - 1)
68 && buf[size-2] != '\n') {
71 buf = realloc (buf, size);
72 if (fgets (buf + o, size - o, fp) == NULL)
77 raw = realloc(raw, (count + 50) * sizeof(char *));
79 if((scout = strchr(buf, '\n')))
82 raw[count++] = strdup(buf);
85 raw = realloc(raw, (count + 1) * sizeof(char *));
93 /* something to remove whitespace, a hash pooper */
94 char *trim_alloc(char *line)
97 char *dest, *src, *end;
99 new = malloc(strlen(line) + 1);
101 fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
104 dest = new, src = line, end = line + (strlen(line) - 1);
106 /* remove it from the front */
111 /* and now from the back */
118 /* this does from the first space
119 * blasting away any versions stuff in depends
130 int line_is_blank(const char *line)
134 for (s = line; *s; s++) {
141 void push_error_list(struct errlist ** errors, char * msg){
142 struct errlist *err_lst_tmp;
145 err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
146 err_lst_tmp->errmsg=strdup(msg) ;
147 err_lst_tmp->next = *errors;
148 *errors = err_lst_tmp;
152 void reverse_error_list(struct errlist **errors){
153 struct errlist *result=NULL;
154 struct errlist *current= *errors;
155 struct errlist *next;
157 while ( current != NULL ) {
158 next = current->next;
159 current->next=result;
168 void free_error_list(){
169 struct errlist *err_tmp_lst;
171 err_tmp_lst = error_list;
173 while (err_tmp_lst != NULL) {
174 free(err_tmp_lst->errmsg);
175 err_tmp_lst = error_list->next;
177 error_list = err_tmp_lst;