changeset 2746:aa2e0f33f55d

use aud_vfs_file_get_contents().
author William Pitcock <nenolod@atheme.org>
date Mon, 30 Jun 2008 23:03:47 -0500
parents 3ba15b5aeadb
children ead11a126bdd
files src/psf2/plugin.c
diffstat 1 files changed, 6 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/psf2/plugin.c	Mon Jun 30 22:37:17 2008 -0500
+++ b/src/psf2/plugin.c	Mon Jun 30 23:03:47 2008 -0500
@@ -58,36 +58,11 @@
 	uint8 *filebuf;
 	uint32 size;
 	VFSFile *auxfile;
-
-	auxfile = aud_vfs_fopen(filename, "rb");
-	if (!auxfile)
-	{
-		char buf[PATH_MAX];
-		snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
-		auxfile = aud_vfs_fopen(buf, "rb");
-
-		if (!auxfile)
-		{
-			printf("Unable to find auxiliary file %s\n", buf);
-			return AO_FAIL;
-		}
-	}
+	char buf[PATH_MAX];
 
-	aud_vfs_fseek(auxfile, 0, SEEK_END);
-	size = aud_vfs_ftell(auxfile);
-	aud_vfs_fseek(auxfile, 0, SEEK_SET);
-
-	filebuf = malloc(size);
+	snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
 
-	if (!filebuf)
-	{
-		aud_vfs_fclose(auxfile);
-		printf("ERROR: could not allocate %d bytes of memory\n", size);
-		return AO_FAIL;
-	}
-
-	aud_vfs_fread(filebuf, size, 1, auxfile);
-	aud_vfs_fclose(auxfile);
+	aud_vfs_file_get_contents(buf, &filebuf, &size);
 
 	*buffer = filebuf;
 	*length = (uint64)size;
@@ -97,35 +72,11 @@
 
 void psf2_play(InputPlayback *data)
 {
-	VFSFile *file;
 	uint8 *buffer;
 	uint32 size, filesig;
 
-	path = strdup(data->filename);
-	file = aud_vfs_fopen(data->filename, "rb");
-
-	if (!file)
-	{
-		printf("ERROR: could not open file %s\n", data->filename);
-		return;
-	}
-
-	aud_vfs_fseek(file, 0, SEEK_END);
-	size = aud_vfs_ftell(file);
-	aud_vfs_fseek(file, 0, SEEK_SET);
-
-	buffer = malloc(size);
-
-	if (!buffer)
-	{
-		aud_vfs_fclose(file);
-		printf("ERROR: could not allocate %d bytes of memory\n", size);
-		return;
-	}
-
-	// read the file
-	aud_vfs_fread(buffer, size, 1, file);
-	aud_vfs_fclose(file);
+	path = g_strdup(data->filename);
+	aud_vfs_file_get_contents(data->filename, &buffer, &size);
 
 	// now try to identify the file
 	type = 0;
@@ -167,6 +118,7 @@
 	}	
 
 	free(buffer);
+	g_free(path);
 }
 
 void psf2_update(unsigned char *buffer, long count, InputPlayback *playback)