X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=src%2Ffileutil.c;h=ce0bdb7b50d3405b0c4b87b4715c297f8284f4ce;hb=f03d3bbce7b36e358df5ee15fab1af190ffcad5a;hp=d902a6a3d2f0f0d7ecd7ff84854d1374697377d9;hpb=51f0f8ed69b065cd2577a27c2a2911cdda243b99;p=oss%2Fcatdoc.git diff --git a/src/fileutil.c b/src/fileutil.c index d902a6a..ce0bdb7 100644 --- a/src/fileutil.c +++ b/src/fileutil.c @@ -71,13 +71,11 @@ char *find_file(char *name, const char *path) char *q; char path_buf[PATH_BUF_SIZE]; char dir_sep[2]={DIR_SEP,0}; - for (p=path;p;p=q+1) { + for (p=path;p;p=(q?(q+1):NULL)) { q=strchr(p,LIST_SEP); - if (q) { if (!prepare_path_buf(path_buf,p,q)) continue; } else { - q--; if (!prepare_path_buf(path_buf,p,p+strlen(p))) continue; } strcat(path_buf,dir_sep); /* always one char */ @@ -101,15 +99,18 @@ char *find_file(char *name, const char *path) /************************************************************************/ int check_charset(char **filename,const char *charset) { char *tmppath; + if (charset == NULL ) { + return 0; + } if (!strncmp(charset,"utf-8",6)) { *filename=strdup("utf-8"); return 1; } tmppath=find_file(stradd(charset,CHARSET_EXT),charset_path); - if (tmppath&& *tmppath) { - *filename=strdup(charset); - free(tmppath); - return 1; + if (tmppath && *tmppath) { + *filename=strdup(charset); + free(tmppath); + return 1; } return 0; } @@ -178,17 +179,18 @@ void list_charsets(void) { char *q; char path_buf[PATH_BUF_SIZE]; char dir_sep[2]={DIR_SEP,0}; + char **ptr; #ifdef __MSDOS__ struct ffblk ffblock; int res,col; #else glob_t glob_buf; int count,glob_flags=GLOB_ERR; + + memset(&glob_buf,0,sizeof(glob_t)); #endif - char **ptr; - for (p=charset_path;p;p=q+1) { + for (p=charset_path;p;p=(q?(q+1):NULL)) { q=strchr(p,LIST_SEP); - if (q) { if (q-p>=PATH_BUF_SIZE) { /* Oops, dir name too long, perhabs broken config file */ @@ -197,7 +199,6 @@ void list_charsets(void) { strncpy(path_buf,p,q-p); path_buf[q-p]=0; } else { - q--; if (strlen(p)>=PATH_BUF_SIZE) continue; strcpy(path_buf,p); }