1 /* $Id: physfsx.h,v 1.4 2004-12-02 09:48:57 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);
90 strncat(realPath, stdPath, PATH_MAX - strlen(realPath));
91 while ((p = strchr(p, '/')))
97 static inline int PHYSFSX_rename(char *oldpath, char *newpath)
99 char old[PATH_MAX], new[PATH_MAX];
101 PHYSFSX_getRealPath(oldpath, old);
102 PHYSFSX_getRealPath(newpath, new);
103 return (rename(old, new) == 0);
107 // returns -1 if error
108 // Gets bytes free in current write dir
109 static inline PHYSFS_sint64 PHYSFSX_getFreeDiskSpace()
111 #if defined(__linux__) || (defined(__MACH__) && defined(__APPLE__))
114 if (!statfs(PHYSFS_getWriteDir(), &sfs))
115 return (PHYSFS_sint64)(sfs.f_bavail * sfs.f_bsize);
123 #endif /* PHYSFSX_H */