1 /* $Id: physfsx.h,v 1.3 2004-12-02 08:52:59 btb Exp $ */
5 * Some simple physfs extensions
12 #if !defined(macintosh) && !defined(_MSC_VER)
13 #include <sys/param.h>
15 #if defined(__linux__)
17 #elif defined(__MACH__) && defined(__APPLE__)
18 #include <sys/mount.h>
24 static inline int PHYSFSX_readString(PHYSFS_file *file, char *s)
32 PHYSFS_read(file, ptr, 1, 1);
33 while (!PHYSFS_eof(file) && *ptr++ != 0);
38 static inline int PHYSFSX_gets(PHYSFS_file *file, char *s)
46 PHYSFS_read(file, ptr, 1, 1);
47 while (!PHYSFS_eof(file) && *ptr++ != '\n');
52 static inline int PHYSFSX_writeU8(PHYSFS_file *file, PHYSFS_uint8 val)
54 return PHYSFS_write(file, &val, 1, 1);
57 static inline int PHYSFSX_writeString(PHYSFS_file *file, char *s)
59 return PHYSFS_write(file, s, 1, strlen(s) + 1);
62 static inline int PHYSFSX_puts(PHYSFS_file *file, char *s)
64 return PHYSFS_write(file, s, 1, strlen(s));
67 static inline int PHYSFSX_putc(PHYSFS_file *file, int c)
69 unsigned char ch = (unsigned char)c;
71 if (PHYSFS_write(file, &ch, 1, 1) < 1)
77 static inline int PHYSFSX_getRealPath(char *stdPath, char *realPath)
79 const char *realDir = PHYSFS_getRealDir(stdPath);
81 char sep = *PHYSFS_getDirSeparator();
86 strncpy(realPath, realDir, PATH_MAX); // some compilers (like MPW) don't have snprintf
87 p = realPath + strlen(realPath);
88 strncat(realPath, stdPath, PATH_MAX - strlen(realPath));
89 while ((p = strchr(p, '/')))
95 static inline int PHYSFSX_rename(char *oldpath, char *newpath)
97 char old[PATH_MAX], new[PATH_MAX];
99 PHYSFSX_getRealPath(oldpath, old);
100 PHYSFSX_getRealPath(newpath, new);
101 return (rename(old, new) == 0);
105 // returns -1 if error
106 // Gets bytes free in current write dir
107 static inline PHYSFS_sint64 PHYSFSX_getFreeDiskSpace()
109 #if defined(__linux__) || (defined(__MACH__) && defined(__APPLE__))
112 if (!statfs(PHYSFS_getWriteDir(), &sfs))
113 return (PHYSFS_sint64)(sfs.f_bavail * sfs.f_bsize);
121 #endif /* PHYSFSX_H */