unix.c
changeset 1597 ef6253448620
parent 1596 483007886b59
child 1687 521050dcd91e
equal deleted inserted replaced
1596:483007886b59 1597:ef6253448620
    10 #include <sys/stat.h>
    10 #include <sys/stat.h>
    11 #include <time.h>
    11 #include <time.h>
    12 #include <pwd.h>
    12 #include <pwd.h>
    13 #include <signal.h>
    13 #include <signal.h>
    14 
    14 
    15 #if defined(__linux__)
    15 #if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__linux__)
       
    16 	#define HAS_STATVFS
       
    17 #endif
       
    18 
       
    19 #ifdef HAS_STATVFS
    16 #include <sys/statvfs.h>
    20 #include <sys/statvfs.h>
    17 #endif
    21 #endif
    18 
    22 
    19 
    23 
    20 #if defined(WITH_SDL)
    24 #if defined(WITH_SDL)
   310 StringID FiosGetDescText(const char **path, uint32 *tot)
   314 StringID FiosGetDescText(const char **path, uint32 *tot)
   311 {
   315 {
   312 	uint32 free = 0;
   316 	uint32 free = 0;
   313 	*path = _fios_path[0] != '\0' ? _fios_path : "/";
   317 	*path = _fios_path[0] != '\0' ? _fios_path : "/";
   314 
   318 
   315 #if defined(__linux__)
   319 #ifdef HAS_STATVFS
   316 	{
   320 	{
   317 		struct statvfs s;
   321 		struct statvfs s;
   318 
   322 
   319 		if (statvfs(*path, &s) != 0) {
   323 		if (statvfs(*path, &s) == 0) {
   320 			free = ((uint64)s.f_bsize * s.f_bavail) >> 20;
   324 			free = (uint64)s.f_frsize * s.f_bavail >> 20;
   321 		} else
   325 		} else
   322 			return STR_4006_UNABLE_TO_READ_DRIVE;
   326 			return STR_4006_UNABLE_TO_READ_DRIVE;
   323 	}
   327 	}
   324 #endif
   328 #endif
   325 	if (tot != NULL) *tot = free;
   329 	if (tot != NULL) *tot = free;