sysutils.pp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Sysutils unit for OS/2
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit sysutils;
  14. interface
  15. {$MODE objfpc}
  16. { force ansistrings }
  17. {$H+}
  18. uses
  19. Dos;
  20. { Include platform independent interface part }
  21. {$i sysutilh.inc}
  22. implementation
  23. { Include platform independent implementation part }
  24. {$i sysutils.inc}
  25. {****************************************************************************
  26. System (imported) calls
  27. ****************************************************************************}
  28. (* "uses DosCalls" could not be used here due to type *)
  29. (* conflicts, so needed parts had to be redefined here). *)
  30. type
  31. TFileStatus = object
  32. end;
  33. PFileStatus = ^TFileStatus;
  34. TFileStatus0 = object (TFileStatus)
  35. DateCreation, {Date of file creation.}
  36. TimeCreation, {Time of file creation.}
  37. DateLastAccess, {Date of last access to file.}
  38. TimeLastAccess, {Time of last access to file.}
  39. DateLastWrite, {Date of last modification of file.}
  40. TimeLastWrite: word; {Time of last modification of file.}
  41. FileSize, {Size of file.}
  42. FileAlloc: longint; {Amount of space the file really
  43. occupies on disk.}
  44. end;
  45. PFileStatus0 = ^TFileStatus0;
  46. TFileStatus3 = object (TFileStatus)
  47. NextEntryOffset: longint; {Offset of next entry}
  48. DateCreation, {Date of file creation.}
  49. TimeCreation, {Time of file creation.}
  50. DateLastAccess, {Date of last access to file.}
  51. TimeLastAccess, {Time of last access to file.}
  52. DateLastWrite, {Date of last modification of file.}
  53. TimeLastWrite: word; {Time of last modification of file.}
  54. FileSize, {Size of file.}
  55. FileAlloc: longint; {Amount of space the file really
  56. occupies on disk.}
  57. AttrFile: longint; {Attributes of file.}
  58. end;
  59. PFileStatus3 = ^TFileStatus3;
  60. TFileFindBuf3 = object (TFileStatus3)
  61. Name: ShortString; {Also possible to use as ASCIIZ.
  62. The byte following the last string
  63. character is always zero.}
  64. end;
  65. PFileFindBuf3 = ^TFileFindBuf3;
  66. TFSInfo = record
  67. case word of
  68. 1:
  69. (File_Sys_ID,
  70. Sectors_Per_Cluster,
  71. Total_Clusters,
  72. Free_Clusters: longint;
  73. Bytes_Per_Sector: word);
  74. 2: {For date/time description,
  75. see file searching realted
  76. routines.}
  77. (Label_Date, {Date when volume label was created.}
  78. Label_Time: word; {Time when volume label was created.}
  79. VolumeLabel: ShortString); {Volume label. Can also be used
  80. as ASCIIZ, because the byte
  81. following the last character of
  82. the string is always zero.}
  83. end;
  84. PFSInfo = ^TFSInfo;
  85. TCountryCode=record
  86. Country, {Country to query info about (0=current).}
  87. CodePage: longint; {Code page to query info about (0=current).}
  88. end;
  89. PCountryCode=^TCountryCode;
  90. TTimeFmt = (Clock12, Clock24);
  91. TCountryInfo=record
  92. Country, CodePage: longint; {Country and codepage requested.}
  93. case byte of
  94. 0:
  95. (DateFormat: longint; {1=ddmmyy 2=yymmdd 3=mmddyy}
  96. CurrencyUnit: array [0..4] of char;
  97. ThousandSeparator: char; {Thousands separator.}
  98. Zero1: byte; {Always zero.}
  99. DecimalSeparator: char; {Decimals separator,}
  100. Zero2: byte;
  101. DateSeparator: char; {Date separator.}
  102. Zero3: byte;
  103. TimeSeparator: char; {Time separator.}
  104. Zero4: byte;
  105. CurrencyFormat, {Bit field:
  106. Bit 0: 0=indicator before value
  107. 1=indicator after value
  108. Bit 1: 1=insert space after
  109. indicator.
  110. Bit 2: 1=Ignore bit 0&1, replace
  111. decimal separator with
  112. indicator.}
  113. DecimalPlace: byte; {Number of decimal places used in
  114. currency indication.}
  115. TimeFormat: TTimeFmt; {12/24 hour.}
  116. Reserve1: array [0..1] of word;
  117. DataSeparator: char; {Data list separator}
  118. Zero5: byte;
  119. Reserve2: array [0..4] of word);
  120. 1:
  121. (fsDateFmt: longint; {1=ddmmyy 2=yymmdd 3=mmddyy}
  122. szCurrency: array [0..4] of char;
  123. {null terminated currency symbol}
  124. szThousandsSeparator: array [0..1] of char;
  125. {Thousands separator + #0}
  126. szDecimal: array [0..1] of char;
  127. {Decimals separator + #0}
  128. szDateSeparator: array [0..1] of char;
  129. {Date separator + #0}
  130. szTimeSeparator: array [0..1] of char;
  131. {Time separator + #0}
  132. fsCurrencyFmt, {Bit field:
  133. Bit 0: 0=indicator before value
  134. 1=indicator after value
  135. Bit 1: 1=insert space after
  136. indicator.
  137. Bit 2: 1=Ignore bit 0&1, replace
  138. decimal separator with
  139. indicator}
  140. cDecimalPlace: byte; {Number of decimal places used in
  141. currency indication}
  142. fsTimeFmt: byte; {0=12,1=24 hours}
  143. abReserved1: array [0..1] of word;
  144. szDataSeparator: array [0..1] of char;
  145. {Data list separator + #0}
  146. abReserved2: array [0..4] of word);
  147. end;
  148. PCountryInfo=^TCountryInfo;
  149. const
  150. ilStandard = 1;
  151. ilQueryEAsize = 2;
  152. ilQueryEAs = 3;
  153. ilQueryFullName = 5;
  154. {This is the correct way to call external assembler procedures.}
  155. procedure syscall;external name '___SYSCALL';
  156. function DosSetFileInfo (Handle, InfoLevel: longint; AFileStatus: PFileStatus;
  157. FileStatusLen: longint): longint; cdecl; external 'DOSCALLS' index 218;
  158. function DosQueryFSInfo (DiskNum, InfoLevel: longint; var Buffer: TFSInfo;
  159. BufLen: longint): longint; cdecl; external 'DOSCALLS' index 278;
  160. function DosQueryFileInfo (Handle, InfoLevel: longint;
  161. AFileStatus: PFileStatus; FileStatusLen: longint): longint; cdecl;
  162. external 'DOSCALLS' index 279;
  163. function DosScanEnv (Name: PChar; var Value: PChar): longint; cdecl;
  164. external 'DOSCALLS' index 227;
  165. function DosFindFirst (FileMask: PChar; var Handle: longint; Attrib: longint;
  166. AFileStatus: PFileStatus; FileStatusLen: longint;
  167. var Count: longint; InfoLevel: longint): longint; cdecl;
  168. external 'DOSCALLS' index 264;
  169. function DosFindNext (Handle: longint; AFileStatus: PFileStatus;
  170. FileStatusLen: longint; var Count: longint): longint; cdecl;
  171. external 'DOSCALLS' index 265;
  172. function DosFindClose (Handle: longint): longint; cdecl;
  173. external 'DOSCALLS' index 263;
  174. function DosQueryCtryInfo (Size: longint; var Country: TCountryCode;
  175. var Res: TCountryInfo; var ActualSize: longint): longint; cdecl;
  176. external 'NLS' index 5;
  177. function DosMapCase (Size: longint; var Country: TCountryCode;
  178. AString: PChar): longint; cdecl; external 'NLS' index 7;
  179. {****************************************************************************
  180. File Functions
  181. ****************************************************************************}
  182. const
  183. ofRead = $0000; {Open for reading}
  184. ofWrite = $0001; {Open for writing}
  185. ofReadWrite = $0002; {Open for reading/writing}
  186. doDenyRW = $0010; {DenyAll (no sharing)}
  187. faCreateNew = $00010000; {Create if file does not exist}
  188. faOpenReplace = $00040000; {Truncate if file exists}
  189. faCreate = $00050000; {Create if file does not exist, truncate otherwise}
  190. FindResvdMask = $00003737; {Allowed bits in attribute
  191. specification for DosFindFirst call.}
  192. {$ASMMODE INTEL}
  193. function FileOpen (const FileName: string; Mode: integer): longint;
  194. {$IFOPT H+}
  195. assembler;
  196. {$ELSE}
  197. var FN: string;
  198. begin
  199. FN := FileName + #0;
  200. {$ENDIF}
  201. asm
  202. mov eax, Mode
  203. (* DenyAll if sharing not specified. *)
  204. test eax, 112
  205. jnz @FOpen1
  206. or eax, 16
  207. @FOpen1:
  208. mov ecx, eax
  209. mov eax, 7F2Bh
  210. {$IFOPT H+}
  211. mov edx, FileName
  212. {$ELSE}
  213. lea edx, FN
  214. inc edx
  215. {$ENDIF}
  216. call syscall
  217. {$IFOPT H-}
  218. mov [ebp - 4], eax
  219. end;
  220. {$ENDIF}
  221. end;
  222. function FileCreate (const FileName: string): longint;
  223. {$IFOPT H+}
  224. assembler;
  225. {$ELSE}
  226. var FN: string;
  227. begin
  228. FN := FileName + #0;
  229. {$ENDIF}
  230. asm
  231. mov eax, 7F2Bh
  232. mov ecx, ofReadWrite or faCreate or doDenyRW (* Sharing to DenyAll *)
  233. {$IFOPT H+}
  234. mov edx, FileName
  235. {$ELSE}
  236. lea edx, FN
  237. inc edx
  238. {$ENDIF}
  239. call syscall
  240. {$IFOPT H-}
  241. mov [ebp - 4], eax
  242. end;
  243. {$ENDIF}
  244. end;
  245. function FileRead (Handle: longint; var Buffer; Count: longint): longint;
  246. assembler;
  247. asm
  248. mov eax, 3F00h
  249. mov ebx, Handle
  250. mov ecx, Count
  251. mov edx, Buffer
  252. call syscall
  253. jnc @FReadEnd
  254. mov eax, -1
  255. @FReadEnd:
  256. end;
  257. function FileWrite (Handle: longint; const Buffer; Count: longint): longint;
  258. assembler;
  259. asm
  260. mov eax, 4000h
  261. mov ebx, Handle
  262. mov ecx, Count
  263. mov edx, Buffer
  264. call syscall
  265. jnc @FWriteEnd
  266. mov eax, -1
  267. @FWriteEnd:
  268. end;
  269. function FileSeek (Handle, FOffset, Origin: longint): longint; assembler;
  270. asm
  271. mov eax, Origin
  272. mov ah, 42h
  273. mov ebx, Handle
  274. mov edx, FOffset
  275. call syscall
  276. jnc @FSeekEnd
  277. mov eax, -1
  278. @FSeekEnd:
  279. end;
  280. Function FileSeek (Handle : Longint; FOffset,Origin : Int64) : Int64;
  281. begin
  282. {$warning need to add 64bit call }
  283. Result:=FileSeek(Handle,Longint(Foffset),Longint(Origin));
  284. end;
  285. procedure FileClose (Handle: longint);
  286. begin
  287. if (Handle <= 4) or (os_mode = osOS2) and (Handle <= 2) then
  288. asm
  289. mov eax, 3E00h
  290. mov ebx, Handle
  291. call syscall
  292. end;
  293. end;
  294. function FileTruncate (Handle, Size: longint): boolean; assembler;
  295. asm
  296. mov eax, 7F25h
  297. mov ebx, Handle
  298. mov edx, Size
  299. call syscall
  300. jc @FTruncEnd
  301. mov eax, 4202h
  302. mov ebx, Handle
  303. mov edx, 0
  304. call syscall
  305. mov eax, 0
  306. jnc @FTruncEnd
  307. dec eax
  308. @FTruncEnd:
  309. end;
  310. function FileAge (const FileName: string): longint;
  311. var Handle: longint;
  312. begin
  313. Handle := FileOpen (FileName, 0);
  314. if Handle <> -1 then
  315. begin
  316. Result := FileGetDate (Handle);
  317. FileClose (Handle);
  318. end
  319. else
  320. Result := -1;
  321. end;
  322. function FileExists (const FileName: string): boolean;
  323. {$IFOPT H+}
  324. assembler;
  325. {$ELSE}
  326. var FN: string;
  327. begin
  328. FN := FileName + #0;
  329. {$ENDIF}
  330. asm
  331. mov ax, 4300h
  332. {$IFOPT H+}
  333. mov edx, FileName
  334. {$ELSE}
  335. lea edx, FN
  336. inc edx
  337. {$ENDIF}
  338. call syscall
  339. mov eax, 0
  340. jc @FExistsEnd
  341. test cx, 18h
  342. jnz @FExistsEnd
  343. inc eax
  344. @FExistsEnd:
  345. {$IFOPT H-}
  346. end;
  347. {$ENDIF}
  348. end;
  349. type TRec = record
  350. T, D: word;
  351. end;
  352. PSearchRec = ^SearchRec;
  353. function FindFirst (const Path: string; Attr: longint; var Rslt: TSearchRec): longint;
  354. var SR: PSearchRec;
  355. FStat: PFileFindBuf3;
  356. Count: longint;
  357. Err: longint;
  358. begin
  359. if os_mode = osOS2 then
  360. begin
  361. New (FStat);
  362. Rslt.FindHandle := $FFFFFFFF;
  363. Count := 1;
  364. Err := DosFindFirst (PChar (Path), Rslt.FindHandle,
  365. Attr and FindResvdMask, FStat, SizeOf (FStat^), Count,
  366. ilStandard);
  367. if (Err = 0) and (Count = 0) then Err := 18;
  368. FindFirst := -Err;
  369. if Err = 0 then
  370. begin
  371. Rslt.Name := FStat^.Name;
  372. Rslt.Size := FStat^.FileSize;
  373. Rslt.Attr := FStat^.AttrFile;
  374. Rslt.ExcludeAttr := 0;
  375. TRec (Rslt.Time).T := FStat^.TimeLastWrite;
  376. TRec (Rslt.Time).D := FStat^.DateLastWrite;
  377. end;
  378. Dispose (FStat);
  379. end
  380. else
  381. begin
  382. Err := DOS.DosError;
  383. GetMem (SR, SizeOf (SearchRec));
  384. Rslt.FindHandle := longint(SR);
  385. DOS.FindFirst (Path, Attr, SR^);
  386. FindFirst := -DOS.DosError;
  387. if DosError = 0 then
  388. begin
  389. Rslt.Time := SR^.Time;
  390. Rslt.Size := SR^.Size;
  391. Rslt.Attr := SR^.Attr;
  392. Rslt.ExcludeAttr := 0;
  393. Rslt.Name := SR^.Name;
  394. end;
  395. DOS.DosError := Err;
  396. end;
  397. end;
  398. function FindNext (var Rslt: TSearchRec): longint;
  399. var SR: PSearchRec;
  400. FStat: PFileFindBuf3;
  401. Count: longint;
  402. Err: longint;
  403. begin
  404. if os_mode = osOS2 then
  405. begin
  406. New (FStat);
  407. Count := 1;
  408. Err := DosFindNext (Rslt.FindHandle, FStat, SizeOf (FStat^),
  409. Count);
  410. if (Err = 0) and (Count = 0) then Err := 18;
  411. FindNext := -Err;
  412. if Err = 0 then
  413. begin
  414. Rslt.Name := FStat^.Name;
  415. Rslt.Size := FStat^.FileSize;
  416. Rslt.Attr := FStat^.AttrFile;
  417. Rslt.ExcludeAttr := 0;
  418. TRec (Rslt.Time).T := FStat^.TimeLastWrite;
  419. TRec (Rslt.Time).D := FStat^.DateLastWrite;
  420. end;
  421. Dispose (FStat);
  422. end
  423. else
  424. begin
  425. SR := PSearchRec (Rslt.FindHandle);
  426. if SR <> nil then
  427. begin
  428. DOS.FindNext (SR^);
  429. FindNext := -DosError;
  430. if DosError = 0 then
  431. begin
  432. Rslt.Time := SR^.Time;
  433. Rslt.Size := SR^.Size;
  434. Rslt.Attr := SR^.Attr;
  435. Rslt.ExcludeAttr := 0;
  436. Rslt.Name := SR^.Name;
  437. end;
  438. end;
  439. end;
  440. end;
  441. procedure FindClose (var F: TSearchrec);
  442. var SR: PSearchRec;
  443. begin
  444. if os_mode = osOS2 then
  445. begin
  446. DosFindClose (F.FindHandle);
  447. end
  448. else
  449. begin
  450. SR := PSearchRec (F.FindHandle);
  451. DOS.FindClose (SR^);
  452. FreeMem (SR, SizeOf (SearchRec));
  453. end;
  454. F.FindHandle := 0;
  455. end;
  456. function FileGetDate (Handle: longint): longint; assembler;
  457. asm
  458. mov ax, 5700h
  459. mov ebx, Handle
  460. call syscall
  461. mov eax, -1
  462. jc @FGetDateEnd
  463. mov ax, dx
  464. shld eax, ecx, 16
  465. @FGetDateEnd:
  466. end;
  467. function FileSetDate (Handle, Age: longint): longint;
  468. var FStat: PFileStatus0;
  469. RC: longint;
  470. begin
  471. if os_mode = osOS2 then
  472. begin
  473. New (FStat);
  474. RC := DosQueryFileInfo (Handle, ilStandard, FStat,
  475. SizeOf (FStat^));
  476. if RC <> 0 then
  477. FileSetDate := -1
  478. else
  479. begin
  480. FStat^.DateLastAccess := Hi (Age);
  481. FStat^.DateLastWrite := Hi (Age);
  482. FStat^.TimeLastAccess := Lo (Age);
  483. FStat^.TimeLastWrite := Lo (Age);
  484. RC := DosSetFileInfo (Handle, ilStandard, FStat,
  485. SizeOf (FStat^));
  486. if RC <> 0 then
  487. FileSetDate := -1
  488. else
  489. FileSetDate := 0;
  490. end;
  491. Dispose (FStat);
  492. end
  493. else
  494. asm
  495. mov ax, 5701h
  496. mov ebx, Handle
  497. mov cx, word ptr [Age]
  498. mov dx, word ptr [Age + 2]
  499. call syscall
  500. jnc @FSetDateEnd
  501. mov eax, -1
  502. @FSetDateEnd:
  503. mov [ebp - 4], eax
  504. end;
  505. end;
  506. function FileGetAttr (const FileName: string): longint;
  507. {$IFOPT H+}
  508. assembler;
  509. {$ELSE}
  510. var FN: string;
  511. begin
  512. FN := FileName + #0;
  513. {$ENDIF}
  514. asm
  515. mov ax, 4300h
  516. {$IFOPT H+}
  517. mov edx, FileName
  518. {$ELSE}
  519. lea edx, FN
  520. inc edx
  521. {$ENDIF}
  522. call syscall
  523. jnc @FGetAttrEnd
  524. mov eax, -1
  525. @FGetAttrEnd:
  526. {$IFOPT H-}
  527. mov [ebp - 4], eax
  528. end;
  529. {$ENDIF}
  530. end;
  531. function FileSetAttr (const Filename: string; Attr: longint): longint;
  532. {$IFOPT H+}
  533. assembler;
  534. {$ELSE}
  535. var FN: string;
  536. begin
  537. FN := FileName + #0;
  538. {$ENDIF}
  539. asm
  540. mov ax, 4301h
  541. mov ecx, Attr
  542. {$IFOPT H+}
  543. mov edx, FileName
  544. {$ELSE}
  545. lea edx, FN
  546. inc edx
  547. {$ENDIF}
  548. call syscall
  549. mov eax, 0
  550. jnc @FSetAttrEnd
  551. mov eax, -1
  552. @FSetAttrEnd:
  553. {$IFOPT H-}
  554. mov [ebp - 4], eax
  555. end;
  556. {$ENDIF}
  557. end;
  558. function DeleteFile (const FileName: string): boolean;
  559. {$IFOPT H+}
  560. assembler;
  561. {$ELSE}
  562. var FN: string;
  563. begin
  564. FN := FileName + #0;
  565. {$ENDIF}
  566. asm
  567. mov ax, 4100h
  568. {$IFOPT H+}
  569. mov edx, FileName
  570. {$ELSE}
  571. lea edx, FN
  572. inc edx
  573. {$ENDIF}
  574. call syscall
  575. mov eax, 0
  576. jc @FDeleteEnd
  577. inc eax
  578. @FDeleteEnd:
  579. {$IFOPT H-}
  580. mov [ebp - 4], eax
  581. end;
  582. {$ENDIF}
  583. end;
  584. function RenameFile (const OldName, NewName: string): boolean;
  585. {$IFOPT H+}
  586. assembler;
  587. {$ELSE}
  588. var FN1, FN2: string;
  589. begin
  590. FN1 := OldName + #0;
  591. FN2 := NewName + #0;
  592. {$ENDIF}
  593. asm
  594. mov ax, 5600h
  595. {$IFOPT H+}
  596. mov edx, OldName
  597. mov edi, NewName
  598. {$ELSE}
  599. lea edx, FN1
  600. inc edx
  601. lea edi, FN2
  602. inc edi
  603. {$ENDIF}
  604. call syscall
  605. mov eax, 0
  606. jc @FRenameEnd
  607. inc eax
  608. @FRenameEnd:
  609. {$IFOPT H-}
  610. mov [ebp - 4], eax
  611. end;
  612. {$ENDIF}
  613. end;
  614. {****************************************************************************
  615. Disk Functions
  616. ****************************************************************************}
  617. {$ASMMODE ATT}
  618. function DiskFree (Drive: byte): int64;
  619. var FI: TFSinfo;
  620. RC: longint;
  621. begin
  622. if (os_mode = osDOS) or (os_mode = osDPMI) then
  623. {Function 36 is not supported in OS/2.}
  624. asm
  625. movb Drive,%dl
  626. movb $0x36,%ah
  627. call syscall
  628. cmpw $-1,%ax
  629. je .LDISKFREE1
  630. mulw %cx
  631. mulw %bx
  632. shll $16,%edx
  633. movw %ax,%dx
  634. movl $0,%eax
  635. xchgl %edx,%eax
  636. leave
  637. ret
  638. .LDISKFREE1:
  639. cltd
  640. leave
  641. ret
  642. end
  643. else
  644. {In OS/2, we use the filesystem information.}
  645. begin
  646. RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  647. if RC = 0 then
  648. DiskFree := int64 (FI.Free_Clusters) *
  649. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  650. else
  651. DiskFree := -1;
  652. end;
  653. end;
  654. function DiskSize (Drive: byte): int64;
  655. var FI: TFSinfo;
  656. RC: longint;
  657. begin
  658. if (os_mode = osDOS) or (os_mode = osDPMI) then
  659. {Function 36 is not supported in OS/2.}
  660. asm
  661. movb Drive,%dl
  662. movb $0x36,%ah
  663. call syscall
  664. movw %dx,%bx
  665. cmpw $-1,%ax
  666. je .LDISKSIZE1
  667. mulw %cx
  668. mulw %bx
  669. shll $16,%edx
  670. movw %ax,%dx
  671. movl $0,%eax
  672. xchgl %edx,%eax
  673. leave
  674. ret
  675. .LDISKSIZE1:
  676. cltd
  677. leave
  678. ret
  679. end
  680. else
  681. {In OS/2, we use the filesystem information.}
  682. begin
  683. RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  684. if RC = 0 then
  685. DiskSize := int64 (FI.Total_Clusters) *
  686. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  687. else
  688. DiskSize := -1;
  689. end;
  690. end;
  691. function GetCurrentDir: string;
  692. begin
  693. GetDir (0, Result);
  694. end;
  695. function SetCurrentDir (const NewDir: string): boolean;
  696. begin
  697. {$I-}
  698. ChDir (NewDir);
  699. Result := (IOResult = 0);
  700. {$I+}
  701. end;
  702. function CreateDir (const NewDir: string): boolean;
  703. begin
  704. {$I-}
  705. MkDir (NewDir);
  706. Result := (IOResult = 0);
  707. {$I+}
  708. end;
  709. function RemoveDir (const Dir: string): boolean;
  710. begin
  711. {$I-}
  712. RmDir (Dir);
  713. Result := (IOResult = 0);
  714. {$I+}
  715. end;
  716. {****************************************************************************
  717. Time Functions
  718. ****************************************************************************}
  719. {$asmmode intel}
  720. procedure GetLocalTime (var SystemTime: TSystemTime); assembler;
  721. asm
  722. (* Expects the default record alignment (word)!!! *)
  723. mov ah, 2Ah
  724. call syscall
  725. mov edi, SystemTime
  726. mov ax, cx
  727. stosw
  728. xor eax, eax
  729. mov al, dl
  730. shl eax, 16
  731. mov al, dh
  732. stosd
  733. push edi
  734. mov ah, 2Ch
  735. call syscall
  736. pop edi
  737. xor eax, eax
  738. mov al, cl
  739. shl eax, 16
  740. mov al, ch
  741. stosd
  742. mov al, dl
  743. shl eax, 16
  744. mov al, dh
  745. stosd
  746. end;
  747. {$asmmode default}
  748. {****************************************************************************
  749. Misc Functions
  750. ****************************************************************************}
  751. procedure Beep;
  752. begin
  753. end;
  754. {****************************************************************************
  755. Locale Functions
  756. ****************************************************************************}
  757. procedure InitAnsi;
  758. var I: byte;
  759. Country: TCountryCode;
  760. begin
  761. for I := 0 to 255 do
  762. UpperCaseTable [I] := Chr (I);
  763. Move (UpperCaseTable, LowerCaseTable, SizeOf (UpperCaseTable));
  764. if os_mode = osOS2 then
  765. begin
  766. FillChar (Country, SizeOf (Country), 0);
  767. DosMapCase (SizeOf (UpperCaseTable), Country, @UpperCaseTable);
  768. end
  769. else
  770. begin
  771. (* !!! TODO: DOS/DPMI mode support!!! *)
  772. end;
  773. for I := 0 to 255 do
  774. if UpperCaseTable [I] <> Chr (I) then
  775. LowerCaseTable [Ord (UpperCaseTable [I])] := Chr (I);
  776. end;
  777. procedure InitInternational;
  778. var Country: TCountryCode;
  779. CtryInfo: TCountryInfo;
  780. Size: longint;
  781. RC: longint;
  782. begin
  783. Size := 0;
  784. FillChar (Country, SizeOf (Country), 0);
  785. FillChar (CtryInfo, SizeOf (CtryInfo), 0);
  786. RC := DosQueryCtryInfo (SizeOf (CtryInfo), Country, CtryInfo, Size);
  787. if RC = 0 then
  788. begin
  789. DateSeparator := CtryInfo.DateSeparator;
  790. case CtryInfo.DateFormat of
  791. 1: begin
  792. ShortDateFormat := 'd/m/y';
  793. LongDateFormat := 'dd" "mmmm" "yyyy';
  794. end;
  795. 2: begin
  796. ShortDateFormat := 'y/m/d';
  797. LongDateFormat := 'yyyy" "mmmm" "dd';
  798. end;
  799. 3: begin
  800. ShortDateFormat := 'm/d/y';
  801. LongDateFormat := 'mmmm" "dd" "yyyy';
  802. end;
  803. end;
  804. TimeSeparator := CtryInfo.TimeSeparator;
  805. DecimalSeparator := CtryInfo.DecimalSeparator;
  806. ThousandSeparator := CtryInfo.ThousandSeparator;
  807. CurrencyFormat := CtryInfo.CurrencyFormat;
  808. CurrencyString := PChar (CtryInfo.CurrencyUnit);
  809. end;
  810. InitAnsi;
  811. end;
  812. function SysErrorMessage(ErrorCode: Integer): String;
  813. begin
  814. Result:=Format(SUnknownErrorCode,[ErrorCode]);
  815. end;
  816. {****************************************************************************
  817. OS Utils
  818. ****************************************************************************}
  819. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  820. var P: PChar;
  821. begin
  822. if DosScanEnv (PChar (EnvVar), P) = 0
  823. then GetEnvironmentVariable := StrPas (P)
  824. else GetEnvironmentVariable := '';
  825. end;
  826. {****************************************************************************
  827. Initialization code
  828. ****************************************************************************}
  829. Initialization
  830. InitExceptions; { Initialize exceptions. OS independent }
  831. InitInternational; { Initialize internationalization settings }
  832. Finalization
  833. DoneExceptions;
  834. end.
  835. {
  836. $Log$
  837. Revision 1.18 2002-09-23 17:42:37 hajny
  838. * AnsiString to PChar typecast
  839. Revision 1.17 2002/09/07 16:01:25 peter
  840. * old logs removed and tabs fixed
  841. Revision 1.16 2002/07/11 16:00:05 hajny
  842. * FindFirst fix (invalid attribute bits masked out)
  843. Revision 1.15 2002/01/25 16:23:03 peter
  844. * merged filesearch() fix
  845. }