file.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. #include "rar.hpp"
  2. static File *CreatedFiles[256];
  3. static int RemoveCreatedActive=0;
  4. File::File()
  5. {
  6. hFile=BAD_HANDLE;
  7. *FileName=0;
  8. *FileNameW=0;
  9. NewFile=false;
  10. LastWrite=false;
  11. HandleType=FILE_HANDLENORMAL;
  12. SkipClose=false;
  13. IgnoreReadErrors=false;
  14. ErrorType=FILE_SUCCESS;
  15. OpenShared=false;
  16. AllowDelete=true;
  17. CloseCount=0;
  18. AllowExceptions=true;
  19. #ifdef _WIN_ALL
  20. NoSequentialRead=false;
  21. #endif
  22. }
  23. File::~File()
  24. {
  25. if (hFile!=BAD_HANDLE && !SkipClose)
  26. if (NewFile)
  27. Delete();
  28. else
  29. Close();
  30. }
  31. void File::operator = (File &SrcFile)
  32. {
  33. hFile=SrcFile.hFile;
  34. strcpy(FileName,SrcFile.FileName);
  35. NewFile=SrcFile.NewFile;
  36. LastWrite=SrcFile.LastWrite;
  37. HandleType=SrcFile.HandleType;
  38. SrcFile.SkipClose=true;
  39. }
  40. bool File::Open(const char *Name,const wchar *NameW,bool OpenShared,bool Update)
  41. {
  42. ErrorType=FILE_SUCCESS;
  43. FileHandle hNewFile;
  44. if (File::OpenShared)
  45. OpenShared=true;
  46. #ifdef _WIN_ALL
  47. uint Access=GENERIC_READ;
  48. if (Update)
  49. Access|=GENERIC_WRITE;
  50. uint ShareMode=FILE_SHARE_READ;
  51. if (OpenShared)
  52. ShareMode|=FILE_SHARE_WRITE;
  53. uint Flags=NoSequentialRead ? 0:FILE_FLAG_SEQUENTIAL_SCAN;
  54. if (WinNT() && NameW!=NULL && *NameW!=0)
  55. hNewFile=CreateFileW(NameW,Access,ShareMode,NULL,OPEN_EXISTING,Flags,NULL);
  56. else
  57. hNewFile=CreateFileA(Name,Access,ShareMode,NULL,OPEN_EXISTING,Flags,NULL);
  58. if (hNewFile==BAD_HANDLE && GetLastError()==ERROR_FILE_NOT_FOUND)
  59. ErrorType=FILE_NOTFOUND;
  60. #else
  61. int flags=Update ? O_RDWR:O_RDONLY;
  62. #ifdef O_BINARY
  63. flags|=O_BINARY;
  64. #if defined(_AIX) && defined(_LARGE_FILE_API)
  65. flags|=O_LARGEFILE;
  66. #endif
  67. #endif
  68. #if defined(_EMX) && !defined(_DJGPP)
  69. int sflags=OpenShared ? SH_DENYNO:SH_DENYWR;
  70. int handle=sopen(Name,flags,sflags);
  71. #else
  72. int handle=open(Name,flags);
  73. #ifdef LOCK_EX
  74. #ifdef _OSF_SOURCE
  75. extern "C" int flock(int, int);
  76. #endif
  77. if (!OpenShared && Update && handle>=0 && flock(handle,LOCK_EX|LOCK_NB)==-1)
  78. {
  79. close(handle);
  80. return(false);
  81. }
  82. #endif
  83. #endif
  84. hNewFile=handle==-1 ? BAD_HANDLE:fdopen(handle,Update ? UPDATEBINARY:READBINARY);
  85. if (hNewFile==BAD_HANDLE && errno==ENOENT)
  86. ErrorType=FILE_NOTFOUND;
  87. #endif
  88. NewFile=false;
  89. HandleType=FILE_HANDLENORMAL;
  90. SkipClose=false;
  91. bool Success=hNewFile!=BAD_HANDLE;
  92. if (Success)
  93. {
  94. hFile=hNewFile;
  95. // We use memove instead of strcpy and wcscpy to avoid problems
  96. // with overlapped buffers. While we do not call this function with
  97. // really overlapped buffers yet, we do call it with Name equal to
  98. // FileName like Arc.Open(Arc.FileName,Arc.FileNameW).
  99. if (NameW!=NULL)
  100. memmove(FileNameW,NameW,(wcslen(NameW)+1)*sizeof(*NameW));
  101. else
  102. *FileNameW=0;
  103. if (Name!=NULL)
  104. memmove(FileName,Name,strlen(Name)+1);
  105. else
  106. WideToChar(NameW,FileName);
  107. AddFileToList(hFile);
  108. }
  109. return(Success);
  110. }
  111. #if !defined(SHELL_EXT) && !defined(SFX_MODULE)
  112. void File::TOpen(const char *Name,const wchar *NameW)
  113. {
  114. if (!WOpen(Name,NameW))
  115. ErrHandler.Exit(OPEN_ERROR);
  116. }
  117. #endif
  118. bool File::WOpen(const char *Name,const wchar *NameW)
  119. {
  120. if (Open(Name,NameW))
  121. return(true);
  122. ErrHandler.OpenErrorMsg(Name,NameW);
  123. return(false);
  124. }
  125. bool File::Create(const char *Name,const wchar *NameW,bool ShareRead)
  126. {
  127. #ifdef _WIN_ALL
  128. DWORD ShareMode=(ShareRead || File::OpenShared) ? FILE_SHARE_READ:0;
  129. if (WinNT() && NameW!=NULL && *NameW!=0)
  130. hFile=CreateFileW(NameW,GENERIC_READ|GENERIC_WRITE,ShareMode,NULL,
  131. CREATE_ALWAYS,0,NULL);
  132. else
  133. hFile=CreateFileA(Name,GENERIC_READ|GENERIC_WRITE,ShareMode,NULL,
  134. CREATE_ALWAYS,0,NULL);
  135. #else
  136. hFile=fopen(Name,CREATEBINARY);
  137. #endif
  138. NewFile=true;
  139. HandleType=FILE_HANDLENORMAL;
  140. SkipClose=false;
  141. if (NameW!=NULL)
  142. wcscpy(FileNameW,NameW);
  143. else
  144. *FileNameW=0;
  145. if (Name!=NULL)
  146. strcpy(FileName,Name);
  147. else
  148. WideToChar(NameW,FileName);
  149. AddFileToList(hFile);
  150. return(hFile!=BAD_HANDLE);
  151. }
  152. void File::AddFileToList(FileHandle hFile)
  153. {
  154. if (hFile!=BAD_HANDLE)
  155. for (int I=0;I<sizeof(CreatedFiles)/sizeof(CreatedFiles[0]);I++)
  156. if (CreatedFiles[I]==NULL)
  157. {
  158. CreatedFiles[I]=this;
  159. break;
  160. }
  161. }
  162. #if !defined(SHELL_EXT) && !defined(SFX_MODULE)
  163. void File::TCreate(const char *Name,const wchar *NameW,bool ShareRead)
  164. {
  165. if (!WCreate(Name,NameW,ShareRead))
  166. ErrHandler.Exit(FATAL_ERROR);
  167. }
  168. #endif
  169. bool File::WCreate(const char *Name,const wchar *NameW,bool ShareRead)
  170. {
  171. if (Create(Name,NameW,ShareRead))
  172. return(true);
  173. ErrHandler.SetErrorCode(CREATE_ERROR);
  174. ErrHandler.CreateErrorMsg(Name,NameW);
  175. return(false);
  176. }
  177. bool File::Close()
  178. {
  179. bool Success=true;
  180. if (HandleType!=FILE_HANDLENORMAL)
  181. HandleType=FILE_HANDLENORMAL;
  182. else
  183. if (hFile!=BAD_HANDLE)
  184. {
  185. if (!SkipClose)
  186. {
  187. #ifdef _WIN_ALL
  188. Success=CloseHandle(hFile)==TRUE;
  189. #else
  190. Success=fclose(hFile)!=EOF;
  191. #endif
  192. if (Success || !RemoveCreatedActive)
  193. for (int I=0;I<sizeof(CreatedFiles)/sizeof(CreatedFiles[0]);I++)
  194. if (CreatedFiles[I]==this)
  195. {
  196. CreatedFiles[I]=NULL;
  197. break;
  198. }
  199. }
  200. hFile=BAD_HANDLE;
  201. if (!Success && AllowExceptions)
  202. ErrHandler.CloseError(FileName,FileNameW);
  203. }
  204. CloseCount++;
  205. return(Success);
  206. }
  207. void File::Flush()
  208. {
  209. #ifdef _WIN_ALL
  210. FlushFileBuffers(hFile);
  211. #else
  212. fflush(hFile);
  213. #endif
  214. }
  215. bool File::Delete()
  216. {
  217. if (HandleType!=FILE_HANDLENORMAL)
  218. return(false);
  219. if (hFile!=BAD_HANDLE)
  220. Close();
  221. if (!AllowDelete)
  222. return(false);
  223. return(DelFile(FileName,FileNameW));
  224. }
  225. bool File::Rename(const char *NewName,const wchar *NewNameW)
  226. {
  227. // we do not need to rename if names are already same
  228. bool Success=strcmp(FileName,NewName)==0;
  229. if (Success && *FileNameW!=0 && *NullToEmpty(NewNameW)!=0)
  230. Success=wcscmp(FileNameW,NewNameW)==0;
  231. if (!Success)
  232. Success=RenameFile(FileName,FileNameW,NewName,NewNameW);
  233. if (Success)
  234. {
  235. // renamed successfully, storing the new name
  236. strcpy(FileName,NewName);
  237. wcscpy(FileNameW,NullToEmpty(NewNameW));
  238. }
  239. return(Success);
  240. }
  241. void File::Write(const void *Data,size_t Size)
  242. {
  243. if (Size==0)
  244. return;
  245. #ifndef _WIN_CE
  246. if (HandleType!=FILE_HANDLENORMAL)
  247. switch(HandleType)
  248. {
  249. case FILE_HANDLESTD:
  250. #ifdef _WIN_ALL
  251. hFile=GetStdHandle(STD_OUTPUT_HANDLE);
  252. #else
  253. hFile=stdout;
  254. #endif
  255. break;
  256. case FILE_HANDLEERR:
  257. #ifdef _WIN_ALL
  258. hFile=GetStdHandle(STD_ERROR_HANDLE);
  259. #else
  260. hFile=stderr;
  261. #endif
  262. break;
  263. }
  264. #endif
  265. while (1)
  266. {
  267. bool Success=false;
  268. #ifdef _WIN_ALL
  269. DWORD Written=0;
  270. if (HandleType!=FILE_HANDLENORMAL)
  271. {
  272. // writing to stdout can fail in old Windows if data block is too large
  273. const size_t MaxSize=0x4000;
  274. for (size_t I=0;I<Size;I+=MaxSize)
  275. {
  276. Success=WriteFile(hFile,(byte *)Data+I,(DWORD)Min(Size-I,MaxSize),&Written,NULL)==TRUE;
  277. if (!Success)
  278. break;
  279. }
  280. }
  281. else
  282. Success=WriteFile(hFile,Data,(DWORD)Size,&Written,NULL)==TRUE;
  283. #else
  284. int Written=fwrite(Data,1,Size,hFile);
  285. Success=Written==Size && !ferror(hFile);
  286. #endif
  287. if (!Success && AllowExceptions && HandleType==FILE_HANDLENORMAL)
  288. {
  289. #if defined(_WIN_ALL) && !defined(SFX_MODULE) && !defined(RARDLL)
  290. int ErrCode=GetLastError();
  291. int64 FilePos=Tell();
  292. uint64 FreeSize=GetFreeDisk(FileName);
  293. SetLastError(ErrCode);
  294. if (FreeSize>Size && FilePos-Size<=0xffffffff && FilePos+Size>0xffffffff)
  295. ErrHandler.WriteErrorFAT(FileName,FileNameW);
  296. #endif
  297. if (ErrHandler.AskRepeatWrite(FileName,FileNameW,false))
  298. {
  299. #ifndef _WIN_ALL
  300. clearerr(hFile);
  301. #endif
  302. if (Written<Size && Written>0)
  303. Seek(Tell()-Written,SEEK_SET);
  304. continue;
  305. }
  306. ErrHandler.WriteError(NULL,NULL,FileName,FileNameW);
  307. }
  308. break;
  309. }
  310. LastWrite=true;
  311. }
  312. int File::Read(void *Data,size_t Size)
  313. {
  314. int64 FilePos=0; // Initialized only to suppress some compilers warning.
  315. if (IgnoreReadErrors)
  316. FilePos=Tell();
  317. int ReadSize;
  318. while (true)
  319. {
  320. ReadSize=DirectRead(Data,Size);
  321. if (ReadSize==-1)
  322. {
  323. ErrorType=FILE_READERROR;
  324. if (AllowExceptions)
  325. if (IgnoreReadErrors)
  326. {
  327. ReadSize=0;
  328. for (size_t I=0;I<Size;I+=512)
  329. {
  330. Seek(FilePos+I,SEEK_SET);
  331. size_t SizeToRead=Min(Size-I,512);
  332. int ReadCode=DirectRead(Data,SizeToRead);
  333. ReadSize+=(ReadCode==-1) ? 512:ReadCode;
  334. }
  335. }
  336. else
  337. {
  338. if (HandleType==FILE_HANDLENORMAL && ErrHandler.AskRepeatRead(FileName,FileNameW))
  339. continue;
  340. ErrHandler.ReadError(FileName,FileNameW);
  341. }
  342. }
  343. break;
  344. }
  345. return(ReadSize);
  346. }
  347. // Returns -1 in case of error.
  348. int File::DirectRead(void *Data,size_t Size)
  349. {
  350. #ifdef _WIN_ALL
  351. const size_t MaxDeviceRead=20000;
  352. #endif
  353. #ifndef _WIN_CE
  354. if (HandleType==FILE_HANDLESTD)
  355. {
  356. #ifdef _WIN_ALL
  357. if (Size>MaxDeviceRead)
  358. Size=MaxDeviceRead;
  359. hFile=GetStdHandle(STD_INPUT_HANDLE);
  360. #else
  361. hFile=stdin;
  362. #endif
  363. }
  364. #endif
  365. #ifdef _WIN_ALL
  366. DWORD Read;
  367. if (!ReadFile(hFile,Data,(DWORD)Size,&Read,NULL))
  368. {
  369. if (IsDevice() && Size>MaxDeviceRead)
  370. return(DirectRead(Data,MaxDeviceRead));
  371. if (HandleType==FILE_HANDLESTD && GetLastError()==ERROR_BROKEN_PIPE)
  372. return(0);
  373. return(-1);
  374. }
  375. return(Read);
  376. #else
  377. if (LastWrite)
  378. {
  379. fflush(hFile);
  380. LastWrite=false;
  381. }
  382. clearerr(hFile);
  383. size_t ReadSize=fread(Data,1,Size,hFile);
  384. if (ferror(hFile))
  385. return(-1);
  386. return((int)ReadSize);
  387. #endif
  388. }
  389. void File::Seek(int64 Offset,int Method)
  390. {
  391. if (!RawSeek(Offset,Method) && AllowExceptions)
  392. ErrHandler.SeekError(FileName,FileNameW);
  393. }
  394. bool File::RawSeek(int64 Offset,int Method)
  395. {
  396. if (hFile==BAD_HANDLE)
  397. return(true);
  398. if (Offset<0 && Method!=SEEK_SET)
  399. {
  400. Offset=(Method==SEEK_CUR ? Tell():FileLength())+Offset;
  401. Method=SEEK_SET;
  402. }
  403. #ifdef _WIN_ALL
  404. LONG HighDist=(LONG)(Offset>>32);
  405. if (SetFilePointer(hFile,(LONG)Offset,&HighDist,Method)==0xffffffff &&
  406. GetLastError()!=NO_ERROR)
  407. return(false);
  408. #else
  409. LastWrite=false;
  410. #if defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE) && !defined(__VMS)
  411. if (fseeko(hFile,Offset,Method)!=0)
  412. #else
  413. if (fseek(hFile,(long)Offset,Method)!=0)
  414. #endif
  415. return(false);
  416. #endif
  417. return(true);
  418. }
  419. int64 File::Tell()
  420. {
  421. if (hFile==BAD_HANDLE)
  422. if (AllowExceptions)
  423. ErrHandler.SeekError(FileName,FileNameW);
  424. else
  425. return(-1);
  426. #ifdef _WIN_ALL
  427. LONG HighDist=0;
  428. uint LowDist=SetFilePointer(hFile,0,&HighDist,FILE_CURRENT);
  429. if (LowDist==0xffffffff && GetLastError()!=NO_ERROR)
  430. if (AllowExceptions)
  431. ErrHandler.SeekError(FileName,FileNameW);
  432. else
  433. return(-1);
  434. return(INT32TO64(HighDist,LowDist));
  435. #else
  436. #if defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE)
  437. return(ftello(hFile));
  438. #else
  439. return(ftell(hFile));
  440. #endif
  441. #endif
  442. }
  443. void File::Prealloc(int64 Size)
  444. {
  445. #ifdef _WIN_ALL
  446. if (RawSeek(Size,SEEK_SET))
  447. {
  448. Truncate();
  449. Seek(0,SEEK_SET);
  450. }
  451. #endif
  452. #if defined(_UNIX) && defined(USE_FALLOCATE)
  453. // fallocate is rather new call. Only latest kernels support it.
  454. // So we are not using it by default yet.
  455. int fd = fileno(hFile);
  456. if (fd >= 0)
  457. fallocate(fd, 0, 0, Size);
  458. #endif
  459. }
  460. byte File::GetByte()
  461. {
  462. byte Byte=0;
  463. Read(&Byte,1);
  464. return(Byte);
  465. }
  466. void File::PutByte(byte Byte)
  467. {
  468. Write(&Byte,1);
  469. }
  470. bool File::Truncate()
  471. {
  472. #ifdef _WIN_ALL
  473. return(SetEndOfFile(hFile)==TRUE);
  474. #else
  475. return(false);
  476. #endif
  477. }
  478. void File::SetOpenFileTime(RarTime *ftm,RarTime *ftc,RarTime *fta)
  479. {
  480. #ifdef _WIN_ALL
  481. bool sm=ftm!=NULL && ftm->IsSet();
  482. bool sc=ftc!=NULL && ftc->IsSet();
  483. bool sa=fta!=NULL && fta->IsSet();
  484. FILETIME fm,fc,fa;
  485. if (sm)
  486. ftm->GetWin32(&fm);
  487. if (sc)
  488. ftc->GetWin32(&fc);
  489. if (sa)
  490. fta->GetWin32(&fa);
  491. SetFileTime(hFile,sc ? &fc:NULL,sa ? &fa:NULL,sm ? &fm:NULL);
  492. #endif
  493. }
  494. void File::SetCloseFileTime(RarTime *ftm,RarTime *fta)
  495. {
  496. #if defined(_UNIX) || defined(_EMX)
  497. SetCloseFileTimeByName(FileName,ftm,fta);
  498. #endif
  499. }
  500. void File::SetCloseFileTimeByName(const char *Name,RarTime *ftm,RarTime *fta)
  501. {
  502. #if defined(_UNIX) || defined(_EMX)
  503. bool setm=ftm!=NULL && ftm->IsSet();
  504. bool seta=fta!=NULL && fta->IsSet();
  505. if (setm || seta)
  506. {
  507. utimbuf ut;
  508. if (setm)
  509. ut.modtime=ftm->GetUnix();
  510. else
  511. ut.modtime=fta->GetUnix();
  512. if (seta)
  513. ut.actime=fta->GetUnix();
  514. else
  515. ut.actime=ut.modtime;
  516. utime(Name,&ut);
  517. }
  518. #endif
  519. }
  520. void File::GetOpenFileTime(RarTime *ft)
  521. {
  522. #ifdef _WIN_ALL
  523. FILETIME FileTime;
  524. GetFileTime(hFile,NULL,NULL,&FileTime);
  525. *ft=FileTime;
  526. #endif
  527. #if defined(_UNIX) || defined(_EMX)
  528. struct stat st;
  529. fstat(fileno(hFile),&st);
  530. *ft=st.st_mtime;
  531. #endif
  532. }
  533. int64 File::FileLength()
  534. {
  535. SaveFilePos SavePos(*this);
  536. Seek(0,SEEK_END);
  537. return(Tell());
  538. }
  539. void File::SetHandleType(FILE_HANDLETYPE Type)
  540. {
  541. HandleType=Type;
  542. }
  543. bool File::IsDevice()
  544. {
  545. if (hFile==BAD_HANDLE)
  546. return(false);
  547. #ifdef _WIN_ALL
  548. uint Type=GetFileType(hFile);
  549. return(Type==FILE_TYPE_CHAR || Type==FILE_TYPE_PIPE);
  550. #else
  551. return(isatty(fileno(hFile)));
  552. #endif
  553. }
  554. #ifndef SFX_MODULE
  555. void File::fprintf(const char *fmt,...)
  556. {
  557. va_list argptr;
  558. va_start(argptr,fmt);
  559. safebuf char Msg[2*NM+1024],OutMsg[2*NM+1024];
  560. vsprintf(Msg,fmt,argptr);
  561. #ifdef _WIN_ALL
  562. for (int Src=0,Dest=0;;Src++)
  563. {
  564. char CurChar=Msg[Src];
  565. if (CurChar=='\n')
  566. OutMsg[Dest++]='\r';
  567. OutMsg[Dest++]=CurChar;
  568. if (CurChar==0)
  569. break;
  570. }
  571. #else
  572. strcpy(OutMsg,Msg);
  573. #endif
  574. Write(OutMsg,strlen(OutMsg));
  575. va_end(argptr);
  576. }
  577. #endif
  578. bool File::RemoveCreated()
  579. {
  580. RemoveCreatedActive++;
  581. bool RetCode=true;
  582. for (int I=0;I<sizeof(CreatedFiles)/sizeof(CreatedFiles[0]);I++)
  583. if (CreatedFiles[I]!=NULL)
  584. {
  585. CreatedFiles[I]->SetExceptions(false);
  586. bool Success;
  587. if (CreatedFiles[I]->NewFile)
  588. Success=CreatedFiles[I]->Delete();
  589. else
  590. Success=CreatedFiles[I]->Close();
  591. if (Success)
  592. CreatedFiles[I]=NULL;
  593. else
  594. RetCode=false;
  595. }
  596. RemoveCreatedActive--;
  597. return(RetCode);
  598. }
  599. #ifndef SFX_MODULE
  600. int64 File::Copy(File &Dest,int64 Length)
  601. {
  602. Array<char> Buffer(0x10000);
  603. int64 CopySize=0;
  604. bool CopyAll=(Length==INT64NDF);
  605. while (CopyAll || Length>0)
  606. {
  607. Wait();
  608. size_t SizeToRead=(!CopyAll && Length<(int64)Buffer.Size()) ? (size_t)Length:Buffer.Size();
  609. int ReadSize=Read(&Buffer[0],SizeToRead);
  610. if (ReadSize==0)
  611. break;
  612. Dest.Write(&Buffer[0],ReadSize);
  613. CopySize+=ReadSize;
  614. if (!CopyAll)
  615. Length-=ReadSize;
  616. }
  617. return(CopySize);
  618. }
  619. #endif