|
MythTV
0.26-pre
|
00001 /* 00002 * This file is part of libbluray 00003 * Copyright (C) 2009-2010 Obliter0n 00004 * Copyright (C) 2009-2010 John Stebbins 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #if HAVE_CONFIG_H 00022 #include "config.h" 00023 #endif 00024 00025 #if defined(__MINGW32__) 00026 /* ftello64() and fseeko64() prototypes from stdio.h */ 00027 # undef __STRICT_ANSI__ 00028 #endif 00029 00030 #include "file.h" 00031 #include "file_mythiowrapper.h" 00032 #include "util/macro.h" 00033 #include "util/logging.h" 00034 00035 #include <stdio.h> 00036 #include <stdlib.h> 00037 #include <sys/stat.h> 00038 #include <sys/types.h> 00039 00040 #ifdef WIN32 00041 #define ftello _ftelli64 00042 #define fseeko _fseeki64 00043 #endif // #ifdef WIN32 00044 00045 static void file_close_linux(BD_FILE_H *file) 00046 { 00047 if (file) { 00048 fclose((FILE *)file->internal); 00049 00050 BD_DEBUG(DBG_FILE, "Closed LINUX file (%p)\n", file); 00051 00052 X_FREE(file); 00053 } 00054 } 00055 00056 static int64_t file_seek_linux(BD_FILE_H *file, int64_t offset, int32_t origin) 00057 { 00058 #if defined(__MINGW32__) 00059 return fseeko64((FILE *)file->internal, offset, origin); 00060 #else 00061 return fseeko((FILE *)file->internal, offset, origin); 00062 #endif 00063 } 00064 00065 static int64_t file_tell_linux(BD_FILE_H *file) 00066 { 00067 #if defined(__MINGW32__) 00068 return ftello64((FILE *)file->internal); 00069 #else 00070 return ftello((FILE *)file->internal); 00071 #endif 00072 } 00073 00074 static int file_stat_linux(BD_FILE_H *file, struct stat *buf) 00075 { 00076 return fstat(fileno((FILE *)file->internal), buf); 00077 } 00078 00079 static int file_eof_linux(BD_FILE_H *file) 00080 { 00081 return feof((FILE *)file->internal); 00082 } 00083 00084 static int64_t file_read_linux(BD_FILE_H *file, uint8_t *buf, int64_t size) 00085 { 00086 return fread(buf, 1, size, (FILE *)file->internal); 00087 } 00088 00089 static int64_t file_write_linux(BD_FILE_H *file, const uint8_t *buf, int64_t size) 00090 { 00091 return fwrite(buf, 1, size, (FILE *)file->internal); 00092 } 00093 00094 static BD_FILE_H *file_open_linux(const char* filename, const char *mode) 00095 { 00096 if (strncmp(filename, "myth://", 7) == 0) 00097 return file_open_mythiowrapper(filename, mode); 00098 00099 FILE *fp = NULL; 00100 BD_FILE_H *file = malloc(sizeof(BD_FILE_H)); 00101 00102 BD_DEBUG(DBG_FILE, "Opening LINUX file %s... (%p)\n", filename, file); 00103 file->close = file_close_linux; 00104 file->seek = file_seek_linux; 00105 file->read = file_read_linux; 00106 file->write = file_write_linux; 00107 file->tell = file_tell_linux; 00108 file->eof = file_eof_linux; 00109 file->stat = file_stat_linux; 00110 00111 if ((fp = fopen(filename, mode))) { 00112 file->internal = fp; 00113 00114 return file; 00115 } 00116 00117 BD_DEBUG(DBG_FILE, "Error opening file! (%p)\n", file); 00118 00119 X_FREE(file); 00120 00121 return NULL; 00122 } 00123 00124 BD_FILE_H* (*file_open)(const char* filename, const char *mode) = file_open_linux;
1.7.6.1