- grep is now a static function

- code cleanup
This commit is contained in:
Aurelien Foret 2006-02-16 21:05:49 +00:00
parent 58a7e85534
commit 181efcdeaa
2 changed files with 26 additions and 29 deletions

View File

@ -58,7 +58,6 @@ long _alpm_gzopen_frontend(char *pathname, int oflags, int mode)
break;
case O_RDWR:
default:
errno = EINVAL;
return -1;
}
@ -71,7 +70,6 @@ long _alpm_gzopen_frontend(char *pathname, int oflags, int mode)
}
if(!(gzf = gzdopen(fd, gzoflags))) {
close(fd);
errno = ENOMEM;
return -1;
}
@ -179,31 +177,6 @@ char *_alpm_strtrim(char *str)
return(str);
}
/* A cheap grep for text files, returns 1 if a substring
* was found in the text file fn, 0 if it wasn't
*/
int _alpm_grep(const char *fn, const char *needle)
{
FILE *fp;
if((fp = fopen(fn, "r")) == NULL) {
return(0);
}
while(!feof(fp)) {
char line[1024];
fgets(line, 1024, fp);
if(feof(fp)) {
continue;
}
if(strstr(line, needle)) {
fclose(fp);
return(1);
}
}
fclose(fp);
return(0);
}
/* Create a lock file
*/
int _alpm_lckmk(char *file)
@ -358,6 +331,31 @@ int _alpm_ldconfig(char *root)
return(0);
}
/* A cheap grep for text files, returns 1 if a substring
* was found in the text file fn, 0 if it wasn't
*/
static int grep(const char *fn, const char *needle)
{
FILE *fp;
if((fp = fopen(fn, "r")) == NULL) {
return(0);
}
while(!feof(fp)) {
char line[1024];
fgets(line, 1024, fp);
if(feof(fp)) {
continue;
}
if(strstr(line, needle)) {
fclose(fp);
return(1);
}
}
fclose(fp);
return(0);
}
int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, char *oldver)
{
char scriptfn[PATH_MAX];
@ -394,7 +392,7 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha
scriptpath = scriptfn + strlen(root) - 1;
}
if(!_alpm_grep(scriptfn, script)) {
if(!grep(scriptfn, script)) {
/* script not found in scriptlet file */
goto cleanup;
}

View File

@ -48,7 +48,6 @@ int _alpm_makepath(char *path);
int _alpm_copyfile(char *src, char *dest);
char *_alpm_strtoupper(char *str);
char *_alpm_strtrim(char *str);
int _alpm_grep(const char *fn, const char *needle);
int _alpm_lckmk(char *file);
int _alpm_lckrm(char *file);
int _alpm_unpack(char *archive, const char *prefix, const char *fn);