Mercurial > audlegacy
annotate libaudacious/vfs_stdio.c @ 1490:ded11c19cc0a trunk
[svn] - do things in a less hackish way
| author | nenolod |
|---|---|
| date | Thu, 03 Aug 2006 22:54:57 -0700 |
| parents | 411b4aaf928b |
| children | e9c24e35bd76 |
| rev | line source |
|---|---|
| 0 | 1 /* This program is free software; you can redistribute it and/or modify |
| 1460 | 2 * it under the terms of the GNU General Public License as published by |
| 0 | 3 * the Free Software Foundation; either version 2 of the License, or |
| 4 * (at your option) any later version. | |
| 5 * | |
| 6 * This program is distributed in the hope that it will be useful, | |
| 7 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 9 * GNU General Public License for more details. | |
| 10 * | |
| 11 * You should have received a copy of the GNU General Public License | |
| 12 * along with this program; if not, write to the Free Software | |
| 1459 | 13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 0 | 14 */ |
| 15 | |
| 16 #include "vfs.h" | |
| 17 #include <stdio.h> | |
| 18 | |
| 19 #include <unistd.h> | |
| 20 #include <sys/stat.h> | |
| 21 #include <sys/types.h> | |
| 22 | |
| 23 | |
| 24 struct _VFSFile { | |
| 25 FILE *handle; | |
| 26 }; | |
| 27 | |
| 28 | |
| 29 gboolean | |
| 30 vfs_init(void) | |
| 31 { | |
| 32 return TRUE; | |
| 33 } | |
| 34 | |
| 35 VFSFile * | |
| 36 vfs_fopen(const gchar * path, | |
| 37 const gchar * mode) | |
| 38 { | |
| 39 VFSFile *file; | |
| 40 | |
| 550 | 41 if (!path || !mode) |
| 42 return NULL; | |
| 43 | |
| 0 | 44 file = g_new(VFSFile, 1); |
| 45 | |
| 46 file->handle = fopen(path, mode); | |
| 47 | |
| 48 if (file->handle == NULL) { | |
| 49 g_free(file); | |
| 50 file = NULL; | |
| 51 } | |
| 52 | |
| 53 return file; | |
| 54 } | |
| 55 | |
| 56 gint | |
| 57 vfs_fclose(VFSFile * file) | |
| 58 { | |
| 59 gint ret = 0; | |
| 60 | |
| 821 | 61 if (file == NULL) |
| 62 return -1; | |
| 63 | |
| 0 | 64 if (file->handle) { |
| 65 if (fclose(file->handle) != 0) | |
| 66 ret = -1; | |
| 67 } | |
| 68 | |
| 69 g_free(file); | |
| 70 | |
| 71 return ret; | |
| 72 } | |
| 73 | |
| 74 size_t | |
| 75 vfs_fread(gpointer ptr, | |
| 76 size_t size, | |
| 77 size_t nmemb, | |
| 78 VFSFile * file) | |
| 79 { | |
| 821 | 80 if (file == NULL) |
| 81 return 0; | |
| 82 | |
| 0 | 83 return fread(ptr, size, nmemb, file->handle); |
| 84 } | |
| 85 | |
| 86 size_t | |
| 87 vfs_fwrite(gconstpointer ptr, | |
| 88 size_t size, | |
| 89 size_t nmemb, | |
| 90 VFSFile * file) | |
| 91 { | |
| 821 | 92 if (file == NULL) |
| 93 return 0; | |
| 94 | |
| 0 | 95 return fwrite(ptr, size, nmemb, file->handle); |
| 96 } | |
| 97 | |
| 98 gint | |
| 99 vfs_fseek(VFSFile * file, | |
| 100 glong offset, | |
| 101 gint whence) | |
| 102 { | |
| 821 | 103 if (file == NULL) |
| 104 return 0; | |
| 105 | |
| 0 | 106 return fseek(file->handle, offset, whence); |
| 107 } | |
| 108 | |
| 109 void | |
| 110 vfs_rewind(VFSFile * file) | |
| 111 { | |
| 821 | 112 if (file == NULL) |
| 113 return; | |
| 114 | |
| 0 | 115 rewind(file->handle); |
| 116 } | |
| 117 | |
| 118 glong | |
| 119 vfs_ftell(VFSFile * file) | |
| 120 { | |
| 821 | 121 if (file == NULL) |
| 122 return 0; | |
| 123 | |
| 0 | 124 return ftell(file->handle); |
| 125 } | |
| 126 | |
| 127 gboolean | |
|
811
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
128 vfs_feof(VFSFile * file) |
|
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
129 { |
| 821 | 130 if (file == NULL) |
| 131 return FALSE; | |
| 132 | |
| 133 return (gboolean) feof(file->handle); | |
|
811
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
134 } |
|
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
135 |
|
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
136 gboolean |
| 0 | 137 vfs_file_test(const gchar * path, GFileTest test) |
| 138 { | |
| 139 return g_file_test(path, test); | |
| 140 } | |
| 141 | |
| 142 /* NOTE: stat() is not part of stdio */ | |
| 143 gboolean | |
| 144 vfs_is_writeable(const gchar * path) | |
| 145 { | |
| 146 struct stat info; | |
| 147 | |
| 148 if (stat(path, &info) == -1) | |
| 149 return FALSE; | |
| 150 | |
| 151 return (info.st_mode & S_IWUSR); | |
| 152 } | |
| 153 | |
| 154 gint | |
| 155 vfs_truncate(VFSFile * file, glong size) | |
| 156 { | |
| 821 | 157 if (file == NULL) |
| 158 return -1; | |
| 159 | |
| 0 | 160 return ftruncate(fileno(file->handle), size); |
| 161 } |
