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