#include "FileStream.h"
#if defined VCZH_GCC
#include <stdio.h>
#endif
namespace
{
namespace
{
#if defined VCZH_GCC
void _fseeki64(FILE* file, pos_t offset, int origin)
{
fseek(file, (long)offset, origin);
}
#endif
::
(
const
&
,
)
:accessRight(
)
{
const
wchar_t
*
=
L"rb"
;
switch
(
)
{
case
:
mode
=
L"rb"
;
break
;
case
:
mode
=
L"wb"
;
break
;
case
:
mode
=
L"w+b"
;
break
;
}
#if defined VCZH_MSVC
if
(
(&
,
.
(),
mode
)!=
0
)
{
=
0
;
}
#elif defined VCZH_GCC
AString fileNameA = wtoa(fileName);
AString modeA = wtoa(mode);
file = fopen(fileNameA.Buffer(), modeA.Buffer());
#endif
}
::
()
{
();
}
bool
::
()
const
{
return
!=
0
&& (
==
||
==
);
}
bool
::
()
const
{
return
!=
0
&& (
==
||
==
);
}
bool
::
()
const
{
return
!=
0
;
}
bool
::
()
const
{
return
!=
0
&& (
==
||
==
);
}
bool
::
()
const
{
return
!=
0
&&
==
;
}
bool
::
()
const
{
return
!=
0
;
}
void
::
()
{
if
(
!=
0
)
{
(
);
=
0
;
}
}
::
()
const
{
if
(
!=
0
)
{
#if defined VCZH_MSVC
=
0
;
if
(
(
, &
position
)==
0
)
{
return
position
;
}
#elif defined VCZH_GCC
return (pos_t)ftell(file);
#endif
}
return
-
1
;
}
::
()
const
{
if
(
!=
0
)
{
#if defined VCZH_MSVC
=
0
;
if
(
(
, &
position
)==
0
)
{
if(fseek(file, 0, SEEK_END)==0)
{
=
();
if
(
(
, &
position
)==
0
)
{
return
size
;
}
}
}
#elif defined VCZH_GCC
long position = ftell(file);
fseek(file, 0, SEEK_END);
long size=ftell(file);
fseek(file, position, SEEK_SET);
return (pos_t)size;
#endif
}
return
-
1
;
}
void
::
(
)
{
if
(
()+
>
())
{
_fseeki64(file, 0, SEEK_END);
}
else
if
(
()+
<
0
)
{
_fseeki64(file, 0, SEEK_SET);
}
else
{
_fseeki64(file, _size, SEEK_CUR);
}
}
void
::
(
)
{
if
(
>
())
{
_fseeki64(file, 0, SEEK_END);
}
else
if
(
<
0
)
{
_fseeki64(file, 0, SEEK_SET);
}
else
{
_fseeki64(file, _size, SEEK_SET);
}
}
void
::
(
)
{
if
(
<
0
)
{
_fseeki64(file, 0, SEEK_END);
}
else
if
(
>
())
{
_fseeki64(file, 0, SEEK_SET);
}
else
{
_fseeki64(file, -_size, SEEK_END);
}
}
::
(
void
*
,
)
{
CHECK_ERROR(file!=0, L"FileStream::Read(pos_t)#Stream is closed, cannot perform this operation.");
do
{
if
(!(
!=
0
))
throw
(
L"FileStream::Read(pos_t)#Stream is closed, cannot perform this operation."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"FileStream::Read(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"FileStream::Read(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
return
(
,
1
,
,
);
}
::
(
void
*
,
)
{
CHECK_ERROR(file!=0, L"FileStream::Write(pos_t)#Stream is closed, cannot perform this operation.");
do
{
if
(!(
!=
0
))
throw
(
L"FileStream::Write(pos_t)#Stream is closed, cannot perform this operation."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"FileStream::Write(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"FileStream::Write(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
return
(
,
1
,
,
);
}
::
(
void
*
,
)
{
CHECK_ERROR(file!=0, L"FileStream::Peek(pos_t)#Stream is closed, cannot perform this operation.");
do
{
if
(!(
!=
0
))
throw
(
L"FileStream::Peek(pos_t)#Stream is closed, cannot perform this operation."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"FileStream::Peek(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"FileStream::Peek(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
#if defined VCZH_MSVC
=
0
;
if
(
(
, &
position
)==
0
)
{
=
(
,
1
,
,
);
if
(
(
, &
position
)==
0
)
{
return
count
;
}
}
return
-
1
;
#elif defined VCZH_GCC
long position=ftell(file);
size_t count=fread(_buffer, 1, _size, file);
fseek(file, position, SEEK_SET);
return count;
#endif
}
}
}