sysutils.pp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  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) or fpS_ISDIR(info.st_mode) 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. {****************************************************************************
  847. Locale Functions
  848. ****************************************************************************}
  849. Function GetEpochTime: cint;
  850. {
  851. Get the number of seconds since 00:00, January 1 1970, GMT
  852. the time NOT corrected any way
  853. }
  854. begin
  855. GetEpochTime:=fptime;
  856. end;
  857. procedure GetTime(var hour,min,sec,msec,usec:word);
  858. {
  859. Gets the current time, adjusted to local time
  860. }
  861. var
  862. year,day,month:Word;
  863. tz:timeval;
  864. begin
  865. fpgettimeofday(@tz,nil);
  866. EpochToLocal(tz.tv_sec,year,month,day,hour,min,sec);
  867. msec:=tz.tv_usec div 1000;
  868. usec:=tz.tv_usec mod 1000;
  869. end;
  870. procedure GetTime(var hour,min,sec,sec100:word);
  871. {
  872. Gets the current time, adjusted to local time
  873. }
  874. var
  875. usec : word;
  876. begin
  877. gettime(hour,min,sec,sec100,usec);
  878. sec100:=sec100 div 10;
  879. end;
  880. Procedure GetTime(Var Hour,Min,Sec:Word);
  881. {
  882. Gets the current time, adjusted to local time
  883. }
  884. var
  885. msec,usec : Word;
  886. Begin
  887. gettime(hour,min,sec,msec,usec);
  888. End;
  889. Procedure GetDate(Var Year,Month,Day:Word);
  890. {
  891. Gets the current date, adjusted to local time
  892. }
  893. var
  894. hour,minute,second : word;
  895. Begin
  896. EpochToLocal(fptime,year,month,day,hour,minute,second);
  897. End;
  898. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  899. {
  900. Gets the current date, adjusted to local time
  901. }
  902. Begin
  903. EpochToLocal(fptime,year,month,day,hour,minute,second);
  904. End;
  905. {$ifndef FPUNONE}
  906. Procedure GetLocalTime(var SystemTime: TSystemTime);
  907. var
  908. usecs : Word;
  909. begin
  910. GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond, usecs);
  911. GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day);
  912. // SystemTime.MilliSecond := 0;
  913. end ;
  914. {$endif}
  915. Procedure InitAnsi;
  916. Var
  917. i : longint;
  918. begin
  919. { Fill table entries 0 to 127 }
  920. for i := 0 to 96 do
  921. UpperCaseTable[i] := chr(i);
  922. for i := 97 to 122 do
  923. UpperCaseTable[i] := chr(i - 32);
  924. for i := 123 to 191 do
  925. UpperCaseTable[i] := chr(i);
  926. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  927. for i := 0 to 64 do
  928. LowerCaseTable[i] := chr(i);
  929. for i := 65 to 90 do
  930. LowerCaseTable[i] := chr(i + 32);
  931. for i := 91 to 191 do
  932. LowerCaseTable[i] := chr(i);
  933. Move (CPISO88591LCT,LowerCaseTable[192],SizeOf(CPISO88591UCT));
  934. end;
  935. Procedure InitInternational;
  936. begin
  937. InitInternationalGeneric;
  938. InitAnsi;
  939. end;
  940. function SysErrorMessage(ErrorCode: Integer): String;
  941. begin
  942. Result:=StrError(ErrorCode);
  943. end;
  944. {****************************************************************************
  945. OS utility functions
  946. ****************************************************************************}
  947. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  948. begin
  949. Result:=StrPas(BaseUnix.FPGetenv(PChar(pointer(EnvVar))));
  950. end;
  951. Function GetEnvironmentVariableCount : Integer;
  952. begin
  953. Result:=FPCCountEnvVar(EnvP);
  954. end;
  955. Function GetEnvironmentString(Index : Integer) : String;
  956. begin
  957. Result:=FPCGetEnvStrFromP(Envp,Index);
  958. end;
  959. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
  960. var
  961. pid : longint;
  962. e : EOSError;
  963. CommandLine: AnsiString;
  964. cmdline2 : ppchar;
  965. Begin
  966. { always surround the name of the application by quotes
  967. so that long filenames will always be accepted. But don't
  968. do it if there are already double quotes!
  969. }
  970. // Only place we still parse
  971. cmdline2:=nil;
  972. if Comline<>'' Then
  973. begin
  974. CommandLine:=ComLine;
  975. { Make an unique copy because stringtoppchar modifies the
  976. string }
  977. UniqueString(CommandLine);
  978. cmdline2:=StringtoPPChar(CommandLine,1);
  979. cmdline2^:=pchar(pointer(Path));
  980. end
  981. else
  982. begin
  983. getmem(cmdline2,2*sizeof(pchar));
  984. cmdline2^:=pchar(Path);
  985. cmdline2[1]:=nil;
  986. end;
  987. {$ifdef USE_VFORK}
  988. pid:=fpvFork;
  989. {$else USE_VFORK}
  990. pid:=fpFork;
  991. {$endif USE_VFORK}
  992. if pid=0 then
  993. begin
  994. {The child does the actual exec, and then exits}
  995. fpexecv(pchar(pointer(Path)),Cmdline2);
  996. { If the execve fails, we return an exitvalue of 127, to let it be known}
  997. fpExit(127);
  998. end
  999. else
  1000. if pid=-1 then {Fork failed}
  1001. begin
  1002. e:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,-1]);
  1003. e.ErrorCode:=-1;
  1004. raise e;
  1005. end;
  1006. { We're in the parent, let's wait. }
  1007. result:=WaitProcess(pid); // WaitPid and result-convert
  1008. if Comline<>'' Then
  1009. freemem(cmdline2);
  1010. if (result<0) or (result=127) then
  1011. begin
  1012. E:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,result]);
  1013. E.ErrorCode:=result;
  1014. Raise E;
  1015. end;
  1016. End;
  1017. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString;Flags:TExecuteFlags=[]):integer;
  1018. var
  1019. pid : longint;
  1020. e : EOSError;
  1021. Begin
  1022. pid:=fpFork;
  1023. if pid=0 then
  1024. begin
  1025. {The child does the actual exec, and then exits}
  1026. fpexecl(Path,Comline);
  1027. { If the execve fails, we return an exitvalue of 127, to let it be known}
  1028. fpExit(127);
  1029. end
  1030. else
  1031. if pid=-1 then {Fork failed}
  1032. begin
  1033. e:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,-1]);
  1034. e.ErrorCode:=-1;
  1035. raise e;
  1036. end;
  1037. { We're in the parent, let's wait. }
  1038. result:=WaitProcess(pid); // WaitPid and result-convert
  1039. if (result<0) or (result=127) then
  1040. begin
  1041. E:=EOSError.CreateFmt(SExecuteProcessFailed,[Path,result]);
  1042. E.ErrorCode:=result;
  1043. raise E;
  1044. end;
  1045. End;
  1046. procedure Sleep(milliseconds: Cardinal);
  1047. Var
  1048. timeout,timeoutresult : TTimespec;
  1049. res: cint;
  1050. begin
  1051. timeout.tv_sec:=milliseconds div 1000;
  1052. timeout.tv_nsec:=1000*1000*(milliseconds mod 1000);
  1053. repeat
  1054. res:=fpnanosleep(@timeout,@timeoutresult);
  1055. timeout:=timeoutresult;
  1056. until (res<>-1) or (fpgeterrno<>ESysEINTR);
  1057. end;
  1058. Function GetLastOSError : Integer;
  1059. begin
  1060. Result:=fpgetErrNo;
  1061. end;
  1062. { ---------------------------------------------------------------------
  1063. Application config files
  1064. ---------------------------------------------------------------------}
  1065. Function GetHomeDir : String;
  1066. begin
  1067. Result:=GetEnvironmentVariable('HOME');
  1068. If (Result<>'') then
  1069. Result:=IncludeTrailingPathDelimiter(Result);
  1070. end;
  1071. { Follows base-dir spec,
  1072. see [http://freedesktop.org/Standards/basedir-spec].
  1073. Always ends with PathDelim. }
  1074. Function XdgConfigHome : String;
  1075. begin
  1076. Result:=GetEnvironmentVariable('XDG_CONFIG_HOME');
  1077. if (Result='') then
  1078. Result:=GetHomeDir + '.config/'
  1079. else
  1080. Result:=IncludeTrailingPathDelimiter(Result);
  1081. end;
  1082. Function GetAppConfigDir(Global : Boolean) : String;
  1083. begin
  1084. If Global then
  1085. Result:=IncludeTrailingPathDelimiter(SysConfigDir)
  1086. else
  1087. Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
  1088. if VendorName<>'' then
  1089. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  1090. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  1091. end;
  1092. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  1093. begin
  1094. If Global then
  1095. Result:=IncludeTrailingPathDelimiter(SysConfigDir)
  1096. else
  1097. Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
  1098. if SubDir then
  1099. begin
  1100. if VendorName<>'' then
  1101. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  1102. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  1103. end;
  1104. Result:=Result+ApplicationName+ConfigExtension;
  1105. end;
  1106. {****************************************************************************
  1107. GetTempDir
  1108. ****************************************************************************}
  1109. Function GetTempDir(Global : Boolean) : String;
  1110. begin
  1111. If Assigned(OnGetTempDir) then
  1112. Result:=OnGetTempDir(Global)
  1113. else
  1114. begin
  1115. Result:=GetEnvironmentVariable('TEMP');
  1116. If (Result='') Then
  1117. Result:=GetEnvironmentVariable('TMP');
  1118. if (Result='') then
  1119. Result:='/tmp/' // fallback.
  1120. end;
  1121. if (Result<>'') then
  1122. Result:=IncludeTrailingPathDelimiter(Result);
  1123. end;
  1124. {****************************************************************************
  1125. GetUserDir
  1126. ****************************************************************************}
  1127. Var
  1128. TheUserDir : String;
  1129. Function GetUserDir : String;
  1130. begin
  1131. If (TheUserDir='') then
  1132. begin
  1133. TheUserDir:=GetEnvironmentVariable('HOME');
  1134. if (TheUserDir<>'') then
  1135. TheUserDir:=IncludeTrailingPathDelimiter(TheUserDir)
  1136. else
  1137. TheUserDir:=GetTempDir(False);
  1138. end;
  1139. Result:=TheUserDir;
  1140. end;
  1141. Procedure SysBeep;
  1142. begin
  1143. Write(#7);
  1144. Flush(Output);
  1145. end;
  1146. {****************************************************************************
  1147. Initialization code
  1148. ****************************************************************************}
  1149. Initialization
  1150. InitExceptions; { Initialize exceptions. OS independent }
  1151. InitInternational; { Initialize internationalization settings }
  1152. SysConfigDir:='/etc'; { Initialize system config dir }
  1153. OnBeep:=@SysBeep;
  1154. Finalization
  1155. FreeDriveStr;
  1156. DoneExceptions;
  1157. end.