From ec136784d4328b4c75f622c08273cf9dc6cac40f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 16 Nov 2010 20:12:26 -0600 Subject: Refactor statfs/statvfs type check Turn it into a configure-type typedef, which allows us to reduce the amount of duplicated code and clean up some #ifdef magic in the code itself. Adjust some of the other defined checks to look at the headers available rather than trying to pull in the right ones based on configure checks. Signed-off-by: Dan McGee Signed-off-by: Allan McRae --- lib/libalpm/diskspace.c | 51 +++++++++++++++++-------------------------------- lib/libalpm/diskspace.h | 11 ++++------- 2 files changed, 21 insertions(+), 41 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index 1f1a6201..ad6ceba5 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -19,18 +19,23 @@ #include "config.h" -#if defined HAVE_GETMNTENT +#if defined(HAVE_MNTENT_H) #include +#endif +#if defined(HAVE_SYS_STATVFS_H) #include -#elif defined HAVE_GETMNTINFO_STATFS +#endif +#if defined(HAVE_SYS_PARAM_H) #include +#endif +#if defined(HAVE_SYS_MOUNT_H) #include -#if HAVE_SYS_UCRED_H +#endif +#if defined(HAVE_SYS_UCRED_H) #include #endif -#elif defined HAVE_GETMNTINFO_STATVFS +#if defined(HAVE_SYS_TYPES_H) #include -#include #endif #include @@ -60,7 +65,7 @@ static alpm_list_t *mount_point_list() #if defined HAVE_GETMNTENT struct mntent *mnt; FILE *fp; - struct statvfs fsp; + FSSTATSTYPE fsp; fp = setmntent(MOUNTED, "r"); @@ -77,8 +82,8 @@ static alpm_list_t *mount_point_list() MALLOC(mp, sizeof(alpm_mountpoint_t), RET_ERR(PM_ERR_MEMORY, NULL)); mp->mount_dir = strdup(mnt->mnt_dir); - MALLOC(mp->fsp, sizeof(struct statvfs), RET_ERR(PM_ERR_MEMORY, NULL)); - memcpy((void *)(mp->fsp), (void *)(&fsp), sizeof(struct statvfs)); + MALLOC(mp->fsp, sizeof(FSSTATSTYPE), RET_ERR(PM_ERR_MEMORY, NULL)); + memcpy((void *)(mp->fsp), (void *)(&fsp), sizeof(FSSTATSTYPE)); mp->blocks_needed = 0; mp->max_blocks_needed = 0; @@ -88,9 +93,9 @@ static alpm_list_t *mount_point_list() } endmntent(fp); -#elif defined HAVE_GETMNTINFO_STATFS +#elif defined HAVE_GETMNTINFO int entries; - struct statfs *fsp; + FSSTATSTYPE *fsp; entries = getmntinfo(&fsp, MNT_NOWAIT); @@ -102,30 +107,8 @@ static alpm_list_t *mount_point_list() MALLOC(mp, sizeof(alpm_mountpoint_t), RET_ERR(PM_ERR_MEMORY, NULL)); mp->mount_dir = strdup(fsp->f_mntonname); - MALLOC(mp->fsp, sizeof(struct statfs), RET_ERR(PM_ERR_MEMORY, NULL)); - memcpy((void *)(mp->fsp), (void *)fsp, sizeof(struct statfs)); - - mp->blocks_needed = 0; - mp->max_blocks_needed = 0; - - mount_points = alpm_list_add(mount_points, mp); - } -#elif defined HAVE_GETMNTINFO_STATVFS - int entries; - struct statvfs *fsp; - - entries = getmntinfo(&fsp, MNT_NOWAIT); - - if (entries < 0) { - return NULL; - } - - for (; entries-- > 0; fsp++) { - MALLOC(mp, sizeof(alpm_mountpoint_t), RET_ERR(PM_ERR_MEMORY, NULL)); - mp->mount_dir = strdup(fsp->f_mntonname); - - MALLOC(mp->fsp, sizeof(struct statvfs), RET_ERR(PM_ERR_MEMORY, NULL)); - memcpy((void *)(mp->fsp), (void *)fsp, sizeof(struct statvfs)); + MALLOC(mp->fsp, sizeof(FSSTATSTYPE), RET_ERR(PM_ERR_MEMORY, NULL)); + memcpy((void *)(mp->fsp), (void *)fsp, sizeof(FSSTATSTYPE)); mp->blocks_needed = 0; mp->max_blocks_needed = 0; diff --git a/lib/libalpm/diskspace.h b/lib/libalpm/diskspace.h index 15ff2f67..60c00280 100644 --- a/lib/libalpm/diskspace.h +++ b/lib/libalpm/diskspace.h @@ -20,9 +20,10 @@ #ifndef _ALPM_DISKSPACE_H #define _ALPM_DISKSPACE_H -#if defined HAVE_GETMNTINFO_STATFS +#if defined(HAVE_SYS_MOUNT_H) #include -#else +#endif +#if defined(HAVE_SYS_STATVFS_H) #include #endif @@ -31,15 +32,11 @@ typedef struct __alpm_mountpoint_t { /* mount point information */ char *mount_dir; -#if defined HAVE_GETMNTINFO_STATFS - struct statfs *fsp; -#else - struct statvfs *fsp; -#endif /* storage for additional disk usage calculations */ long blocks_needed; long max_blocks_needed; int used; + FSSTATSTYPE *fsp; } alpm_mountpoint_t; int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db); -- cgit v1.2.3-70-g09d2