sysutils.pp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. Sysutils unit for linux
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit sysutils;
  13. interface
  14. {$MODE objfpc}
  15. {$MODESWITCH OUT}
  16. { force ansistrings }
  17. {$H+}
  18. {$if (defined(BSD) or defined(SUNOS)) and defined(FPC_USE_LIBC)}
  19. {$define USE_VFORK}
  20. {$endif}
  21. {$DEFINE OS_FILESETDATEBYNAME}
  22. {$DEFINE HAS_SLEEP}
  23. {$DEFINE HAS_OSERROR}
  24. {$DEFINE HAS_OSCONFIG}
  25. {$DEFINE HAS_TEMPDIR}
  26. {$DEFINE HASUNIX}
  27. {$DEFINE HASCREATEGUID}
  28. {$DEFINE HAS_OSUSERDIR}
  29. uses
  30. Unix,errors,sysconst,Unixtype;
  31. { Include platform independent interface part }
  32. {$i sysutilh.inc}
  33. Function AddDisk(const path:string) : Byte;
  34. { the following is Kylix compatibility stuff, it should be moved to a
  35. special compatibilty unit (FK) }
  36. const
  37. RTL_SIGINT = 0;
  38. RTL_SIGFPE = 1;
  39. RTL_SIGSEGV = 2;
  40. RTL_SIGILL = 3;
  41. RTL_SIGBUS = 4;
  42. RTL_SIGQUIT = 5;
  43. RTL_SIGLAST = RTL_SIGQUIT;
  44. RTL_SIGDEFAULT = -1;
  45. type
  46. TSignalState = (ssNotHooked, ssHooked, ssOverridden);
  47. function InquireSignal(RtlSigNum: Integer): TSignalState;
  48. procedure AbandonSignalHandler(RtlSigNum: Integer);
  49. procedure HookSignal(RtlSigNum: Integer);
  50. procedure UnhookSignal(RtlSigNum: Integer; OnlyIfHooked: Boolean = True);
  51. implementation
  52. Uses
  53. {$ifdef FPC_USE_LIBC}initc{$ELSE}Syscall{$ENDIF}, Baseunix, unixutil;
  54. type
  55. tsiginfo = record
  56. oldsiginfo: sigactionrec;
  57. hooked: boolean;
  58. end;
  59. const
  60. rtlsig2ossig: array[RTL_SIGINT..RTL_SIGLAST] of byte =
  61. (SIGINT,SIGFPE,SIGSEGV,SIGILL,SIGBUS,SIGQUIT);
  62. { to avoid linking in all this stuff in every program,
  63. as it's unlikely to be used by anything but libraries
  64. }
  65. signalinfoinited: boolean = false;
  66. var
  67. siginfo: array[RTL_SIGINT..RTL_SIGLAST] of tsiginfo;
  68. oldsigfpe: SigActionRec; external name '_FPC_OLDSIGFPE';
  69. oldsigsegv: SigActionRec; external name '_FPC_OLDSIGSEGV';
  70. oldsigbus: SigActionRec; external name '_FPC_OLDSIGBUS';
  71. oldsigill: SigActionRec; external name '_FPC_OLDSIGILL';
  72. procedure defaultsighandler; external name '_FPC_DEFAULTSIGHANDLER';
  73. procedure installdefaultsignalhandler(signum: Integer; out oldact: SigActionRec); external name '_FPC_INSTALLDEFAULTSIGHANDLER';
  74. function InternalInquireSignal(RtlSigNum: Integer; out act: SigActionRec; frominit: boolean): TSignalState;
  75. begin
  76. result:=ssNotHooked;
  77. if (RtlSigNum<>RTL_SIGDEFAULT) and
  78. (RtlSigNum<RTL_SIGLAST) then
  79. begin
  80. if (frominit or
  81. siginfo[RtlSigNum].hooked) and
  82. (fpsigaction(rtlsig2ossig[RtlSigNum],nil,@act)=0) then
  83. begin
  84. if not frominit then
  85. begin
  86. { check whether the installed signal handler is still ours }
  87. if (pointer(act.sa_handler)=pointer(@defaultsighandler)) then
  88. result:=ssHooked
  89. else
  90. result:=ssOverridden;
  91. end
  92. else if IsLibrary then
  93. begin
  94. { library -> signals have not been hooked by system init code }
  95. exit
  96. end
  97. else
  98. begin
  99. { program -> signals have been hooked by system init code }
  100. if (byte(RtlSigNum) in [RTL_SIGFPE,RTL_SIGSEGV,RTL_SIGILL,RTL_SIGBUS]) then
  101. begin
  102. if (pointer(act.sa_handler)=pointer(@defaultsighandler)) then
  103. result:=ssHooked
  104. else
  105. result:=ssOverridden;
  106. { return the original handlers as saved by the system unit
  107. (the current call to sigaction simply returned our
  108. system unit's installed handlers)
  109. }
  110. case RtlSigNum of
  111. RTL_SIGFPE:
  112. act:=oldsigfpe;
  113. RTL_SIGSEGV:
  114. act:=oldsigsegv;
  115. RTL_SIGILL:
  116. act:=oldsigill;
  117. RTL_SIGBUS:
  118. act:=oldsigbus;
  119. end;
  120. end
  121. else
  122. begin
  123. { these are not hooked in the startup code }
  124. result:=ssNotHooked;
  125. end
  126. end
  127. end
  128. end;
  129. end;
  130. procedure initsignalinfo;
  131. var
  132. i: Integer;
  133. begin
  134. for i:=RTL_SIGINT to RTL_SIGLAST do
  135. siginfo[i].hooked:=(InternalInquireSignal(i,siginfo[i].oldsiginfo,true)=ssHooked);
  136. signalinfoinited:=true;
  137. end;
  138. function InquireSignal(RtlSigNum: Integer): TSignalState;
  139. var
  140. act: SigActionRec;
  141. begin
  142. if not signalinfoinited then
  143. initsignalinfo;
  144. result:=InternalInquireSignal(RtlSigNum,act,false);
  145. end;
  146. procedure AbandonSignalHandler(RtlSigNum: Integer);
  147. begin
  148. if not signalinfoinited then
  149. initsignalinfo;
  150. if (RtlSigNum<>RTL_SIGDEFAULT) and
  151. (RtlSigNum<RTL_SIGLAST) then
  152. siginfo[RtlSigNum].hooked:=false;
  153. end;
  154. procedure HookSignal(RtlSigNum: Integer);
  155. var
  156. lowsig, highsig, i: Integer;
  157. begin
  158. if not signalinfoinited then
  159. initsignalinfo;
  160. if (RtlSigNum<>RTL_SIGDEFAULT) then
  161. begin
  162. lowsig:=RtlSigNum;
  163. highsig:=RtlSigNum;
  164. end
  165. else
  166. begin
  167. { we don't hook SIGINT and SIGQUIT by default }
  168. lowsig:=RTL_SIGFPE;
  169. highsig:=RTL_SIGBUS;
  170. end;
  171. { install the default rtl signal handler for the selected signal(s) }
  172. for i:=lowsig to highsig do
  173. begin
  174. installdefaultsignalhandler(rtlsig2ossig[i],siginfo[i].oldsiginfo);
  175. siginfo[i].hooked:=true;
  176. end;
  177. end;
  178. procedure UnhookSignal(RtlSigNum: Integer; OnlyIfHooked: Boolean = True);
  179. var
  180. act: SigActionRec;
  181. lowsig, highsig, i: Integer;
  182. state: TSignalState;
  183. begin
  184. if not signalinfoinited then
  185. initsignalinfo;
  186. if (RtlSigNum<>RTL_SIGDEFAULT) then
  187. begin
  188. lowsig:=RtlSigNum;
  189. highsig:=RtlSigNum;
  190. end
  191. else
  192. begin
  193. { we don't hook SIGINT and SIGQUIT by default }
  194. lowsig:=RTL_SIGFPE;
  195. highsig:=RTL_SIGBUS;
  196. end;
  197. for i:=lowsig to highsig do
  198. begin
  199. if not OnlyIfHooked or
  200. (InquireSignal(i)=ssHooked) then
  201. begin
  202. { restore the handler that was present when we hooked the signal,
  203. if we hooked it at one time or another. If the user doesn't
  204. want this, they have to call AbandonSignalHandler() first
  205. }
  206. if siginfo[i].hooked then
  207. act:=siginfo[i].oldsiginfo
  208. else
  209. begin
  210. fillchar(act,sizeof(act),0);
  211. pointer(act.sa_handler):=pointer(SIG_DFL);
  212. end;
  213. if (fpsigaction(rtlsig2ossig[RtlSigNum],@act,nil)=0) then
  214. siginfo[i].hooked:=false;
  215. end;
  216. end;
  217. end;
  218. {$Define OS_FILEISREADONLY} // Specific implementation for Unix.
  219. {$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
  220. {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
  221. { Include platform independent implementation part }
  222. {$i sysutils.inc}
  223. { Include SysCreateGUID function }
  224. {$i suuid.inc}
  225. Const
  226. {Date Translation}
  227. C1970=2440588;
  228. D0 = 1461;
  229. D1 = 146097;
  230. D2 =1721119;
  231. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  232. Var
  233. YYear,XYear,Temp,TempMonth : LongInt;
  234. Begin
  235. Temp:=((JulianDN-D2) shl 2)-1;
  236. JulianDN:=Temp Div D1;
  237. XYear:=(Temp Mod D1) or 3;
  238. YYear:=(XYear Div D0);
  239. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  240. Day:=((Temp Mod 153)+5) Div 5;
  241. TempMonth:=Temp Div 153;
  242. If TempMonth>=10 Then
  243. Begin
  244. inc(YYear);
  245. dec(TempMonth,12);
  246. End;
  247. inc(TempMonth,3);
  248. Month := TempMonth;
  249. Year:=YYear+(JulianDN*100);
  250. end;
  251. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  252. {
  253. Transforms Epoch time into local time (hour, minute,seconds)
  254. }
  255. Var
  256. DateNum: LongInt;
  257. Begin
  258. inc(Epoch,TZSeconds);
  259. Datenum:=(Epoch Div 86400) + c1970;
  260. JulianToGregorian(DateNum,Year,Month,day);
  261. Epoch:=Abs(Epoch Mod 86400);
  262. Hour:=Epoch Div 3600;
  263. Epoch:=Epoch Mod 3600;
  264. Minute:=Epoch Div 60;
  265. Second:=Epoch Mod 60;
  266. End;
  267. {****************************************************************************
  268. File Functions
  269. ****************************************************************************}
  270. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  271. Var
  272. DotPos,SlashPos,i : longint;
  273. Begin
  274. SlashPos:=0;
  275. DotPos:=256;
  276. i:=Length(Path);
  277. While (i>0) and (SlashPos=0) Do
  278. Begin
  279. If (DotPos=256) and (Path[i]='.') Then
  280. begin
  281. DotPos:=i;
  282. end;
  283. If (Path[i]='/') Then
  284. SlashPos:=i;
  285. Dec(i);
  286. End;
  287. Ext:=Copy(Path,DotPos,255);
  288. Dir:=Copy(Path,1,SlashPos);
  289. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  290. End;
  291. Function DoFileLocking(Handle: Longint; Mode: Integer) : Longint;
  292. var
  293. lockop: cint;
  294. lockres: cint;
  295. closeres: cint;
  296. lockerr: cint;
  297. begin
  298. DoFileLocking:=Handle;
  299. {$ifdef beos}
  300. {$else}
  301. if (Handle>=0) then
  302. begin
  303. {$ifdef solaris}
  304. { Solaris' flock is based on top of fcntl, which does not allow
  305. exclusive locks for files only opened for reading nor shared
  306. locks for files opened only for writing.
  307. If no locking is specified, we normally need an exclusive lock.
  308. So create an exclusive lock for fmOpenWrite and fmOpenReadWrite,
  309. but only a shared lock for fmOpenRead (since an exclusive lock
  310. is not possible in that case)
  311. }
  312. if ((mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead or fmShareDenyNone)) = 0) then
  313. begin
  314. if ((mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) = fmOpenRead) then
  315. mode := mode or fmShareDenyWrite
  316. else
  317. mode := mode or fmShareExclusive;
  318. end;
  319. {$endif solaris}
  320. case (mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead or fmShareDenyNone)) of
  321. fmShareCompat,
  322. fmShareExclusive:
  323. lockop:=LOCK_EX or LOCK_NB;
  324. fmShareDenyWrite:
  325. lockop:=LOCK_SH or LOCK_NB;
  326. fmShareDenyNone:
  327. exit;
  328. else
  329. begin
  330. { fmShareDenyRead does not exit under *nix, only shared access
  331. (similar to fmShareDenyWrite) and exclusive access (same as
  332. fmShareExclusive)
  333. }
  334. repeat
  335. closeres:=FpClose(Handle);
  336. until (closeres<>-1) or (fpgeterrno<>ESysEINTR);
  337. DoFileLocking:=-1;
  338. exit;
  339. end;
  340. end;
  341. repeat
  342. lockres:=fpflock(Handle,lockop);
  343. until (lockres=0) or
  344. (fpgeterrno<>ESysEIntr);
  345. lockerr:=fpgeterrno;
  346. { Only return an error if locks are working and the file was already
  347. locked. Not if locks are simply unsupported (e.g., on Angstrom Linux
  348. you always get ESysNOLCK in the default configuration) }
  349. if (lockres<>0) and
  350. ((lockerr=ESysEAGAIN) or
  351. (lockerr=EsysEDEADLK)) then
  352. begin
  353. repeat
  354. closeres:=FpClose(Handle);
  355. until (closeres<>-1) or (fpgeterrno<>ESysEINTR);
  356. DoFileLocking:=-1;
  357. exit;
  358. end;
  359. end;
  360. {$endif not beos}
  361. end;
  362. Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
  363. Var
  364. LinuxFlags : longint;
  365. begin
  366. LinuxFlags:=0;
  367. case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
  368. fmOpenRead : LinuxFlags:=LinuxFlags or O_RdOnly;
  369. fmOpenWrite : LinuxFlags:=LinuxFlags or O_WrOnly;
  370. fmOpenReadWrite : LinuxFlags:=LinuxFlags or O_RdWr;
  371. end;
  372. repeat
  373. FileOpen:=fpOpen (pointer(FileName),LinuxFlags);
  374. until (FileOpen<>-1) or (fpgeterrno<>ESysEINTR);
  375. FileOpen:=DoFileLocking(FileOpen, Mode);
  376. end;
  377. Function FileCreate (Const FileName : String) : Longint;
  378. begin
  379. repeat
  380. FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc);
  381. until (FileCreate<>-1) or (fpgeterrno<>ESysEINTR);
  382. end;
  383. Function FileCreate (Const FileName : String;Mode : Longint) : Longint;
  384. begin
  385. repeat
  386. FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Mode);
  387. until (FileCreate<>-1) or (fpgeterrno<>ESysEINTR);
  388. end;
  389. Function FileRead (Handle : Longint; out Buffer; Count : longint) : Longint;
  390. begin
  391. repeat
  392. FileRead:=fpRead (Handle,Buffer,Count);
  393. until (FileRead<>-1) or (fpgeterrno<>ESysEINTR);
  394. end;
  395. Function FileWrite (Handle : Longint; const Buffer; Count : Longint) : Longint;
  396. begin
  397. repeat
  398. FileWrite:=fpWrite (Handle,Buffer,Count);
  399. until (FileWrite<>-1) or (fpgeterrno<>ESysEINTR);
  400. end;
  401. Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;
  402. begin
  403. result:=longint(FileSeek(Handle,int64(FOffset),Origin));
  404. end;
  405. Function FileSeek (Handle : Longint; FOffset : Int64; Origin : Longint) : Int64;
  406. begin
  407. FileSeek:=fplSeek (Handle,FOffset,Origin);
  408. end;
  409. Procedure FileClose (Handle : Longint);
  410. var
  411. res: cint;
  412. begin
  413. repeat
  414. res:=fpclose(Handle);
  415. until (res<>-1) or (fpgeterrno<>ESysEINTR);
  416. end;
  417. Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
  418. var
  419. res: cint;
  420. begin
  421. if (SizeOf (TOff) < 8) (* fpFTruncate only supporting signed 32-bit size *)
  422. and (Size > high (longint)) then
  423. FileTruncate := false
  424. else
  425. begin
  426. repeat
  427. res:=fpftruncate(Handle,Size);
  428. until (res<>-1) or (fpgeterrno<>ESysEINTR);
  429. FileTruncate:=res>=0;
  430. end;
  431. end;
  432. {$ifndef FPUNONE}
  433. Function UnixToWinAge(UnixAge : time_t): Longint;
  434. Var
  435. Y,M,D,hh,mm,ss : word;
  436. begin
  437. EpochToLocal(UnixAge,y,m,d,hh,mm,ss);
  438. Result:=DateTimeToFileDate(EncodeDate(y,m,d)+EncodeTime(hh,mm,ss,0));
  439. end;
  440. Function FileAge (Const FileName : String): Longint;
  441. Var Info : Stat;
  442. begin
  443. If fpstat (pointer(FileName),Info)<0 then
  444. exit(-1)
  445. else
  446. Result:=UnixToWinAge(info.st_mtime);
  447. end;
  448. {$endif}
  449. Function FileExists (Const FileName : String) : Boolean;
  450. begin
  451. // Don't use stat. It fails on files >2 GB.
  452. // Access obeys the same access rules, so the result should be the same.
  453. FileExists:=fpAccess(pointer(filename),F_OK)=0;
  454. end;
  455. Function DirectoryExists (Const Directory : String) : Boolean;
  456. Var Info : Stat;
  457. begin
  458. DirectoryExists:=(fpstat(pointer(Directory),Info)>=0) and fpS_ISDIR(Info.st_mode);
  459. end;
  460. Function LinuxToWinAttr (const FN : Ansistring; Const Info : Stat) : Longint;
  461. Var
  462. LinkInfo : Stat;
  463. begin
  464. Result:=faArchive;
  465. If fpS_ISDIR(Info.st_mode) then
  466. Result:=Result or faDirectory;
  467. If (Length(FN)>=2) and
  468. (FN[1]='.') and
  469. (FN[2]<>'.') then
  470. Result:=Result or faHidden;
  471. If (Info.st_Mode and S_IWUSR)=0 Then
  472. Result:=Result or faReadOnly;
  473. If fpS_ISSOCK(Info.st_mode) or fpS_ISBLK(Info.st_mode) or fpS_ISCHR(Info.st_mode) or fpS_ISFIFO(Info.st_mode) Then
  474. Result:=Result or faSysFile;
  475. If fpS_ISLNK(Info.st_mode) Then
  476. begin
  477. Result:=Result or faSymLink;
  478. // Windows reports if the link points to a directory.
  479. if (fpstat(FN,LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
  480. Result := Result or faDirectory;
  481. end;
  482. end;
  483. Function FNMatch(const Pattern,Name:string):Boolean;
  484. Var
  485. LenPat,LenName : longint;
  486. Function DoFNMatch(i,j:longint):Boolean;
  487. Var
  488. Found : boolean;
  489. Begin
  490. Found:=true;
  491. While Found and (i<=LenPat) Do
  492. Begin
  493. Case Pattern[i] of
  494. '?' : Found:=(j<=LenName);
  495. '*' : Begin
  496. {find the next character in pattern, different of ? and *}
  497. while Found do
  498. begin
  499. inc(i);
  500. if i>LenPat then Break;
  501. case Pattern[i] of
  502. '*' : ;
  503. '?' : begin
  504. if j>LenName then begin DoFNMatch:=false; Exit; end;
  505. inc(j);
  506. end;
  507. else
  508. Found:=false;
  509. end;
  510. end;
  511. Assert((i>LenPat) or ( (Pattern[i]<>'*') and (Pattern[i]<>'?') ));
  512. {Now, find in name the character which i points to, if the * or ?
  513. wasn't the last character in the pattern, else, use up all the
  514. chars in name}
  515. Found:=false;
  516. if (i<=LenPat) then
  517. begin
  518. repeat
  519. {find a letter (not only first !) which maches pattern[i]}
  520. while (j<=LenName) and (name[j]<>pattern[i]) do
  521. inc (j);
  522. if (j<LenName) then
  523. begin
  524. if DoFnMatch(i+1,j+1) then
  525. begin
  526. i:=LenPat;
  527. j:=LenName;{we can stop}
  528. Found:=true;
  529. Break;
  530. end else
  531. inc(j);{We didn't find one, need to look further}
  532. end else
  533. if j=LenName then
  534. begin
  535. Found:=true;
  536. Break;
  537. end;
  538. { This 'until' condition must be j>LenName, not j>=LenName.
  539. That's because when we 'need to look further' and
  540. j = LenName then loop must not terminate. }
  541. until (j>LenName);
  542. end else
  543. begin
  544. j:=LenName;{we can stop}
  545. Found:=true;
  546. end;
  547. end;
  548. else {not a wildcard character in pattern}
  549. Found:=(j<=LenName) and (pattern[i]=name[j]);
  550. end;
  551. inc(i);
  552. inc(j);
  553. end;
  554. DoFnMatch:=Found and (j>LenName);
  555. end;
  556. Begin {start FNMatch}
  557. LenPat:=Length(Pattern);
  558. LenName:=Length(Name);
  559. FNMatch:=DoFNMatch(1,1);
  560. End;
  561. Type
  562. TUnixFindData = Record
  563. NamePos : LongInt; {to track which search this is}
  564. DirPtr : Pointer; {directory pointer for reading directory}
  565. SearchSpec : String;
  566. SearchType : Byte; {0=normal, 1=open will close, 2=only 1 file}
  567. SearchAttr : Byte; {attribute we are searching for}
  568. End;
  569. PUnixFindData = ^TUnixFindData;
  570. Procedure FindClose(Var f: TSearchRec);
  571. var
  572. UnixFindData : PUnixFindData;
  573. Begin
  574. UnixFindData:=PUnixFindData(f.FindHandle);
  575. If (UnixFindData=Nil) then
  576. Exit;
  577. if UnixFindData^.SearchType=0 then
  578. begin
  579. if UnixFindData^.dirptr<>nil then
  580. fpclosedir(pdir(UnixFindData^.dirptr)^);
  581. end;
  582. Dispose(UnixFindData);
  583. f.FindHandle:=nil;
  584. End;
  585. Function FindGetFileInfo(const s:string;var f:TSearchRec):boolean;
  586. var
  587. st : baseunix.stat;
  588. WinAttr : longint;
  589. begin
  590. FindGetFileInfo:=false;
  591. If Assigned(F.FindHandle) and ((((PUnixFindData(f.FindHandle)^.searchattr)) and faSymlink) > 0) then
  592. FindGetFileInfo:=(fplstat(pointer(s),st)=0)
  593. else
  594. FindGetFileInfo:=(fpstat(pointer(s),st)=0);
  595. If not FindGetFileInfo then
  596. exit;
  597. WinAttr:=LinuxToWinAttr(ExtractFileName(s),st);
  598. If ((WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0) Then
  599. Begin
  600. f.Name:=ExtractFileName(s);
  601. f.Attr:=WinAttr;
  602. f.Size:=st.st_Size;
  603. f.Mode:=st.st_mode;
  604. {$ifndef FPUNONE}
  605. f.Time:=UnixToWinAge(st.st_mtime);
  606. {$endif}
  607. FindGetFileInfo:=true;
  608. End
  609. else
  610. FindGetFileInfo:=false;
  611. end;
  612. Function FindNext (Var Rslt : TSearchRec) : Longint;
  613. {
  614. re-opens dir if not already in array and calls FindGetFileInfo
  615. }
  616. Var
  617. DirName : String;
  618. FName,
  619. SName : string;
  620. Found,
  621. Finished : boolean;
  622. p : pdirent;
  623. UnixFindData : PUnixFindData;
  624. Begin
  625. Result:=-1;
  626. UnixFindData:=PUnixFindData(Rslt.FindHandle);
  627. { SearchSpec='' means that there were no wild cards, so only one file to
  628. find.
  629. }
  630. If (UnixFindData=Nil) then
  631. exit;
  632. if UnixFindData^.SearchSpec='' then
  633. exit;
  634. if (UnixFindData^.SearchType=0) and
  635. (UnixFindData^.Dirptr=nil) then
  636. begin
  637. If UnixFindData^.NamePos = 0 Then
  638. DirName:='./'
  639. Else
  640. DirName:=Copy(UnixFindData^.SearchSpec,1,UnixFindData^.NamePos);
  641. UnixFindData^.DirPtr := fpopendir(Pchar(pointer(DirName)));
  642. end;
  643. SName:=Copy(UnixFindData^.SearchSpec,UnixFindData^.NamePos+1,Length(UnixFindData^.SearchSpec));
  644. Found:=False;
  645. Finished:=(UnixFindData^.dirptr=nil);
  646. While Not Finished Do
  647. Begin
  648. p:=fpreaddir(pdir(UnixFindData^.dirptr)^);
  649. if p=nil then
  650. FName:=''
  651. else
  652. FName:=p^.d_name;
  653. If FName='' Then
  654. Finished:=True
  655. Else
  656. Begin
  657. If FNMatch(SName,FName) Then
  658. Begin
  659. Found:=FindGetFileInfo(Copy(UnixFindData^.SearchSpec,1,UnixFindData^.NamePos)+FName,Rslt);
  660. if Found then
  661. begin
  662. Result:=0;
  663. exit;
  664. end;
  665. End;
  666. End;
  667. End;
  668. End;
  669. Function FindFirst (Const Path : String; Attr : Longint; out Rslt : TSearchRec) : Longint;
  670. {
  671. opens dir and calls FindNext if needed.
  672. }
  673. var
  674. UnixFindData : PUnixFindData;
  675. Begin
  676. Result:=-1;
  677. fillchar(Rslt,sizeof(Rslt),0);
  678. if Path='' then
  679. exit;
  680. { Allocate UnixFindData (we always need it, for the search attributes) }
  681. New(UnixFindData);
  682. FillChar(UnixFindData^,sizeof(UnixFindData^),0);
  683. Rslt.FindHandle:=UnixFindData;
  684. {We always also search for readonly and archive, regardless of Attr:}
  685. UnixFindData^.SearchAttr := Attr or faarchive or fareadonly;
  686. {Wildcards?}
  687. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  688. begin
  689. if FindGetFileInfo(Path,Rslt) then
  690. Result:=0;
  691. end
  692. else
  693. begin
  694. {Create Info}
  695. UnixFindData^.SearchSpec := Path;
  696. UnixFindData^.NamePos := Length(UnixFindData^.SearchSpec);
  697. while (UnixFindData^.NamePos>0) and (UnixFindData^.SearchSpec[UnixFindData^.NamePos]<>'/') do
  698. dec(UnixFindData^.NamePos);
  699. Result:=FindNext(Rslt);
  700. end;
  701. If (Result<>0) then
  702. FindClose(Rslt);
  703. End;
  704. Function FileGetDate (Handle : Longint) : Longint;
  705. Var Info : Stat;
  706. begin
  707. If (fpFStat(Handle,Info))<0 then
  708. Result:=-1
  709. else
  710. Result:=Info.st_Mtime;
  711. end;
  712. Function FileSetDate (Handle,Age : Longint) : Longint;
  713. begin
  714. // Impossible under Linux from FileHandle !!
  715. FileSetDate:=-1;
  716. end;
  717. Function FileGetAttr (Const FileName : String) : Longint;
  718. Var Info : Stat;
  719. begin
  720. If FpStat (pointer(FileName),Info)<0 then
  721. Result:=-1
  722. Else
  723. Result:=LinuxToWinAttr(Pchar(ExtractFileName(FileName)),Info);
  724. end;
  725. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  726. begin
  727. Result:=-1;
  728. end;
  729. Function DeleteFile (Const FileName : String) : Boolean;
  730. begin
  731. Result:=fpUnLink (pointer(FileName))>=0;
  732. end;
  733. Function RenameFile (Const OldName, NewName : String) : Boolean;
  734. begin
  735. RenameFile:=BaseUnix.FpRename(pointer(OldNAme),pointer(NewName))>=0;
  736. end;
  737. Function FileIsReadOnly(const FileName: String): Boolean;
  738. begin
  739. Result := fpAccess(PChar(pointer(FileName)),W_OK)<>0;
  740. end;
  741. Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
  742. var
  743. t: TUTimBuf;
  744. begin
  745. Result := 0;
  746. t.actime := Age;
  747. t.modtime := Age;
  748. if fputime(PChar(pointer(FileName)), @t) = -1 then
  749. Result := fpgeterrno;
  750. end;
  751. {****************************************************************************
  752. Disk Functions
  753. ****************************************************************************}
  754. {
  755. The Diskfree and Disksize functions need a file on the specified drive, since this
  756. is required for the statfs system call.
  757. These filenames are set in drivestr[0..26], and have been preset to :
  758. 0 - '.' (default drive - hence current dir is ok.)
  759. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  760. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  761. 3 - '/' (C: equivalent of dos is the root partition)
  762. 4..26 (can be set by you're own applications)
  763. ! Use AddDisk() to Add new drives !
  764. They both return -1 when a failure occurs.
  765. }
  766. Const
  767. FixDriveStr : array[0..3] of pchar=(
  768. '.',
  769. '/fd0/.',
  770. '/fd1/.',
  771. '/.'
  772. );
  773. var
  774. Drives : byte = 4;
  775. DriveStr : array[4..26] of pchar;
  776. Function AddDisk(const path:string) : Byte;
  777. begin
  778. if not (DriveStr[Drives]=nil) then
  779. FreeMem(DriveStr[Drives]);
  780. GetMem(DriveStr[Drives],length(Path)+1);
  781. StrPCopy(DriveStr[Drives],path);
  782. Result:=Drives;
  783. inc(Drives);
  784. if Drives>26 then
  785. Drives:=4;
  786. end;
  787. Function DiskFree(Drive: Byte): int64;
  788. var
  789. fs : tstatfs;
  790. Begin
  791. if ((Drive in [Low(FixDriveStr)..High(FixDriveStr)]) and (not (fixdrivestr[Drive]=nil)) and (statfs(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  792. ((Drive <= High(drivestr)) and (not (drivestr[Drive]=nil)) and (statfs(StrPas(drivestr[drive]),fs)<>-1)) then
  793. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  794. else
  795. Diskfree:=-1;
  796. End;
  797. Function DiskSize(Drive: Byte): int64;
  798. var
  799. fs : tstatfs;
  800. Begin
  801. if ((Drive in [Low(FixDriveStr)..High(FixDriveStr)]) and (not (fixdrivestr[Drive]=nil)) and (statfs(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  802. ((drive <= High(drivestr)) and (not (drivestr[Drive]=nil)) and (statfs(StrPas(drivestr[drive]),fs)<>-1)) then
  803. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  804. else
  805. DiskSize:=-1;
  806. End;
  807. Procedure FreeDriveStr;
  808. var
  809. i: longint;
  810. begin
  811. for i:=low(drivestr) to high(drivestr) do
  812. if assigned(drivestr[i]) then
  813. begin
  814. freemem(drivestr[i]);
  815. drivestr[i]:=nil;
  816. end;
  817. end;
  818. Function GetCurrentDir : String;
  819. begin
  820. GetDir (0,Result);
  821. end;
  822. Function SetCurrentDir (Const NewDir : String) : Boolean;
  823. begin
  824. {$I-}
  825. ChDir(NewDir);
  826. {$I+}
  827. result := (IOResult = 0);
  828. end;
  829. Function CreateDir (Const NewDir : String) : Boolean;
  830. begin
  831. {$I-}
  832. MkDir(NewDir);
  833. {$I+}
  834. result := (IOResult = 0);
  835. end;
  836. Function RemoveDir (Const Dir : String) : Boolean;
  837. begin
  838. {$I-}
  839. RmDir(Dir);
  840. {$I+}
  841. result := (IOResult = 0);
  842. end;
  843. {****************************************************************************
  844. Misc Functions
  845. ****************************************************************************}
  846. procedure Beep;
  847. begin
  848. end;
  849. {****************************************************************************
  850. Locale Functions
  851. ****************************************************************************}
  852. Function GetEpochTime: cint;
  853. {
  854. Get the number of seconds since 00:00, January 1 1970, GMT
  855. the time NOT corrected any way
  856. }
  857. begin
  858. GetEpochTime:=fptime;
  859. end;
  860. procedure GetTime(var hour,min,sec,msec,usec:word);
  861. {
  862. Gets the current time, adjusted to local time
  863. }
  864. var
  865. year,day,month:Word;
  866. tz:timeval;
  867. begin
  868. fpgettimeofday(@tz,nil);
  869. EpochToLocal(tz.tv_sec,year,month,day,hour,min,sec);
  870. msec:=tz.tv_usec div 1000;
  871. usec:=tz.tv_usec mod 1000;
  872. end;
  873. procedure GetTime(var hour,min,sec,sec100:word);
  874. {
  875. Gets the current time, adjusted to local time
  876. }
  877. var
  878. usec : word;
  879. begin
  880. gettime(hour,min,sec,sec100,usec);
  881. sec100:=sec100 div 10;
  882. end;
  883. Procedure GetTime(Var Hour,Min,Sec:Word);
  884. {
  885. Gets the current time, adjusted to local time
  886. }
  887. var
  888. msec,usec : Word;
  889. Begin
  890. gettime(hour,min,sec,msec,usec);
  891. End;
  892. Procedure GetDate(Var Year,Month,Day:Word);
  893. {
  894. Gets the current date, adjusted to local time
  895. }
  896. var
  897. hour,minute,second : word;
  898. Begin
  899. EpochToLocal(fptime,year,month,day,hour,minute,second);
  900. End;
  901. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  902. {
  903. Gets the current date, adjusted to local time
  904. }
  905. Begin
  906. EpochToLocal(fptime,year,month,day,hour,minute,second);
  907. End;
  908. {$ifndef FPUNONE}
  909. Procedure GetLocalTime(var SystemTime: TSystemTime);
  910. var
  911. usecs : Word;
  912. begin
  913. GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond, usecs);
  914. GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day);
  915. // SystemTime.MilliSecond := 0;
  916. end ;
  917. {$endif}
  918. Procedure InitAnsi;
  919. Var
  920. i : longint;
  921. begin
  922. { Fill table entries 0 to 127 }
  923. for i := 0 to 96 do
  924. UpperCaseTable[i] := chr(i);
  925. for i := 97 to 122 do
  926. UpperCaseTable[i] := chr(i - 32);
  927. for i := 123 to 191 do
  928. UpperCaseTable[i] := chr(i);
  929. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  930. for i := 0 to 64 do
  931. LowerCaseTable[i] := chr(i);
  932. for i := 65 to 90 do
  933. LowerCaseTable[i] := chr(i + 32);
  934. for i := 91 to 191 do
  935. LowerCaseTable[i] := chr(i);
  936. Move (CPISO88591LCT,LowerCaseTable[192],SizeOf(CPISO88591UCT));
  937. end;
  938. Procedure InitInternational;
  939. begin
  940. InitInternationalGeneric;
  941. InitAnsi;
  942. end;
  943. function SysErrorMessage(ErrorCode: Integer): String;
  944. begin
  945. Result:=StrError(ErrorCode);
  946. end;
  947. {****************************************************************************
  948. OS utility functions
  949. ****************************************************************************}
  950. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  951. begin
  952. Result:=StrPas(BaseUnix.FPGetenv(PChar(pointer(EnvVar))));
  953. end;
  954. Function GetEnvironmentVariableCount : Integer;
  955. begin
  956. Result:=FPCCountEnvVar(EnvP);
  957. end;
  958. Function GetEnvironmentString(Index : Integer) : String;
  959. begin
  960. Result:=FPCGetEnvStrFromP(Envp,Index);
  961. end;
  962. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
  963. var
  964. pid : longint;
  965. e : EOSError;
  966. CommandLine: AnsiString;
  967. cmdline2 : ppchar;
  968. Begin
  969. { always surround the name of the application by quotes
  970. so that long filenames will always be accepted. But don't
  971. do it if there are already double quotes!
  972. }
  973. // Only place we still parse
  974. cmdline2:=nil;
  975. if Comline<>'' Then
  976. begin
  977. CommandLine:=ComLine;
  978. { Make an unique copy because stringtoppchar modifies the
  979. string }
  980. UniqueString(CommandLine);
  981. cmdline2:=StringtoPPChar(CommandLine,1);
  982. cmdline2^:=pchar(pointer(Path));
  983. end
  984. else
  985. begin
  986. getmem(cmdline2,2*sizeof(pchar));
  987. cmdline2^:=pchar(Path);
  988. cmdline2[1]:=nil;
  989. end;
  990. {$ifdef USE_VFORK}
  991. pid:=fpvFork;
  992. {$else USE_VFORK}
  993. pid:=fpFork;
  994. {$endif USE_VFORK}
  995. if pid=0 then
  996. begin
  997. {The child does the actual exec, and then exits}
  998. fpexecv(pchar(pointer(Path)),Cmdline2);
  999. { If the execve fails, we return an exitvalue of 127, to let it be known}
  1000. fpExit(127);
  1001. end
  1002. else
  1003. if pid=-1 then {Fork failed}
  1004. begin
  1005. e:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,-1]);
  1006. e.ErrorCode:=-1;
  1007. raise e;
  1008. end;
  1009. { We're in the parent, let's wait. }
  1010. result:=WaitProcess(pid); // WaitPid and result-convert
  1011. if Comline<>'' Then
  1012. freemem(cmdline2);
  1013. if (result<0) or (result=127) then
  1014. begin
  1015. E:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,result]);
  1016. E.ErrorCode:=result;
  1017. Raise E;
  1018. end;
  1019. End;
  1020. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString;Flags:TExecuteFlags=[]):integer;
  1021. var
  1022. pid : longint;
  1023. e : EOSError;
  1024. Begin
  1025. pid:=fpFork;
  1026. if pid=0 then
  1027. begin
  1028. {The child does the actual exec, and then exits}
  1029. fpexecl(Path,Comline);
  1030. { If the execve fails, we return an exitvalue of 127, to let it be known}
  1031. fpExit(127);
  1032. end
  1033. else
  1034. if pid=-1 then {Fork failed}
  1035. begin
  1036. e:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,-1]);
  1037. e.ErrorCode:=-1;
  1038. raise e;
  1039. end;
  1040. { We're in the parent, let's wait. }
  1041. result:=WaitProcess(pid); // WaitPid and result-convert
  1042. if (result<0) or (result=127) then
  1043. begin
  1044. E:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,result]);
  1045. E.ErrorCode:=result;
  1046. raise E;
  1047. end;
  1048. End;
  1049. procedure Sleep(milliseconds: Cardinal);
  1050. Var
  1051. timeout,timeoutresult : TTimespec;
  1052. res: cint;
  1053. begin
  1054. timeout.tv_sec:=milliseconds div 1000;
  1055. timeout.tv_nsec:=1000*1000*(milliseconds mod 1000);
  1056. repeat
  1057. res:=fpnanosleep(@timeout,@timeoutresult);
  1058. timeout:=timeoutresult;
  1059. until (res<>-1) or (fpgeterrno<>ESysEINTR);
  1060. end;
  1061. Function GetLastOSError : Integer;
  1062. begin
  1063. Result:=fpgetErrNo;
  1064. end;
  1065. { ---------------------------------------------------------------------
  1066. Application config files
  1067. ---------------------------------------------------------------------}
  1068. Function GetHomeDir : String;
  1069. begin
  1070. Result:=GetEnvironmentVariable('HOME');
  1071. If (Result<>'') then
  1072. Result:=IncludeTrailingPathDelimiter(Result);
  1073. end;
  1074. { Follows base-dir spec,
  1075. see [http://freedesktop.org/Standards/basedir-spec].
  1076. Always ends with PathDelim. }
  1077. Function XdgConfigHome : String;
  1078. begin
  1079. Result:=GetEnvironmentVariable('XDG_CONFIG_HOME');
  1080. if (Result='') then
  1081. Result:=GetHomeDir + '.config/'
  1082. else
  1083. Result:=IncludeTrailingPathDelimiter(Result);
  1084. end;
  1085. Function GetAppConfigDir(Global : Boolean) : String;
  1086. begin
  1087. If Global then
  1088. Result:=IncludeTrailingPathDelimiter(SysConfigDir)
  1089. else
  1090. Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
  1091. if VendorName<>'' then
  1092. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  1093. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  1094. end;
  1095. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  1096. begin
  1097. If Global then
  1098. Result:=IncludeTrailingPathDelimiter(SysConfigDir)
  1099. else
  1100. Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
  1101. if SubDir then
  1102. begin
  1103. if VendorName<>'' then
  1104. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  1105. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  1106. end;
  1107. Result:=Result+ApplicationName+ConfigExtension;
  1108. end;
  1109. {****************************************************************************
  1110. GetTempDir
  1111. ****************************************************************************}
  1112. Function GetTempDir(Global : Boolean) : String;
  1113. begin
  1114. If Assigned(OnGetTempDir) then
  1115. Result:=OnGetTempDir(Global)
  1116. else
  1117. begin
  1118. Result:=GetEnvironmentVariable('TEMP');
  1119. If (Result='') Then
  1120. Result:=GetEnvironmentVariable('TMP');
  1121. if (Result='') then
  1122. Result:='/tmp/' // fallback.
  1123. end;
  1124. if (Result<>'') then
  1125. Result:=IncludeTrailingPathDelimiter(Result);
  1126. end;
  1127. {****************************************************************************
  1128. GetUserDir
  1129. ****************************************************************************}
  1130. Var
  1131. TheUserDir : String;
  1132. Function GetUserDir : String;
  1133. begin
  1134. If (TheUserDir='') then
  1135. begin
  1136. TheUserDir:=GetEnvironmentVariable('HOME');
  1137. if (TheUserDir<>'') then
  1138. TheUserDir:=IncludeTrailingPathDelimiter(TheUserDir)
  1139. else
  1140. TheUserDir:=GetTempDir(False);
  1141. end;
  1142. Result:=TheUserDir;
  1143. end;
  1144. {****************************************************************************
  1145. Initialization code
  1146. ****************************************************************************}
  1147. Initialization
  1148. InitExceptions; { Initialize exceptions. OS independent }
  1149. InitInternational; { Initialize internationalization settings }
  1150. SysConfigDir:='/etc'; { Initialize system config dir }
  1151. Finalization
  1152. FreeDriveStr;
  1153. DoneExceptions;
  1154. end.