Rev 790 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
790 | bw | 1 | {utf8} |
616 | bw | 2 | unit sysutils; |
3 | |||
4 | {$i _defines.inc} |
||
790 | bw | 5 | {$mode objfpc} |
6 | {$h+} |
||
616 | bw | 7 | |
8 | interface |
||
9 | |||
10 | { force ansistrings } |
||
11 | |||
12 | {$DEFINE HAS_SLEEP} |
||
13 | {-$DEFINE HAS_OSERROR} |
||
14 | {-$DEFINE HAS_OSCONFIG} |
||
15 | {-$DEFINE HAS_CREATEGUID} |
||
16 | |||
17 | |||
18 | { Include platform independent interface part } |
||
19 | {$i sysutilh.inc} |
||
20 | |||
21 | implementation |
||
22 | |||
23 | |||
24 | uses |
||
25 | SysConst; |
||
26 | |||
27 | |||
28 | {-$define HASCREATEGUID} |
||
29 | {-$define HASEXPANDUNCFILENAME} |
||
30 | {-$DEFINE FPC_NOGENERICANSIROUTINES} |
||
31 | {-$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *) |
||
32 | {-$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *) |
||
33 | |||
34 | { Include platform independent implementation part } |
||
35 | {$i sysutils.inc} |
||
36 | |||
37 | |||
38 | {**************************************************************************** |
||
39 | File Functions |
||
40 | ****************************************************************************} |
||
41 | |||
42 | const |
||
43 | FILEHANDLEPREFIX = $4000; |
||
44 | type |
||
45 | PFileRecord = ^TFileRecord; |
||
46 | TFileRecord = record |
||
47 | Filled: Boolean; |
||
48 | F: File; |
||
49 | end; |
||
50 | var |
||
51 | FileHandles: array of TFileRecord; |
||
52 | |||
53 | function FileRecordByHandle(Handle: THandle): PFileRecord; |
||
54 | begin |
||
55 | Dec(Handle, FILEHANDLEPREFIX); |
||
56 | Result := @FileHandles[Handle]; |
||
57 | end; |
||
58 | |||
59 | function CreateFileRecord(): THandle; |
||
60 | var |
||
61 | I, C: Longword; |
||
62 | begin |
||
63 | Result := -1; |
||
64 | C := Length(FileHandles); |
||
65 | for I := 0 to C - 1 do |
||
66 | if not FileHandles[I].Filled then |
||
67 | begin |
||
68 | Result := I; |
||
69 | Break; |
||
70 | end; |
||
71 | if Result < 0 then |
||
72 | begin |
||
73 | SetLength(FileHandles, C + 1); |
||
74 | Result := C; |
||
75 | end; |
||
76 | FileHandles[Result].Filled := True; |
||
77 | FillChar(FileHandles[Result].F, SizeOf(FileRec), 0); |
||
78 | Inc(Result, FILEHANDLEPREFIX); |
||
79 | end; |
||
80 | |||
81 | procedure ReleaseFileRecord(Handle: THandle); |
||
82 | begin |
||
83 | FileRecordByHandle(Handle)^.Filled := False; |
||
84 | end; |
||
85 | |||
86 | function FileOpen(const FileName: String; Mode: Integer): THandle; |
||
87 | var |
||
88 | F: File; |
||
89 | begin |
||
90 | Filemode := Mode; |
||
91 | Assign(F, FileName); |
||
92 | Reset(F, 1); |
||
93 | if InOutRes = 0 then |
||
94 | begin |
||
95 | Result := CreateFileRecord(); |
||
96 | FileRecordByHandle(Result)^.F := F; |
||
97 | end else |
||
98 | Result := feInvalidHandle; |
||
99 | end; |
||
100 | |||
101 | function FileCreate(const FileName: String): THandle; |
||
102 | var |
||
103 | F: File; |
||
104 | begin |
||
105 | Assign(F, FileName); |
||
106 | Rewrite(F, 1); |
||
107 | if InOutRes = 0 then |
||
108 | begin |
||
109 | Result := CreateFileRecord(); |
||
110 | FileRecordByHandle(Result)^.F := F; |
||
111 | end else |
||
112 | Result := feInvalidHandle; |
||
113 | end; |
||
114 | |||
115 | function FileCreate(const FileName: String; Mode: Integer): THandle; |
||
116 | var |
||
117 | F: File; |
||
118 | begin |
||
119 | Filemode := Mode; |
||
120 | Assign(F, FileName); |
||
121 | Rewrite(F, 1); |
||
122 | if InOutRes = 0 then |
||
123 | begin |
||
124 | Result := CreateFileRecord(); |
||
125 | FileRecordByHandle(Result)^.F := F; |
||
126 | end else |
||
127 | Result := feInvalidHandle; |
||
128 | end; |
||
129 | |||
130 | function FileRead(Handle: THandle; var Buffer; Count: Longint): Longint; |
||
131 | begin |
||
132 | BlockRead(FileRecordByHandle(Handle)^.F, Buffer, Count, Result); |
||
133 | end; |
||
134 | |||
135 | function FileWrite(Handle: THandle; const Buffer; Count: Longint): Longint; |
||
136 | begin |
||
137 | BlockWrite(FileRecordByHandle(Handle)^.F, Buffer, Count, Result); |
||
138 | end; |
||
139 | |||
140 | function FileSeek(Handle: THandle; FOffset, Origin: Longint): Longint; |
||
141 | begin |
||
142 | Result := FileSeek(Handle, Int64(FOffset), Origin); |
||
143 | end; |
||
144 | |||
145 | function FileSeek(Handle: THandle; FOffset: Int64; Origin: Longint): Int64; |
||
146 | var |
||
147 | Position: Int64; |
||
148 | begin |
||
149 | case Origin of |
||
150 | fsFromBeginning: Position := FOffset; |
||
151 | fsFromCurrent: Position := FilePos(FileRecordByHandle(Handle)^.F) + FOffset; |
||
152 | fsFromEnd: Position := FileSize(FileRecordByHandle(Handle)^.F) + FOffset; |
||
153 | end; |
||
790 | bw | 154 | {TODO: проверка соответствия [0..filesize]} |
616 | bw | 155 | Seek(FileRecordByHandle(Handle)^.F, Position); |
156 | Result := Position; |
||
157 | end; |
||
158 | |||
159 | procedure FileClose(Handle: THandle); |
||
160 | begin |
||
161 | Close(FileRecordByHandle(Handle)^.F); |
||
162 | ReleaseFileRecord(Handle); |
||
163 | end; |
||
164 | |||
7625 | siemargl | 165 | function FileTruncate(Handle: THandle; Size: Int64): Boolean; |
616 | bw | 166 | begin |
167 | Result := False; |
||
168 | end; |
||
169 | |||
170 | function FileAge(const FileName: String): Longint; |
||
171 | begin |
||
172 | Result := 0; |
||
173 | end; |
||
174 | |||
175 | function FileExists(const FileName: String): Boolean; |
||
176 | var |
||
177 | F: File; |
||
178 | begin |
||
790 | bw | 179 | {$i-} |
616 | bw | 180 | Assign(F, FileName); |
790 | bw | 181 | Reset(F); |
182 | if IOResult = 0 then |
||
183 | begin |
||
616 | bw | 184 | Result := True; |
790 | bw | 185 | Close(F); |
186 | end else |
||
616 | bw | 187 | Result := False; |
790 | bw | 188 | {$i+} |
616 | bw | 189 | end; |
190 | |||
191 | function DirectoryExists(const Directory: String): Boolean; |
||
192 | begin |
||
193 | Result := False; |
||
194 | end; |
||
195 | |||
196 | function FindMatch(var f: TSearchRec): Longint; |
||
197 | begin |
||
198 | Result := feInvalidHandle; |
||
199 | end; |
||
200 | |||
201 | function FindFirst(const Path: String; Attr: Longint; out Rslt: TSearchRec): Longint; |
||
202 | begin |
||
203 | Result := feInvalidHandle; |
||
204 | end; |
||
205 | |||
206 | function FindNext(var Rslt: TSearchRec): Longint; |
||
207 | begin |
||
208 | Result := feInvalidHandle; |
||
209 | end; |
||
210 | |||
211 | procedure FindClose(var F: TSearchrec); |
||
212 | begin |
||
213 | end; |
||
214 | |||
215 | function FileGetDate(Handle: THandle): Longint; |
||
216 | begin |
||
217 | Result := feInvalidHandle; |
||
218 | end; |
||
219 | |||
220 | function FileSetDate(Handle: THandle; Age: Longint): Longint; |
||
221 | begin |
||
222 | Result := feInvalidHandle; |
||
223 | end; |
||
224 | |||
225 | function FileGetAttr(const FileName: String): Longint; |
||
226 | begin |
||
227 | Result := feInvalidHandle; |
||
228 | end; |
||
229 | |||
230 | function FileSetAttr(const Filename: String; Attr: longint): Longint; |
||
231 | begin |
||
232 | Result := feInvalidHandle; |
||
233 | end; |
||
234 | |||
235 | function DeleteFile(const FileName: String): Boolean; |
||
236 | begin |
||
237 | Result := False; |
||
238 | end; |
||
239 | |||
240 | function RenameFile(const OldName, NewName: String): Boolean; |
||
241 | begin |
||
242 | Result := False; |
||
243 | end; |
||
244 | |||
245 | |||
246 | {**************************************************************************** |
||
247 | Disk Functions |
||
248 | ****************************************************************************} |
||
249 | |||
250 | function DiskFree(drive: Byte): Int64; |
||
251 | begin |
||
252 | Result := 0; |
||
253 | end; |
||
254 | |||
255 | function DiskSize(drive: Byte): Int64; |
||
256 | begin |
||
257 | Result := 0; |
||
258 | end; |
||
259 | |||
260 | function GetCurrentDir: String; |
||
261 | begin |
||
262 | GetDir(0, Result); |
||
263 | end; |
||
264 | |||
265 | function SetCurrentDir(const NewDir: String): Boolean; |
||
266 | var |
||
267 | Path: String; |
||
268 | begin |
||
269 | ChDir(NewDir); |
||
270 | GetDir(0, Path); |
||
271 | Result := Path = NewDir; |
||
272 | end; |
||
273 | |||
274 | function CreateDir(const NewDir: String): Boolean; |
||
275 | begin |
||
276 | Result := False; |
||
277 | end; |
||
278 | |||
279 | function RemoveDir(const Dir: String): Boolean; |
||
280 | begin |
||
281 | Result := False; |
||
282 | end; |
||
283 | |||
284 | |||
285 | {**************************************************************************** |
||
286 | Time Functions |
||
287 | ****************************************************************************} |
||
288 | |||
289 | procedure GetLocalTime(var SystemTime: TSystemTime); |
||
290 | begin |
||
291 | end; |
||
292 | |||
293 | |||
294 | {**************************************************************************** |
||
295 | Misc Functions |
||
296 | ****************************************************************************} |
||
297 | |||
298 | procedure Beep; |
||
299 | begin |
||
300 | end; |
||
301 | |||
302 | |||
303 | {**************************************************************************** |
||
304 | Locale Functions |
||
305 | ****************************************************************************} |
||
306 | |||
307 | procedure GetFormatSettings; |
||
308 | var |
||
309 | HF: String; |
||
310 | begin |
||
311 | ShortMonthNames[1] := SShortMonthNameJan; |
||
312 | ShortMonthNames[2] := SShortMonthNameFeb; |
||
313 | ShortMonthNames[3] := SShortMonthNameMar; |
||
314 | ShortMonthNames[4] := SShortMonthNameApr; |
||
315 | ShortMonthNames[5] := SShortMonthNameMay; |
||
316 | ShortMonthNames[6] := SShortMonthNameJun; |
||
317 | ShortMonthNames[7] := SShortMonthNameJul; |
||
318 | ShortMonthNames[8] := SShortMonthNameAug; |
||
319 | ShortMonthNames[9] := SShortMonthNameSep; |
||
320 | ShortMonthNames[10] := SShortMonthNameOct; |
||
321 | ShortMonthNames[11] := SShortMonthNameNov; |
||
322 | ShortMonthNames[12] := SShortMonthNameDec; |
||
323 | |||
324 | LongMonthNames[1] := SLongMonthNameJan; |
||
325 | LongMonthNames[2] := SLongMonthNameFeb; |
||
326 | LongMonthNames[3] := SLongMonthNameMar; |
||
327 | LongMonthNames[4] := SLongMonthNameApr; |
||
328 | LongMonthNames[5] := SLongMonthNameMay; |
||
329 | LongMonthNames[6] := SLongMonthNameJun; |
||
330 | LongMonthNames[7] := SLongMonthNameJul; |
||
331 | LongMonthNames[8] := SLongMonthNameAug; |
||
332 | LongMonthNames[9] := SLongMonthNameSep; |
||
333 | LongMonthNames[10] := SLongMonthNameOct; |
||
334 | LongMonthNames[11] := SLongMonthNameNov; |
||
335 | LongMonthNames[12] := SLongMonthNameDec; |
||
336 | |||
337 | ShortDayNames[1] := SShortDayNameMon; |
||
338 | ShortDayNames[2] := SShortDayNameTue; |
||
339 | ShortDayNames[3] := SShortDayNameWed; |
||
340 | ShortDayNames[4] := SShortDayNameThu; |
||
341 | ShortDayNames[5] := SShortDayNameFri; |
||
342 | ShortDayNames[6] := SShortDayNameSat; |
||
343 | ShortDayNames[7] := SShortDayNameSun; |
||
344 | |||
345 | LongDayNames[1] := SLongDayNameMon; |
||
346 | LongDayNames[2] := SLongDayNameTue; |
||
347 | LongDayNames[3] := SLongDayNameWed; |
||
348 | LongDayNames[4] := SLongDayNameThu; |
||
349 | LongDayNames[5] := SLongDayNameFri; |
||
350 | LongDayNames[6] := SLongDayNameSat; |
||
351 | LongDayNames[7] := SShortDayNameSun; |
||
352 | |||
353 | DateSeparator := '/'; |
||
354 | ShortDateFormat := 'd/mm/yy'; |
||
355 | LongDateFormat := 'd mmmm yyyy'; |
||
356 | { Time stuff } |
||
357 | TimeSeparator := ':'; |
||
358 | TimeAMString := 'AM'; |
||
359 | TimePMString := 'PM'; |
||
360 | HF := 'hh'; |
||
361 | // No support for 12 hour stuff at the moment... |
||
362 | ShortTimeFormat := HF + ':nn'; |
||
363 | LongTimeFormat := HF + ':nn:ss'; |
||
364 | { Currency stuff } |
||
365 | CurrencyString := ''; |
||
366 | CurrencyFormat := 0; |
||
367 | NegCurrFormat := 0; |
||
368 | { Number stuff } |
||
369 | ThousandSeparator := ','; |
||
370 | DecimalSeparator := '.'; |
||
371 | CurrencyDecimals := 2; |
||
372 | end; |
||
373 | |||
374 | Procedure InitInternational; |
||
375 | begin |
||
376 | InitInternationalGeneric; |
||
377 | GetFormatSettings; |
||
378 | end; |
||
379 | |||
380 | |||
381 | {**************************************************************************** |
||
382 | Target Dependent |
||
383 | ****************************************************************************} |
||
384 | |||
385 | function SysErrorMessage(ErrorCode: Integer): String; |
||
386 | const |
||
387 | MaxMsgSize = 255; |
||
388 | var |
||
389 | MsgBuffer: PChar; |
||
390 | begin |
||
391 | GetMem(MsgBuffer, MaxMsgSize); |
||
392 | FillChar(MsgBuffer^, MaxMsgSize, #0); |
||
393 | {TODO} |
||
394 | Result := StrPas(MsgBuffer); |
||
395 | FreeMem(MsgBuffer, MaxMsgSize); |
||
396 | end; |
||
397 | |||
398 | {**************************************************************************** |
||
399 | Initialization code |
||
400 | ****************************************************************************} |
||
401 | |||
402 | Function GetEnvironmentVariable(Const EnvVar: String): String; |
||
403 | begin |
||
404 | Result := ''; |
||
405 | end; |
||
406 | |||
407 | Function GetEnvironmentVariableCount: Integer; |
||
408 | begin |
||
409 | Result := 0; |
||
410 | end; |
||
411 | |||
412 | Function GetEnvironmentString(Index : Integer) : String; |
||
413 | begin |
||
414 | Result := ''; |
||
415 | end; |
||
416 | |||
417 | function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString): Integer; |
||
418 | begin |
||
419 | Result := 0; |
||
420 | end; |
||
421 | |||
422 | function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString): Integer; |
||
423 | var |
||
424 | CommandLine: AnsiString; |
||
425 | i: Integer; |
||
426 | begin |
||
427 | Commandline:=''; |
||
428 | For i:=0 to high(ComLine) Do |
||
429 | Commandline:=CommandLine+' '+Comline[i]; |
||
430 | ExecuteProcess:=ExecuteProcess(Path,CommandLine); |
||
431 | end; |
||
432 | |||
433 | procedure Sleep(Milliseconds: Cardinal); |
||
434 | begin |
||
435 | kos_delay(Milliseconds div 10); |
||
436 | end; |
||
437 | |||
438 | function GetLastOSError: Integer; |
||
439 | begin |
||
440 | Result := -1; |
||
441 | end; |
||
442 | |||
443 | |||
444 | |||
445 | initialization |
||
446 | InitExceptions; |
||
447 | InitInternational; |
||
448 | finalization |
||
449 | DoneExceptions; |
||
450 | end.> |