int fs_init(const char *argv0)
{
- return PHYSFS_init(argv0);
+ if (PHYSFS_init(argv0))
+ {
+ PHYSFS_permitSymbolicLinks(1);
+ return 1;
+ }
+
+ return 0;
}
int fs_quit(void)
return PHYSFS_eof(fh->handle);
}
+int fs_length(fs_file fh)
+{
+ return PHYSFS_fileLength(fh->handle);
+}
+
/* -------------------------------------------------------------------------- */
/*
char *fs_gets(char *dst, int count, fs_file fh)
{
char *s = dst;
- char *cr = NULL;
- int c = 0;
+ int c;
+
+ assert(dst);
+ assert(count > 0);
if (fs_eof(fh))
return NULL;
*s = c;
- /* Normalize possible CRLF and break. */
+ /* Keep a newline and break. */
if (*s == '\n')
{
- if (cr + 1 == s)
- *cr = '\n';
- else
- s++;
-
+ s++;
break;
}
- /* Note carriage return. */
+ /* Ignore carriage returns. */
if (*s == '\r')
- cr = s;
+ {
+ count++;
+ s--;
+ }
s++;
}
- if (count > 0)
- *s = '\0';
+ *s = '\0';
- return c < 0 ? NULL : dst;
+ return dst;
}
/* -------------------------------------------------------------------------- */
}
/* -------------------------------------------------------------------------- */
+
+void *fs_load(const char *path, int *datalen)
+{
+ fs_file fh;
+ void *data;
+
+ data = NULL;
+
+ if ((fh = fs_open(path, "r")))
+ {
+ if ((*datalen = fs_length(fh)) > 0)
+ {
+ if ((data = malloc(*datalen)))
+ {
+ if (fs_read(data, *datalen, 1, fh) != 1)
+ {
+ free(data);
+ data = NULL;
+ *datalen = 0;
+ }
+ }
+ }
+
+ fs_close(fh);
+ }
+
+ return data;
+}
+
+/* -------------------------------------------------------------------------- */