be_files.c: PATH_MAX cleanup

Most of these are not easy to remove, but I could kill the ones in the two
lastupdate functions.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-05-04 19:34:03 -05:00
parent a13bf74979
commit 7fccfc7819
1 changed files with 13 additions and 6 deletions

View File

@ -248,7 +248,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
{ {
FILE *fp = NULL; FILE *fp = NULL;
struct stat buf; struct stat buf;
char path[PATH_MAX+1]; char path[PATH_MAX];
char line[513]; char line[513];
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -747,7 +747,7 @@ int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
time_t _alpm_db_getlastupdate(const pmdb_t *db) time_t _alpm_db_getlastupdate(const pmdb_t *db)
{ {
FILE *fp; FILE *fp;
char file[PATH_MAX]; char *file;
time_t ret = 0; time_t ret = 0;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -756,10 +756,13 @@ time_t _alpm_db_getlastupdate(const pmdb_t *db)
return(ret); return(ret);
} }
snprintf(file, PATH_MAX, "%s.lastupdate", db->path); /* db->path + '.lastupdate' + NULL */
MALLOC(file, strlen(db->path) + 12, RET_ERR(PM_ERR_MEMORY, ret));
sprintf(file, "%s.lastupdate", db->path);
/* get the last update time, if it's there */ /* get the last update time, if it's there */
if((fp = fopen(file, "r")) == NULL) { if((fp = fopen(file, "r")) == NULL) {
free(file);
return(ret); return(ret);
} else { } else {
char line[64]; char line[64];
@ -768,6 +771,7 @@ time_t _alpm_db_getlastupdate(const pmdb_t *db)
} }
} }
fclose(fp); fclose(fp);
free(file);
return(ret); return(ret);
} }
@ -777,7 +781,7 @@ time_t _alpm_db_getlastupdate(const pmdb_t *db)
int _alpm_db_setlastupdate(const pmdb_t *db, time_t time) int _alpm_db_setlastupdate(const pmdb_t *db, time_t time)
{ {
FILE *fp; FILE *fp;
char file[PATH_MAX]; char *file;
int ret = 0; int ret = 0;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -786,16 +790,19 @@ int _alpm_db_setlastupdate(const pmdb_t *db, time_t time)
return(-1); return(-1);
} }
snprintf(file, PATH_MAX, "%s.lastupdate", db->path); /* db->path + '.lastupdate' + NULL */
MALLOC(file, strlen(db->path) + 12, RET_ERR(PM_ERR_MEMORY, ret));
sprintf(file, "%s.lastupdate", db->path);
if((fp = fopen(file, "w")) == NULL) { if((fp = fopen(file, "w")) == NULL) {
free(file);
return(-1); return(-1);
} }
if(fprintf(fp, "%ju", (uintmax_t)time) <= 0) { if(fprintf(fp, "%ju", (uintmax_t)time) <= 0) {
ret = -1; ret = -1;
} }
fclose(fp); fclose(fp);
free(file);
return(ret); return(ret);
} }