2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #ifndef __EMU_FILE_WRAPPER_H__
23 #define __EMU_FILE_WRAPPER_H__
28 #include "threads/CriticalSection.h"
30 #if defined(TARGET_POSIX) && !defined(TARGET_DARWIN) && !defined(TARGET_FREEBSD) && !defined(TARGET_ANDROID)
34 #define MAX_EMULATED_FILES 50
35 #define FILE_WRAPPER_OFFSET 0x00000100
42 typedef struct stEmuFileObject
46 XFILE::CFile* file_xbmc;
47 CCriticalSection *file_lock;
58 * Only to be called when shutting down xbmc
62 EmuFileObject* RegisterFileObject(XFILE::CFile* pFile);
63 void UnRegisterFileObjectByDescriptor(int fd);
64 void UnRegisterFileObjectByStream(FILE* stream);
65 void LockFileObjectByDescriptor(int fd);
66 bool TryLockFileObjectByDescriptor(int fd);
67 void UnlockFileObjectByDescriptor(int fd);
68 EmuFileObject* GetFileObjectByDescriptor(int fd);
69 EmuFileObject* GetFileObjectByStream(FILE* stream);
70 XFILE::CFile* GetFileXbmcByDescriptor(int fd);
71 XFILE::CFile* GetFileXbmcByStream(FILE* stream);
72 static int GetDescriptorByStream(FILE* stream);
73 FILE* GetStreamByDescriptor(int fd);
74 static bool DescriptorIsEmulatedFile(int fd);
75 static bool StreamIsEmulatedFile(FILE* stream);
77 EmuFileObject m_files[MAX_EMULATED_FILES];
78 CCriticalSection m_criticalSection;
81 extern CEmuFileWrapper g_emuFileWrapper;