changeset 821:a17888ed66a8 trunk

[svn] - safety checks
author nenolod
date Sat, 11 Mar 2006 21:06:47 -0800
parents 4e6132a6c2c1
children c5eb4b762977
files libaudacious/vfs_gnome.c libaudacious/vfs_stdio.c
diffstat 2 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libaudacious/vfs_gnome.c	Sat Mar 11 18:13:26 2006 -0800
+++ b/libaudacious/vfs_gnome.c	Sat Mar 11 21:06:47 2006 -0800
@@ -99,6 +99,9 @@
 {
     gint ret = 0;
 
+    if (file == NULL)
+	return 0;
+
     if (file->handle) {
         if (gnome_vfs_close(file->handle) != GNOME_VFS_OK)
             ret = -1;
@@ -118,6 +121,9 @@
     GnomeVFSResult result;
     GnomeVFSFileSize bytes_read;
 
+    if (file == NULL)
+	return 0;
+
     result = gnome_vfs_read(file->handle, ptr, size * nmemb, &bytes_read);
     if (result == GNOME_VFS_OK)
         return bytes_read;
@@ -139,6 +145,9 @@
     GnomeVFSResult result;
     GnomeVFSFileSize bytes_written;
 
+    if (file == NULL)
+	return 0;
+
     result = gnome_vfs_write(file->handle, ptr, size * nmemb, &bytes_written);
     if (result == GNOME_VFS_OK)
         return bytes_written;
@@ -154,6 +163,9 @@
     GnomeVFSResult result;
     GnomeVFSSeekPosition g_whence;
 
+    if (file == NULL)
+	return 0;
+
     switch (whence) {
     case SEEK_SET:
         g_whence = GNOME_VFS_SEEK_START;
@@ -180,6 +192,9 @@
 void
 vfs_rewind(VFSFile * file)
 {
+    if (file == NULL)
+	return;
+
     vfs_fseek(file, 0L, SEEK_SET);
 }
 
@@ -189,6 +204,9 @@
     GnomeVFSResult result;
     GnomeVFSFileSize position;
 
+    if (file == NULL)
+	return 0;
+
     result = gnome_vfs_tell(file->handle, &position);
 
     if (result == GNOME_VFS_OK)
@@ -200,6 +218,9 @@
 gboolean
 vfs_feof(VFSFile * file)
 {
+    if (file == NULL)
+	return FALSE;
+
     return file->eof;
 }
 
@@ -258,6 +279,9 @@
 {
     GnomeVFSResult result;
 
+    if (file == NULL)
+	return -1;
+
     result = gnome_vfs_truncate_handle(file->handle, (GnomeVFSFileSize) length);
 
     if (result == GNOME_VFS_OK)
--- a/libaudacious/vfs_stdio.c	Sat Mar 11 18:13:26 2006 -0800
+++ b/libaudacious/vfs_stdio.c	Sat Mar 11 21:06:47 2006 -0800
@@ -58,6 +58,9 @@
 {
     gint ret = 0;
 
+    if (file == NULL)
+        return -1;
+
     if (file->handle) {
         if (fclose(file->handle) != 0)
             ret = -1;
@@ -74,6 +77,9 @@
           size_t nmemb,
           VFSFile * file)
 {
+    if (file == NULL)
+        return 0;
+
     return fread(ptr, size, nmemb, file->handle);
 }
 
@@ -83,6 +89,9 @@
            size_t nmemb,
            VFSFile * file)
 {
+    if (file == NULL)
+        return 0;
+
     return fwrite(ptr, size, nmemb, file->handle);
 }
 
@@ -91,25 +100,37 @@
           glong offset,
           gint whence)
 {
+    if (file == NULL)
+        return 0;
+
     return fseek(file->handle, offset, whence);
 }
 
 void
 vfs_rewind(VFSFile * file)
 {
+    if (file == NULL)
+        return;
+
     rewind(file->handle);
 }
 
 glong
 vfs_ftell(VFSFile * file)
 {
+    if (file == NULL)
+        return 0;
+
     return ftell(file->handle);
 }
 
 gboolean
 vfs_feof(VFSFile * file)
 {
-    return (gboolean)feof(file->handle);
+    if (file == NULL)
+        return FALSE;
+
+    return (gboolean) feof(file->handle);
 }
 
 gboolean
@@ -133,5 +154,8 @@
 gint
 vfs_truncate(VFSFile * file, glong size)
 {
+    if (file == NULL)
+        return -1;
+
     return ftruncate(fileno(file->handle), size);
 }