2
0

file.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. {
  2. This file is part of the Free Pascal Run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WithOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {****************************************************************************
  11. subroutines For UnTyped File handling
  12. ****************************************************************************}
  13. type
  14. UnTypedFile=File;
  15. procedure InitFile(var f : file);
  16. begin
  17. FillChar(f,SizeOf(FileRec),0);
  18. FileRec(f).Handle:=UnusedHandle;
  19. FileRec(f).mode:=fmClosed;
  20. end;
  21. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  22. Procedure Assign(out f:File;const Name: UnicodeString);
  23. {
  24. Assign Name to file f so it can be used with the file routines
  25. }
  26. Begin
  27. InitFile(F);
  28. {$ifdef FPC_ANSI_TEXTFILEREC}
  29. FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name);
  30. {$ifdef USE_FILEREC_FULLNAME}
  31. if Length(Name)>255 then
  32. RawByteString(FileRec(f).FullName):=Name;
  33. {$endif USE_FILEREC_FULLNAME}
  34. {$else FPC_ANSI_TEXTFILEREC}
  35. FileRec(f).Name:=Name;
  36. {$ifdef USE_FILEREC_FULLNAME}
  37. if Length(Name)>255 then
  38. UnicodeString(FileRec(f).FullName):=Name;
  39. {$endif USE_FILEREC_FULLNAME}
  40. {$endif FPC_ANSI_TEXTFILEREC}
  41. { null terminate, since the name array is regularly used as p(wide)char }
  42. FileRec(f).Name[high(FileRec(f).Name)]:=#0;
  43. End;
  44. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  45. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  46. Procedure Assign(out f:File;const Name: RawByteString);
  47. {
  48. Assign Name to file f so it can be used with the file routines
  49. }
  50. Begin
  51. InitFile(F);
  52. {$ifdef FPC_ANSI_TEXTFILEREC}
  53. { ensure the characters in the record's filename are encoded correctly }
  54. FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(Name);
  55. {$ifdef USE_FILEREC_FULLNAME}
  56. if Length(Name)>255 then
  57. RawbyteString(FileRec(f).FullName):=Name;
  58. {$endif USE_FILEREC_FULLNAME}
  59. {$else FPC_ANSI_TEXTFILEREC}
  60. FileRec(f).Name:=Name;
  61. {$ifdef USE_FILEREC_FULLNAME}
  62. if Length(Name)>255 then
  63. UnicodeString(FileRec(f).FullName):=Name;
  64. {$endif USE_FILEREC_FULLNAME}
  65. {$endif FPC_ANSI_TEXTFILEREC}
  66. { null terminate, since the name array is regularly used as p(wide)char }
  67. FileRec(f).Name[high(FileRec(f).Name)]:=#0;
  68. End;
  69. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  70. Procedure Assign(out f:File;const Name: ShortString);
  71. {
  72. Assign Name to file f so it can be used with the file routines
  73. }
  74. Begin
  75. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  76. Assign(f,AnsiString(Name));
  77. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  78. InitFile(f);
  79. { warning: no encoding support }
  80. FileRec(f).Name:=Name;
  81. { null terminate, since the name array is regularly used as p(wide)char }
  82. FileRec(f).Name[high(FileRec(f).Name)]:=#0;
  83. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  84. End;
  85. Procedure Assign(out f:File;const p: PAnsiChar);
  86. Begin
  87. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  88. Assign(f,AnsiString(p));
  89. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  90. { no use in making this the one that does the work, since the name field is
  91. limited to 255 characters anyway }
  92. Assign(f,strpas(p));
  93. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  94. End;
  95. Procedure Assign(out f:File;const c: AnsiChar);
  96. Begin
  97. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  98. Assign(f,AnsiString(c));
  99. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  100. Assign(f,ShortString(c));
  101. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  102. End;
  103. Procedure Rewrite(var f:File;l:Longint);[IOCheck];
  104. {
  105. Create file f with recordsize of l
  106. }
  107. Begin
  108. If InOutRes <> 0 then
  109. exit;
  110. Case FileRec(f).mode Of
  111. fmInOut,fmInput,fmOutput : Close(f);
  112. fmClosed : ;
  113. else
  114. Begin
  115. InOutRes:=102;
  116. exit;
  117. End;
  118. End;
  119. If l=0 Then
  120. InOutRes:=2
  121. else
  122. Begin
  123. { Reopen with filemode 2, to be Tp compatible (PFV) }
  124. {$ifdef USE_FILEREC_FULLNAME}
  125. if Assigned(FileRec(f).FullName) then
  126. Do_Open(f,FileRec(f).FullName,$1002,false)
  127. else
  128. {$endif USE_FILEREC_FULLNAME}
  129. Do_Open(f,PFileTextRecChar(@FileRec(f).Name),$1002,false);
  130. FileRec(f).RecSize:=l;
  131. End;
  132. End;
  133. Procedure Reset(var f:File;l:Longint);[IOCheck];
  134. {
  135. Open file f with recordsize of l and filemode
  136. }
  137. Begin
  138. If InOutRes <> 0 then
  139. Exit;
  140. Case FileRec(f).mode Of
  141. fmInOut,fmInput,fmOutput : Close(f);
  142. fmClosed : ;
  143. else
  144. Begin
  145. InOutRes:=102;
  146. exit;
  147. End;
  148. End;
  149. If l=0 Then
  150. InOutRes:=2
  151. else
  152. Begin
  153. {$ifdef USE_FILEREC_FULLNAME}
  154. if Assigned(FileRec(f).FullName) then
  155. Do_Open(f,FileRec(f).FullName,Filemode,false)
  156. else
  157. {$endif USE_FILEREC_FULLNAME}
  158. Do_Open(f,PFileTextRecChar(@FileRec(f).Name),Filemode,false);
  159. FileRec(f).RecSize:=l;
  160. End;
  161. End;
  162. Procedure Rewrite(Var f:File);[IOCheck];
  163. {
  164. Create file with (default) 128 byte records
  165. }
  166. Begin
  167. If InOutRes <> 0 then
  168. exit;
  169. Rewrite(f,128);
  170. End;
  171. Procedure Reset(Var f:File);[IOCheck];
  172. {
  173. Open file with (default) 128 byte records
  174. }
  175. Begin
  176. If InOutRes <> 0 then
  177. exit;
  178. Reset(f,128);
  179. End;
  180. Procedure BlockWrite(Var f:File;Const Buf;Count:Int64;var Result:Int64);[IOCheck];
  181. {
  182. Write Count records from Buf to file f, return written records in result
  183. }
  184. Begin
  185. Result:=0;
  186. If InOutRes <> 0 then
  187. exit;
  188. case FileRec(f).Mode of
  189. fmInOut,fmOutput :
  190. Result:=Do_Write(FileRec(f).Handle,@Buf,Count*FileRec(f).RecSize)
  191. div FileRec(f).RecSize;
  192. fmInPut: inOutRes := 105;
  193. else InOutRes:=103;
  194. end;
  195. End;
  196. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;var Result:Longint);[IOCheck];
  197. {
  198. Write Count records from Buf to file f, return written records in result
  199. }
  200. {$ifdef EXCLUDE_COMPLEX_PROCS}
  201. begin
  202. runerror(217);
  203. end;
  204. {$else EXCLUDE_COMPLEX_PROCS}
  205. var
  206. l : Int64;
  207. Begin
  208. BlockWrite(f,Buf,Count,l);
  209. Result:=longint(l);
  210. End;
  211. {$endif EXCLUDE_COMPLEX_PROCS}
  212. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;var Result:Word);[IOCheck];
  213. {
  214. Write Count records from Buf to file f, return written records in Result
  215. }
  216. {$ifdef EXCLUDE_COMPLEX_PROCS}
  217. begin
  218. runerror(217);
  219. end;
  220. {$else EXCLUDE_COMPLEX_PROCS}
  221. var
  222. l : Int64;
  223. Begin
  224. BlockWrite(f,Buf,Count,l);
  225. Result:=word(l);
  226. End;
  227. {$endif EXCLUDE_COMPLEX_PROCS}
  228. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);[IOCheck];
  229. {
  230. Write Count records from Buf to file f, return written records in Result
  231. }
  232. {$ifdef EXCLUDE_COMPLEX_PROCS}
  233. begin
  234. runerror(217);
  235. end;
  236. {$else EXCLUDE_COMPLEX_PROCS}
  237. var
  238. l : Int64;
  239. Begin
  240. BlockWrite(f,Buf,Count,l);
  241. Result:=l;
  242. End;
  243. {$endif EXCLUDE_COMPLEX_PROCS}
  244. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;var Result:Integer);[IOCheck];
  245. {
  246. Write Count records from Buf to file f, return written records in Result
  247. }
  248. {$ifdef EXCLUDE_COMPLEX_PROCS}
  249. begin
  250. runerror(217);
  251. end;
  252. {$else EXCLUDE_COMPLEX_PROCS}
  253. var
  254. l : Int64;
  255. Begin
  256. BlockWrite(f,Buf,Count,l);
  257. Result:=integer(l);
  258. End;
  259. {$endif EXCLUDE_COMPLEX_PROCS}
  260. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);[IOCheck];
  261. {
  262. Write Count records from Buf to file f, if none a Read and Count>0 then
  263. InOutRes is set
  264. }
  265. {$ifdef EXCLUDE_COMPLEX_PROCS}
  266. begin
  267. runerror(217);
  268. end;
  269. {$else EXCLUDE_COMPLEX_PROCS}
  270. var
  271. Result : Int64;
  272. Begin
  273. BlockWrite(f,Buf,Count,Result);
  274. If (InOutRes=0) and (Result<Count) and (Count>0) Then
  275. InOutRes:=101;
  276. End;
  277. {$endif EXCLUDE_COMPLEX_PROCS}
  278. Procedure BlockRead(var f:File;var Buf;Count:Int64;var Result:Int64);[IOCheck];
  279. {
  280. Read Count records from file f ro Buf, return number of read records in
  281. Result
  282. }
  283. Begin
  284. Result:=0;
  285. If InOutRes <> 0 then
  286. exit;
  287. case FileRec(f).Mode of
  288. fmInOut,fmInput :
  289. Result:=Do_Read(FileRec(f).Handle,@Buf,count*FileRec(f).RecSize)
  290. div FileRec(f).RecSize;
  291. fmOutput: inOutRes := 104;
  292. else InOutRes:=103;
  293. end;
  294. End;
  295. Procedure BlockRead(var f:File;var Buf;Count:Longint;var Result:Longint);[IOCheck];
  296. {
  297. Read Count records from file f ro Buf, return number of read records in
  298. Result
  299. }
  300. {$ifdef EXCLUDE_COMPLEX_PROCS}
  301. begin
  302. runerror(217);
  303. end;
  304. {$else EXCLUDE_COMPLEX_PROCS}
  305. var
  306. l : int64;
  307. Begin
  308. BlockRead(f,Buf,Count,l);
  309. Result:=longint(l);
  310. End;
  311. {$endif EXCLUDE_COMPLEX_PROCS}
  312. Procedure BlockRead(var f:File;var Buf;count:Word;var Result:Word);[IOCheck];
  313. {
  314. Read Count records from file f to Buf, return number of read records in
  315. Result
  316. }
  317. {$ifdef EXCLUDE_COMPLEX_PROCS}
  318. begin
  319. runerror(217);
  320. end;
  321. {$else EXCLUDE_COMPLEX_PROCS}
  322. var
  323. l : int64;
  324. Begin
  325. BlockRead(f,Buf,Count,l);
  326. Result:=word(l);
  327. End;
  328. {$endif EXCLUDE_COMPLEX_PROCS}
  329. Procedure BlockRead(var f:File;var Buf;count:Cardinal;var Result:Cardinal);[IOCheck];
  330. {
  331. Read Count records from file f to Buf, return number of read records in
  332. Result
  333. }
  334. {$ifdef EXCLUDE_COMPLEX_PROCS}
  335. begin
  336. runerror(217);
  337. end;
  338. {$else EXCLUDE_COMPLEX_PROCS}
  339. var
  340. l : int64;
  341. Begin
  342. BlockRead(f,Buf,Count,l);
  343. Result:=l;
  344. End;
  345. {$endif EXCLUDE_COMPLEX_PROCS}
  346. Procedure BlockRead(var f:File;var Buf;count:Word;var Result:Integer);[IOCheck];
  347. {
  348. Read Count records from file f to Buf, return number of read records in
  349. Result
  350. }
  351. {$ifdef EXCLUDE_COMPLEX_PROCS}
  352. begin
  353. runerror(217);
  354. end;
  355. {$else EXCLUDE_COMPLEX_PROCS}
  356. var
  357. l : int64;
  358. Begin
  359. BlockRead(f,Buf,Count,l);
  360. Result:=integer(l);
  361. End;
  362. {$endif EXCLUDE_COMPLEX_PROCS}
  363. Procedure BlockRead(Var f:File;Var Buf;Count:Int64);[IOCheck];
  364. {
  365. Read Count records from file f to Buf, if none are read and Count>0 then
  366. InOutRes is set
  367. }
  368. {$ifdef EXCLUDE_COMPLEX_PROCS}
  369. begin
  370. runerror(217);
  371. end;
  372. {$else EXCLUDE_COMPLEX_PROCS}
  373. var
  374. Result : int64;
  375. Begin
  376. BlockRead(f,Buf,Count,Result);
  377. If (InOutRes=0) and (Result<Count) and (Count>0) Then
  378. InOutRes:=100;
  379. End;
  380. {$endif EXCLUDE_COMPLEX_PROCS}
  381. Function FilePos(var f:File):Int64;[IOCheck];
  382. {
  383. Return current Position In file f in records
  384. }
  385. Begin
  386. FilePos:=0;
  387. If InOutRes <> 0 then
  388. exit;
  389. case FileRec(f).Mode of
  390. fmInOut,fmInput,fmOutput :
  391. FilePos:=Do_FilePos(FileRec(f).Handle) div FileRec(f).RecSize;
  392. else
  393. InOutRes:=103;
  394. end;
  395. End;
  396. Function FileSize(var f:File):Int64;[IOCheck];
  397. {
  398. Return the size of file f in records
  399. }
  400. Begin
  401. FileSize:=0;
  402. If InOutRes <> 0 then
  403. exit;
  404. case FileRec(f).Mode of
  405. fmInOut,fmInput,fmOutput :
  406. begin
  407. if (FileRec(f).RecSize>0) then
  408. FileSize:=Do_FileSize(FileRec(f).Handle) div FileRec(f).RecSize;
  409. end;
  410. else InOutRes:=103;
  411. end;
  412. End;
  413. Function Eof(var f:File):Boolean;[IOCheck];
  414. {
  415. Return True if we're at the end of the file f, else False is returned
  416. }
  417. Begin
  418. Eof:=false;
  419. If InOutRes <> 0 then
  420. exit;
  421. case FileRec(f).Mode of
  422. {Can't use do_ routines because we need record support}
  423. fmInOut,fmInput,fmOutput : Eof:=(FileSize(f)<=FilePos(f));
  424. else InOutRes:=103;
  425. end;
  426. End;
  427. Procedure Seek(var f:File;Pos:Int64);[IOCheck];
  428. {
  429. Goto record Pos in file f
  430. }
  431. Begin
  432. If InOutRes <> 0 then
  433. exit;
  434. case FileRec(f).Mode of
  435. fmInOut,fmInput,fmOutput :
  436. Do_Seek(FileRec(f).Handle,Pos*FileRec(f).RecSize);
  437. else InOutRes:=103;
  438. end;
  439. End;
  440. Procedure Truncate(Var f:File);[IOCheck];
  441. {
  442. Truncate/Cut file f at the current record Position
  443. }
  444. Begin
  445. If InOutRes <> 0 then
  446. exit;
  447. case FileRec(f).Mode of
  448. fmInOut,fmOutput :
  449. Do_Truncate(FileRec(f).Handle,FilePos(f)*FileRec(f).RecSize);
  450. else InOutRes:=103;
  451. end;
  452. End;
  453. Procedure Close(var f:File);[IOCheck];
  454. {
  455. Close file f
  456. }
  457. Begin
  458. If InOutRes <> 0 then
  459. exit;
  460. case FileRec(f).Mode of
  461. fmInOut,fmInput,fmOutput :
  462. begin
  463. Do_Close(FileRec(f).Handle);
  464. FileRec(f).mode:=fmClosed;
  465. end
  466. else InOutRes:=103;
  467. end;
  468. {$ifdef USE_FILEREC_FULLNAME}
  469. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  470. UnicodeString(FileRec(f).FullName):='';
  471. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  472. {$endif USE_FILEREC_FULLNAME}
  473. End;
  474. Procedure Erase(var f : File);[IOCheck];
  475. Begin
  476. if InOutRes<>0 then
  477. exit;
  478. if FileRec(f).mode<>fmClosed then
  479. begin
  480. InOutRes:=102;
  481. exit;
  482. end;
  483. Do_Erase(PFileTextRecChar(@FileRec(f).Name),false);
  484. End;
  485. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  486. Procedure Rename(var f : File; const S : UnicodeString);[IOCheck];
  487. {$ifdef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  488. var
  489. fs: RawByteString;
  490. {$endif FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  491. Begin
  492. if InOutRes<>0 then
  493. exit;
  494. if FileRec(f).mode<>fmClosed then
  495. begin
  496. InOutRes:=102;
  497. exit;
  498. end;
  499. {$ifdef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  500. { it's slightly faster to convert the unicodestring here to rawbytestring
  501. than doing it in do_rename(), because here we still know the length }
  502. fs:=ToSingleByteFileSystemEncodedFileName(s);
  503. Do_Rename(PFileTextRecChar(@FileRec(f).Name),PAnsiChar(fs),false,true);
  504. If InOutRes=0 then
  505. FileRec(f).Name:=fs
  506. {$else FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  507. Do_Rename(PFileTextRecChar(@FileRec(f).Name),PUnicodeChar(S),false,false);
  508. If InOutRes=0 then
  509. {$ifdef FPC_ANSI_TEXTFILEREC}
  510. FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(s);
  511. {$else FPC_ANSI_TEXTFILEREC}
  512. FileRec(f).Name:=s
  513. {$endif FPC_ANSI_TEXTFILEREC}
  514. {$endif FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  515. End;
  516. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  517. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  518. Procedure Rename(var f : File;const s : RawByteString);[IOCheck];
  519. var
  520. {$ifdef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  521. fs: RawByteString;
  522. pdst: PAnsiChar;
  523. {$else FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  524. fs: UnicodeString;
  525. pdst: PUnicodeChar;
  526. {$endif FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  527. dstchangeable: boolean;
  528. Begin
  529. if InOutRes<>0 then
  530. exit;
  531. if FileRec(f).mode<>fmClosed then
  532. begin
  533. InOutRes:=102;
  534. exit;
  535. end;
  536. {$ifdef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  537. dstchangeable:=false;
  538. pdst:=PAnsiChar(s);
  539. if StringCodePage(s)<>DefaultFileSystemCodePage then
  540. begin
  541. fs:=ToSingleByteFileSystemEncodedFileName(s);
  542. pdst:=PAnsiChar(fs);
  543. dstchangeable:=true;
  544. end
  545. else
  546. fs:=s;
  547. {$else FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  548. { it's slightly faster to convert the rawbytestring here to unicodestring
  549. than doing it in do_rename, because here we still know the length }
  550. fs:=unicodestring(s);
  551. pdst:=PUnicodeChar(fs);
  552. dstchangeable:=true;
  553. {$endif FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  554. Do_Rename(PFileTextRecChar(@FileRec(f).Name),pdst,false,dstchangeable);
  555. If InOutRes=0 then
  556. {$if defined(FPC_ANSI_TEXTFILEREC) and not defined(FPCRTL_FILESYSTEM_SINGLE_BYTE_API)}
  557. FileRec(f).Name:=ToSingleByteFileSystemEncodedFileName(fs)
  558. {$else FPC_ANSI_TEXTFILEREC and not FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  559. FileRec(f).Name:=fs
  560. {$endif FPC_ANSI_TEXTFILEREC and not FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  561. End;
  562. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  563. Procedure Rename(var f : File;const s : ShortString);[IOCheck];
  564. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  565. Begin
  566. Rename(f,AnsiString(s));
  567. End;
  568. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  569. var
  570. p : array[0..255] Of Char;
  571. Begin
  572. Move(s[1],p,Length(s));
  573. p[Length(s)]:=#0;
  574. Rename(f,Pchar(@p));
  575. End;
  576. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  577. Procedure Rename(var f:File;const p : PAnsiChar);[IOCheck];
  578. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  579. Begin
  580. Rename(f,AnsiString(p));
  581. End;
  582. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  583. var
  584. len: SizeInt;
  585. Begin
  586. if InOutRes<>0 then
  587. exit;
  588. if FileRec(f).mode<>fmClosed then
  589. begin
  590. InOutRes:=102;
  591. exit;
  592. end;
  593. Do_Rename(PFileTextRecChar(@FileRec(f).Name),p,false,false);
  594. { check error code of do_rename }
  595. if InOutRes=0 then
  596. begin
  597. len:=min(StrLen(p),high(FileRec(f).Name));
  598. Move(p^,FileRec(f).Name,len);
  599. FileRec(f).Name[len]:=#0;
  600. end;
  601. End;
  602. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  603. Procedure Rename(var f:File;const c : AnsiChar);[IOCheck];
  604. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  605. Begin
  606. Rename(f,AnsiString(c));
  607. End;
  608. {$else FPC_HAS_FEATURE_ANSISTRINGS}
  609. var
  610. p : array[0..1] Of AnsiChar;
  611. Begin
  612. p[0]:=c;
  613. p[1]:=#0;
  614. Rename(f,PAnsiChar(@p));
  615. End;
  616. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  617. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  618. Function GetFullName(var f:File) : UnicodeString;
  619. begin
  620. {$ifdef USE_FILEREC_FULLNAME}
  621. if Assigned(FileRec(f).FullName) then
  622. Result:=UnicodeString(FileRec(f).FullName)
  623. else
  624. {$endif USE_FILEREC_FULLNAME}
  625. Result:=PFileTextRecChar(@FileRec(f).Name);
  626. end;
  627. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}