diff options
author | Darkvater <darkvater@openttd.org> | 2006-08-05 00:53:09 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-08-05 00:53:09 +0000 |
commit | 198f6caf20bf425bd1d3c8b91291f58213f6b60b (patch) | |
tree | 060490cbd9c8e7eb1a0f6a326ba4b273c535f7d7 /unix.c | |
parent | 525a0ad4c033b378511a3bfc8da79b67a94c2497 (diff) | |
download | openttd-198f6caf20bf425bd1d3c8b91291f58213f6b60b.tar.xz |
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 111 |
1 files changed, 16 insertions, 95 deletions
@@ -52,20 +52,6 @@ extern char *_fios_path; extern FiosItem *_fios_items; extern int _fios_count, _fios_alloc; -#if !defined(__MORPHOS__) && !defined(__AMIGAOS__) -#define ISROOT(__p) (__p[1] == '\0') -#define PATHTEMPLATE "%s/%s" -#else -/* on MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory". - * This is some evil magic which tries to handle this transparently w/o - * disturbing code with too much #ifdefs. It's not possible to switch the - * volume, but at least it doesn't crash :) (tokai) - */ -static bool __isroot; /* not very thread save, but will do in this case */ -#define ISROOT(__p) (__isroot = (__p[strlen(__p)-1] == ':')) -#define PATHTEMPLATE (__isroot ? "%s:%s" : "%s/%s") -#endif - bool FiosIsRoot(const char *path) { #if !defined(__MORPHOS__) && !defined(__AMIGAOS__) @@ -82,6 +68,22 @@ void FiosGetDrives(void) return; } +bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) +{ + uint32 free = 0; + +#ifdef HAS_STATVFS + { + struct statvfs s; + + if (statvfs(path, &s) != 0) return false; + free = (uint64)s.f_frsize * s.f_bavail >> 20; + } +#endif + if (tot != NULL) *tot = free; + return true; +} + bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) { char filename[MAX_PATH]; @@ -99,87 +101,6 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb return (ent->d_name[0] != '.'); // hidden file } -// Browse to -char *FiosBrowseTo(const FiosItem *item) -{ - char *path = _fios_path; - char *s; - - switch (item->type) { - case FIOS_TYPE_PARENT: - /* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */ - if ((s = strrchr(path, '/'))) { - if (s != path) { - s[0] = '\0'; - } else { - s[1] = '\0'; - } - } -#if defined(__MORPHOS__) || defined(__AMIGAOS__) - else { - if ((s = strrchr(path, ':'))) { - s[1] = '\0'; - } - } -#endif - break; - - case FIOS_TYPE_DIR: - if (!ISROOT(path)) strcat(path, "/"); - strcat(path, item->name); - break; - - case FIOS_TYPE_DIRECT: - sprintf(path, "%s/", item->name); - s = strrchr(path, '/'); - if (s[1] == '\0') s[0] = '\0'; // strip trailing slash - break; - - case FIOS_TYPE_FILE: - case FIOS_TYPE_OLDFILE: - case FIOS_TYPE_SCENARIO: - case FIOS_TYPE_OLD_SCENARIO: { - static char str_buffr[512]; - -#if defined(__MORPHOS__) || defined(__AMIGAOS__) - ISROOT(path); /* init __isroot for PATHTEMPLATE */ -#endif - - sprintf(str_buffr, PATHTEMPLATE, path, item->name); - return str_buffr; - } - } - - return NULL; -} - -/** - * Get descriptive texts. Returns the path and free space - * left on the device - * @param path string describing the path - * @param tfs total free space in megabytes, optional (can be NULL) - * @return StringID describing the path (free space or failure) - */ -StringID FiosGetDescText(const char **path, uint32 *tot) -{ - uint32 free = 0; - *path = _fios_path; - -#ifdef HAS_STATVFS - { - struct statvfs s; - - if (statvfs(*path, &s) == 0) { - free = (uint64)s.f_frsize * s.f_bavail >> 20; - } else { - return STR_4006_UNABLE_TO_READ_DRIVE; - } - } -#endif - if (tot != NULL) *tot = free; - return STR_4005_BYTES_FREE; -} - #if defined(__BEOS__) || defined(__linux__) static void ChangeWorkingDirectory(char *exe) { |