- 论坛徽章:
- 0
|
//在SOLARIS平台下,fopen,fseek,fread,fwrite这些函数在哪些情况下会出错呢?
//不是编译的问题!也不是经常出现!我就是想知道那几个函数在哪些情况下会失败!
#define COPY_STRUNIT_LEN 256
#define F_COPY_DONE 0
#define F_OPENSRC_ERR 1
#define F_SRCSEEKEND_ERR 2
#define F_SRCSEEKSET_ERR 3
#define F_OPENDEST_ERR 4
#define F_COPYLEN_ERR 5
BYTE scCopyFile(LPSTR srcPath, LPSTR destPath)
{
FILE *pfsrc, *pfdest;
int filelen, size;
pfsrc = fopen(srcPath, "rb" ;
if ( !pfsrc ) return F_OPENSRC_ERR;
if ( fseek(pfsrc, (LONG)0, SEEK_END) )
{
fclose(pfsrc);
return F_SRCSEEKEND_ERR;
}
filelen = ftell(pfsrc);
if ( fseek(pfsrc, (LONG)0, SEEK_SET) )
{
fclose(pfsrc);
return F_SRCSEEKSET_ERR;
}
pfdest = fopen(destPath, "wb" ;
if ( !pfdest )
{
fclose(pfsrc);
return F_OPENDEST_ERR;
}
while( filelen >; COPY_STRUNIT_LEN)
{
size = fread( (void *)szCopyStrUnit, 1, (size_t)COPY_STRUNIT_LEN, pfsrc);
fwrite( (void *)szCopyStrUnit, 1, (size_t)size, pfdest);
if( size != COPY_STRUNIT_LEN )
{
fclose(pfsrc);
fclose(pfdest);
return F_COPYLEN_ERR;
}
filelen = filelen - size;
}
if( filelen >; 0)
{
size = fread( (void *)szCopyStrUnit, 1, (size_t)filelen, pfsrc);
fwrite( (void *)szCopyStrUnit, 1, (size_t)filelen, pfdest);
}
fclose(pfsrc);
fclose(pfdest);
return F_COPY_DONE;
} |
|