forked from huceke/omxplayer
-
Notifications
You must be signed in to change notification settings - Fork 334
/
File.cpp
175 lines (141 loc) · 3.83 KB
/
File.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* XBMC Media Center
* Copyright (c) 2002 Frodo
* Portions Copyright (c) by the authors of ffmpeg and xvid
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "linux/PlatformDefs.h"
#include <iostream>
#include <stdio.h>
#include "utils/StdString.h"
#include "File.h"
using namespace XFILE;
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifndef __GNUC__
#pragma warning (disable:4244)
#endif
//*********************************************************************************************
CFile::CFile()
{
m_pFile = NULL;
m_flags = 0;
m_iLength = 0;
m_bPipe = false;
}
//*********************************************************************************************
CFile::~CFile()
{
if(m_pFile && !m_bPipe)
fclose(m_pFile);
}
//*********************************************************************************************
bool CFile::Open(const CStdString& strFileName, unsigned int flags)
{
m_flags = flags;
if (strFileName.compare(0, 5, "pipe:") == 0)
{
m_bPipe = true;
m_pFile = stdin;
m_iLength = 0;
return true;
}
m_pFile = fopen64(strFileName.c_str(), "r");
if(!m_pFile)
return false;
fseeko64(m_pFile, 0, SEEK_END);
m_iLength = ftello64(m_pFile);
fseeko64(m_pFile, 0, SEEK_SET);
return true;
}
bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite)
{
return false;
}
bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */)
{
FILE *fp;
if (strFileName.compare(0, 5, "pipe:") == 0)
return true;
fp = fopen64(strFileName.c_str(), "r");
if(!fp)
return false;
fclose(fp);
return true;
}
unsigned int CFile::Read(void *lpBuf, int64_t uiBufSize)
{
unsigned int ret = 0;
if(!m_pFile)
return 0;
ret = fread(lpBuf, 1, uiBufSize, m_pFile);
return ret;
}
//*********************************************************************************************
void CFile::Close()
{
if(m_pFile && !m_bPipe)
fclose(m_pFile);
m_pFile = NULL;
}
//*********************************************************************************************
int64_t CFile::Seek(int64_t iFilePosition, int iWhence)
{
if (!m_pFile)
return -1;
return fseeko64(m_pFile, iFilePosition, iWhence);;
}
//*********************************************************************************************
int64_t CFile::GetLength()
{
return m_iLength;
}
//*********************************************************************************************
int64_t CFile::GetPosition()
{
if (!m_pFile)
return -1;
return ftello64(m_pFile);
}
//*********************************************************************************************
int CFile::Write(const void* lpBuf, int64_t uiBufSize)
{
return -1;
}
int CFile::IoControl(EIoControl request, void* param)
{
if(request == IOCTRL_SEEK_POSSIBLE && m_pFile)
{
if (m_bPipe)
return false;
struct stat st;
if (fstat(fileno(m_pFile), &st) == 0)
{
return !S_ISFIFO(st.st_mode);
}
}
return -1;
}
bool CFile::IsEOF()
{
if (!m_pFile)
return -1;
if (m_bPipe)
return false;
return feof(m_pFile) != 0;
}