aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/action.c13
-rw-r--r--src/configuration.c95
-rw-r--r--src/configuration.h2
-rw-r--r--src/curl.c30
-rw-r--r--src/main.c2
-rw-r--r--src/package.c137
-rw-r--r--src/package.h2
8 files changed, 159 insertions, 124 deletions
diff --git a/ChangeLog b/ChangeLog
index 5850ab5..ef64579 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,5 @@
-0.8 Sep 03, 2003
+0.8 Sep 07, 2003
* --remove target now accepts multiple arguments
( --remove pkg1 pkg2 pkg3 pkg4 )
* --upgrade speed improvement (optimizations)
diff --git a/src/action.c b/src/action.c
index 4ed657d..ff8c178 100644
--- a/src/action.c
+++ b/src/action.c
@@ -151,7 +151,8 @@ void jaospkg_search(const char *pattern){
/* show the details for a specific package */
void jaospkg_show(const char *pkg_name){
pkg_info *pkg;
- if( (pkg = lookup_pkg(pkg_name)) != NULL ){
+ pkg = lookup_pkg(pkg_name);
+ if( pkg != NULL ){
printf("Package Name: %s\n",pkg->name);
printf("Package Location: %s\n",pkg->location);
printf("Package version: %s\n",pkg->version);
@@ -215,11 +216,11 @@ void jaospkg_upgrade(const rc_config *global_config,pkg_info *installed_pkg){
/* use jaospkg_upgrade() soon, pass in pkg_list(s) */
void jaospkg_upgrade_all(const rc_config *global_config){
int iterator;
- struct pkg_list *installed_pkgs = NULL;
- struct pkg_list *update_pkgs = NULL;
- struct pkg_list *current_pkgs = NULL;
- pkg_info *update_pkg = NULL;
- pkg_info *current_pkg = NULL;
+ struct pkg_list *installed_pkgs;
+ struct pkg_list *update_pkgs;
+ struct pkg_list *current_pkgs;
+ pkg_info *update_pkg;
+ pkg_info *current_pkg;
/* faster here to retrieve the listings once */
/* then use get_newest_pkg() to pull newest from each list */
diff --git a/src/configuration.c b/src/configuration.c
index d527331..d2a23d4 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -25,7 +25,8 @@ rc_config *read_rc_config(const char *file_name){
char *getline_buffer = NULL;
size_t gb_length = 0;
ssize_t g_size;
- global_config = malloc( 1 * sizeof(rc_config) );
+
+ global_config = malloc( sizeof *global_config );
if( global_config == NULL ){
fprintf(stderr,"Failed to malloc global_config\n");
if( errno ){
@@ -83,6 +84,7 @@ rc_config *read_rc_config(const char *file_name){
}/* end if/else if */
}/* end while */
+ if( getline_buffer ) free(getline_buffer);
if( strcmp(global_config->working_dir,"") == 0 ){
fprintf(stderr,"WORKINGDIR directive not set within %s.\n",file_name);
@@ -205,7 +207,8 @@ struct exclude_list *parse_exclude(char *line){
char *pointer = NULL;
char *buffer = NULL;
int position = 0;
- struct exclude_list *list = malloc( 1 * sizeof(struct exclude_list) );
+ struct exclude_list *list;
+ list = malloc( sizeof *list );
if( list == NULL ){
fprintf(stderr,"Failed to malloc list\n");
if( errno ){
@@ -251,15 +254,6 @@ struct exclude_list *parse_exclude(char *line){
return list;
}
-void free_excludes(struct exclude_list *list){
- int i;
- for(i=0;i < list->count;i++){
- free(list->excludes[i]);
- }
- free(list->excludes);
- free(list);
-}
-
int is_excluded(const rc_config *global_config,const char *pkg_name){
int i;
@@ -283,3 +277,82 @@ int is_excluded(const rc_config *global_config,const char *pkg_name){
return 0;
}
+
+/* recursively create dirs */
+void create_dir_structure(const char *dir_name){
+ char *pointer = NULL;
+ char *cwd = NULL;
+ int position = 0;
+ char *dir_name_buffer = NULL;
+
+ cwd = getcwd(NULL,0);
+ if( cwd == NULL ){
+ fprintf(stderr,"Failed to get cwd\n");
+ exit(1);
+ }
+
+ while( position < (int) strlen(dir_name) ){
+ /* if no more directory delim, then this must be last dir */
+ if( strstr(dir_name + position,"/" ) == NULL ){
+
+ /* pointer = dir_name + position; */
+ dir_name_buffer = calloc( strlen(dir_name + position) + 1 , sizeof(char) );
+ memcpy(dir_name_buffer,dir_name + position,strlen(dir_name + position));
+ dir_name_buffer[ strlen(dir_name + position) ] = '\0';
+
+ if( strcmp(dir_name_buffer,".") != 0 ){
+ if( (mkdir(dir_name_buffer,0755)) == -1){
+#if DEBUG == 1
+ fprintf(stderr,"Failed to mkdir: %s\n",dir_name_buffer);
+#endif
+ /* exit(1); */
+ }
+ if( (chdir(dir_name_buffer)) == -1 ){
+ fprintf(stderr,"Failed to chdir to %s\n",dir_name_buffer);
+ exit(1);
+ }
+ }/* don't create . */
+
+ free(dir_name_buffer);
+ break;
+ }else{
+ if( dir_name[position] == '/' ){
+ /* move on ahead */
+ position++;
+ }else{
+
+ /* figure our dir name and mk it */
+ pointer = index(dir_name + position,'/');
+ dir_name_buffer = calloc(
+ strlen(dir_name + position) - strlen(pointer) + 1 , sizeof(char)
+ );
+ memcpy(dir_name_buffer,dir_name + position, strlen(dir_name + position) - strlen(pointer));
+ dir_name_buffer[ (strlen(dir_name + position) - strlen(pointer)) ] = '\0';
+
+ if( strcmp(dir_name_buffer,".") != 0 ){
+ if( (mkdir(dir_name_buffer,0755)) == -1 ){
+#if DEBUG == 1
+ fprintf(stderr,"Failed to mkdir: %s\n",dir_name_buffer);
+#endif
+ /* exit(1); */
+ }
+ if( (chdir(dir_name_buffer)) == -1 ){
+ fprintf(stderr,"Failed to chdir to %s\n",dir_name_buffer);
+ exit(1);
+ }
+ } /* don't create . */
+
+ free(dir_name_buffer);
+ position += (strlen(dir_name + position) - strlen(pointer));
+ }
+ }
+ }/* end while */
+
+ if( (chdir(cwd)) == -1 ){
+ fprintf(stderr,"Failed to chdir to %s\n",cwd);
+ exit(1);
+ }
+
+ free(cwd);
+}
+
diff --git a/src/configuration.h b/src/configuration.h
index c4705f0..44d71eb 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -44,5 +44,5 @@ FILE *open_file(const char *,const char *);
char spinner(void);
void clean_pkg_dir(const char *);
struct exclude_list *parse_exclude(char *);
-void free_excludes(struct exclude_list *);
int is_excluded(const rc_config *,const char *);
+void create_dir_structure(const char *);
diff --git a/src/curl.c b/src/curl.c
index e349029..627f29a 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -48,17 +48,27 @@ FILE *download_pkg_list(const rc_config *global_config){
char *url = NULL;
fh = open_file(PKG_LIST_L,"w+");
+ if( fh == NULL ){
+ fprintf(stderr,"Failed to open package list target\n");
+ exit(1);
+ }
#if USE_CURL_PROGRESS == 0
printf("Retrieving package data...");
#else
printf("Retrieving package data...\n");
#endif
+
url = calloc(
strlen(global_config->mirror_url) + strlen(PKG_LIST) + 1, sizeof(char)
);
- url = memcpy(url,global_config->mirror_url,strlen(global_config->mirror_url) + 1);
- url = strncat(url,PKG_LIST,strlen(PKG_LIST) + 1);
+ if( url == NULL ){
+ fprintf(stderr,"Failed to calloc url\n");
+ exit(1);
+ }
+
+ memcpy(url,global_config->mirror_url,strlen(global_config->mirror_url) );
+ strncat(url,PKG_LIST,strlen(PKG_LIST) );
download_data(fh,url);
#if USE_CURL_PROGRESS == 0
printf("Done\n");
@@ -74,18 +84,28 @@ FILE *download_patches_list(const rc_config *global_config){
char *url = NULL;
fh = open_file(PATCHES_LIST_L,"w+");
+ if( fh == NULL ){
+ fprintf(stderr,"Failed to open patch list target\n");
+ exit(1);
+ }
#if USE_CURL_PROGRESS == 0
printf("Retrieving patch list...");
#else
printf("Retrieving patch list...\n");
#endif
+
url = calloc(
strlen(global_config->mirror_url) + strlen(PATCHDIR) + strlen(PATCHES_LIST) + 1 , sizeof(char)
);
- url = memcpy(url,global_config->mirror_url,strlen(global_config->mirror_url) + 1);
- url = strncat(url,PATCHDIR,strlen(PATCHDIR) + 1);
- url = strncat(url,PATCHES_LIST,strlen(PATCHES_LIST) + 1);
+ if( url == NULL ){
+ fprintf(stderr,"Failed to calloc url\n");
+ exit(1);
+ }
+
+ memcpy(url,global_config->mirror_url,strlen(global_config->mirror_url) );
+ strncat(url,PATCHDIR,strlen(PATCHDIR) );
+ strncat(url,PATCHES_LIST,strlen(PATCHES_LIST) );
download_data(fh,url);
#if USE_CURL_PROGRESS == 0
printf("Done\n");
diff --git a/src/main.c b/src/main.c
index 5a6f4d4..baefa67 100644
--- a/src/main.c
+++ b/src/main.c
@@ -134,7 +134,7 @@ int main( int argc, char *argv[] ){
}
}
- /* free_excludes(global_config->exclude_list); */
+ free(global_config->exclude_list);
free(global_config);
return 0;
}
diff --git a/src/package.c b/src/package.c
index 37ffb01..92840ca 100644
--- a/src/package.c
+++ b/src/package.c
@@ -18,82 +18,6 @@
#include <main.h>
-/* recursively create dirs */
-void create_dir_structure(char *dir_name){
- char *pointer = NULL;
- char *cwd = NULL;
- int position = 0;
- char *dir_name_buffer = NULL;
-
- if( (cwd = getcwd(NULL,0)) == NULL ){
- fprintf(stderr,"Failed to get cwd\n");
- exit(1);
- }
-
- while( position < (int) strlen(dir_name) ){
- /* if no more directory delim, then this must be last dir */
- if( strstr(dir_name + position,"/" ) == NULL ){
-
- pointer = dir_name + position;
- dir_name_buffer = calloc( strlen(pointer) + 1 , sizeof(char) );
- memcpy(dir_name_buffer,pointer,strlen(pointer));
- dir_name_buffer[ strlen(pointer) ] = '\0';
-
- if( strcmp(dir_name_buffer,".") != 0 ){
- if( (mkdir(dir_name_buffer,0755)) == -1){
-#if DEBUG == 1
- fprintf(stderr,"Failed to mkdir: %s\n",dir_name_buffer);
-#endif
- /* exit(1); */
- }
- if( (chdir(dir_name_buffer)) == -1 ){
- fprintf(stderr,"Failed to chdir to %s\n",dir_name_buffer);
- exit(1);
- }
- }/* don't create . */
-
- free(dir_name_buffer);
- break;
- }else{
- if( dir_name[position] == '/' ){
- /* move on ahead */
- position++;
- }else{
-
- /* figure our dir name and mk it */
- pointer = index(dir_name + position,'/');
- dir_name_buffer = calloc(
- strlen(dir_name + position) - strlen(pointer) + 1 , sizeof(char)
- );
- memcpy(dir_name_buffer,dir_name + position, strlen(dir_name + position) - strlen(pointer));
- dir_name_buffer[ (strlen(dir_name + position) - strlen(pointer)) ] = '\0';
-
- if( strcmp(dir_name_buffer,".") != 0 ){
- if( (mkdir(dir_name_buffer,0755)) == -1 ){
-#if DEBUG == 1
- fprintf(stderr,"Failed to mkdir: %s\n",dir_name_buffer);
-#endif
- /* exit(1); */
- }
- if( (chdir(dir_name_buffer)) == -1 ){
- fprintf(stderr,"Failed to chdir to %s\n",dir_name_buffer);
- exit(1);
- }
- } /* don't create . */
-
- free(dir_name_buffer);
- position += (strlen(dir_name + position) - strlen(pointer));
- }
- }
- }/* end while */
-
- if( (chdir(cwd)) == -1 ){
- fprintf(stderr,"Failed to chdir to %s\n",cwd);
- exit(1);
- }
-
-}
-
/* parse the PACKAGES.TXT file */
struct pkg_list *parse_pkg_list(void){
regex_t name_regex, location_regex, size_c_regex, size_u_regex;
@@ -140,13 +64,13 @@ struct pkg_list *parse_pkg_list(void){
/* pkg name base */
memcpy(list->pkgs[list->pkg_count]->name,
- (char *)getline_buffer + pmatch[1].rm_so,
+ getline_buffer + pmatch[1].rm_so,
pmatch[1].rm_eo - pmatch[1].rm_so
);
list->pkgs[list->pkg_count]->name[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';
/* pkg version */
memcpy(list->pkgs[list->pkg_count]->version,
- (char *)getline_buffer + pmatch[2].rm_so,
+ getline_buffer + pmatch[2].rm_so,
pmatch[2].rm_eo - pmatch[2].rm_so
);
list->pkgs[list->pkg_count]->version[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';
@@ -160,7 +84,7 @@ struct pkg_list *parse_pkg_list(void){
if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) ){
if( regexec( &location_regex, getline_buffer, nmatch, pmatch, 0) == 0 ){
memcpy(list->pkgs[list->pkg_count]->location,
- (char *)getline_buffer + pmatch[1].rm_so,
+ getline_buffer + pmatch[1].rm_so,
pmatch[1].rm_eo - pmatch[1].rm_so
);
list->pkgs[list->pkg_count]->location[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';
@@ -181,8 +105,8 @@ struct pkg_list *parse_pkg_list(void){
fprintf(stderr,"Failed to calloc size_c\n");
exit(1);
}
- memcpy(size_c,(char *)getline_buffer + pmatch[1].rm_so,(pmatch[1].rm_eo - pmatch[1].rm_so));
- list->pkgs[list->pkg_count]->size_c = atoi(size_c);
+ memcpy(size_c,getline_buffer + pmatch[1].rm_so,(pmatch[1].rm_eo - pmatch[1].rm_so));
+ list->pkgs[list->pkg_count]->size_c = strtol(size_c, (char **)NULL, 10);
free(size_c);
}else{
fprintf(stderr,"regexec failed to parse size_c\n");
@@ -201,8 +125,8 @@ struct pkg_list *parse_pkg_list(void){
fprintf(stderr,"Failed to calloc size_u\n");
exit(1);
}
- memcpy(size_u,(char *)getline_buffer + pmatch[1].rm_so,(pmatch[1].rm_eo - pmatch[1].rm_so));
- list->pkgs[list->pkg_count]->size_u = atoi(size_u);
+ memcpy(size_u,getline_buffer + pmatch[1].rm_so,(pmatch[1].rm_eo - pmatch[1].rm_so));
+ list->pkgs[list->pkg_count]->size_u = strtol(size_u, (char **)NULL, 10);
free(size_u);
}else{
fprintf(stderr,"regexec failed to parse size_u\n");
@@ -219,6 +143,8 @@ struct pkg_list *parse_pkg_list(void){
&& (strstr(getline_buffer,"PACKAGE DESCRIPTION") != NULL)
){
+ list->pkgs[list->pkg_count]->description[0] = '\0';
+
while( 1 ){
if( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF ){
if( strcmp(getline_buffer,"\n") != 0 ){
@@ -249,6 +175,7 @@ struct pkg_list *parse_pkg_list(void){
/* printf("%c\b",spinner()); this interferes with --list scripting */
continue;
}
+ if( getline_buffer) free(getline_buffer);
fclose(pkg_list_fh);
return list;
@@ -318,6 +245,10 @@ struct pkg_list *get_installed_pkgs(void){
if( ( regexec(&regex,file->d_name,nmatch,pmatch,0) ) == 0 ){
pkg_info *existing_pkg = NULL;
pkg_info *tmp_pkg = calloc( 1 , sizeof(pkg_info) );
+ if( tmp_pkg == NULL ){
+ fprintf(stderr,"Failed to calloc tmp_pkg\n");
+ exit(1);
+ }
memcpy(
@@ -343,7 +274,7 @@ struct pkg_list *get_installed_pkgs(void){
exit(1);
}
memcpy(list->pkgs[list->pkg_count],tmp_pkg,sizeof(pkg_info));
- free(existing_pkg);
+ if( existing_pkg ) free(existing_pkg);
list->pkg_count++;
/* grow our pkgs array */
@@ -424,15 +355,18 @@ struct pkg_list *parse_update_pkg_list(void){
size_t nmatch = MAX_NMATCH;
regmatch_t pmatch[MAX_PMATCH];
char *getline_buffer = NULL;
- struct pkg_list *list = malloc( 1 * sizeof(struct pkg_list) );
+ struct pkg_list *list;
+
+ list = malloc( sizeof *list );
list->pkg_count = 0;
fh = open_file(PATCHES_LIST_L,"r");
regcomp(&regex,PKG_PARSE_REGEX, REG_EXTENDED|REG_NEWLINE);
- if( (list->pkgs = calloc(1 , sizeof(pkg_info *))) == NULL ){
- fprintf(stderr,"Failed to calloc pkgs\n");
+ list->pkgs = malloc( sizeof *list->pkgs );
+ if( list->pkgs == NULL ){
+ fprintf(stderr,"Failed to malloc pkgs\n");
exit(1);
}
@@ -442,8 +376,10 @@ struct pkg_list *parse_update_pkg_list(void){
if( (regexec( &regex, getline_buffer, nmatch, pmatch, 0)) == 0 ){
- if( (list->pkgs[list->pkg_count] = malloc(1 * sizeof(pkg_info))) == NULL ){
- fprintf(stderr,"Failed to malloc list->pkgs[list->pkg_count]\n");
+ /* find out why malloc isn't working here... mem leak somewhere */
+ list->pkgs[list->pkg_count] = calloc( 1 , sizeof(pkg_info) );
+ if( list->pkgs[list->pkg_count] == NULL ){
+ fprintf(stderr,"Failed to calloc list->pkgs[list->pkg_count]\n");
exit(1);
}
@@ -451,29 +387,31 @@ struct pkg_list *parse_update_pkg_list(void){
memcpy( list->pkgs[list->pkg_count]->location, PATCHDIR, strlen(PATCHDIR));
strncat(
list->pkgs[list->pkg_count]->location,
- (char *)getline_buffer + pmatch[1].rm_so,
+ getline_buffer + pmatch[1].rm_so,
pmatch[1].rm_eo - pmatch[1].rm_so
);
list->pkgs[list->pkg_count]->location[
- strlen(list->pkgs[list->pkg_count]->location)
+ strlen(PATCHDIR) + (pmatch[1].rm_eo - pmatch[1].rm_so)
] = '\0';
/* pkg base name */
memcpy(
list->pkgs[list->pkg_count]->name,
- (char *)getline_buffer + pmatch[2].rm_so,
+ getline_buffer + pmatch[2].rm_so,
pmatch[2].rm_eo - pmatch[2].rm_so
);
- list->pkgs[list->pkg_count]->name[ strlen(list->pkgs[list->pkg_count]->name) ] = '\0';
+ list->pkgs[list->pkg_count]->name[
+ pmatch[2].rm_eo - pmatch[2].rm_so
+ ] = '\0';
/* pkg version */
memcpy(
list->pkgs[list->pkg_count]->version,
- (char *)getline_buffer + pmatch[3].rm_so,
+ getline_buffer + pmatch[3].rm_so,
pmatch[3].rm_eo - pmatch[3].rm_so
);
list->pkgs[list->pkg_count]->version[
- strlen(list->pkgs[list->pkg_count]->version)
+ pmatch[3].rm_eo - pmatch[3].rm_so
] = '\0';
/* fill these in */
@@ -493,6 +431,7 @@ struct pkg_list *parse_update_pkg_list(void){
printf("%c\b",spinner());
} /* end while */
+ if( getline_buffer ) free(getline_buffer);
regfree(&regex);
fclose(fh);
return list;
@@ -511,8 +450,9 @@ pkg_info *lookup_pkg(const char *pkg_name){
for(iterator = 0; iterator < pkgs->pkg_count; iterator++ ){
if( strcmp(pkgs->pkgs[iterator]->name,pkg_name) == 0 ){
if( pkg == NULL ){
- if( (pkg = calloc(1 , sizeof(pkg_info))) == NULL ){
- fprintf(stderr,"Failed to callod pkg\n");
+ pkg = malloc( sizeof *pkg );
+ if( pkg == NULL ){
+ fprintf(stderr,"Failed to malloc pkg\n");
exit(0);
}
}
@@ -543,6 +483,7 @@ int install_pkg(const rc_config *global_config,pkg_info *pkg){
/* build and execute our command */
command = calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof(char) );
+ command[0] = '\0';
command = strcat(command,INSTALL_CMD);
command = strcat(command,pkg_file_name);
@@ -585,6 +526,7 @@ int upgrade_pkg(const rc_config *global_config,pkg_info *pkg){
/* build and execute our command */
command = calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof(char) );
+ command[0] = '\0';
command = strcat(command,UPGRADE_CMD);
command = strcat(command,pkg_file_name);
@@ -613,6 +555,7 @@ int remove_pkg(pkg_info *pkg){
/* build and execute our command */
command = calloc( strlen(REMOVE_CMD) + strlen(pkg->name) + 1 , sizeof(char) );
+ command[0] = '\0';
command = strcat(command,REMOVE_CMD);
command = strcat(command,pkg->name);
cmd_return = system(command);
diff --git a/src/package.h b/src/package.h
index b651b52..81f7184 100644
--- a/src/package.h
+++ b/src/package.h
@@ -71,6 +71,4 @@ int upgrade_pkg(const rc_config *,pkg_info *);
int remove_pkg(pkg_info *);
/* free memory allocated for pkg_list struct */
void free_pkg_list(struct pkg_list *);
-/* recursively create dirs */
-void create_dir_structure(char *);