sysutils.pp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2004 by Karoly Balogh
  4. Sysutils unit for Nintendo DS.
  5. This unit is based on the MorphOS one and is adapted for Nintendo DS
  6. simply by stripping out all stuff inside funcs and procs.
  7. Copyright (c) 2006 by Francesco Lombardi
  8. Based on Amiga version by Carl Eric Codere, and other
  9. parts of the RTL
  10. See the file COPYING.FPC, included in this distribution,
  11. for details about the copyright.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. **********************************************************************}
  16. {$IFNDEF FPC_DOTTEDUNITS}
  17. unit sysutils;
  18. {$ENDIF FPC_DOTTEDUNITS}
  19. interface
  20. {$MODE objfpc}
  21. {$MODESWITCH OUT}
  22. {$IFDEF UNICODERTL}
  23. {$MODESWITCH UNICODESTRINGS}
  24. {$ELSE}
  25. {$H+}
  26. {$ENDIF}
  27. {$modeswitch typehelpers}
  28. {$modeswitch advancedrecords}
  29. {$DEFINE HAS_OSERROR}
  30. {$DEFINE HAS_SLEEP}
  31. { used OS file system APIs use ansistring }
  32. {$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  33. { OS has an ansistring/single byte environment variable API }
  34. {$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
  35. { Include platform independent interface part }
  36. {$i sysutilh.inc}
  37. implementation
  38. {$IFDEF FPC_DOTTEDUNITS}
  39. uses
  40. System.SysConst;
  41. {$ELSE FPC_DOTTEDUNITS}
  42. uses
  43. sysconst;
  44. {$ENDIF FPC_DOTTEDUNITS}
  45. { Include platform independent implementation part }
  46. {$i sysutils.inc}
  47. {****************************************************************************
  48. File Functions
  49. ****************************************************************************}
  50. function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
  51. var
  52. NDSFlags: longint;
  53. SystemFileName: RawByteString;
  54. begin
  55. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  56. NDSFlags := 0;
  57. case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
  58. fmOpenRead : NDSFlags := NDSFlags or O_RdOnly;
  59. fmOpenWrite : NDSFlags := NDSFlags or O_WrOnly;
  60. fmOpenReadWrite : NDSFlags := NDSFlags or O_RdWr;
  61. end;
  62. FileOpen := _open(PAnsiChar(SystemFileName), NDSFlags);
  63. end;
  64. function FileGetDate(Handle: LongInt) : Int64;
  65. begin
  66. result := -1;
  67. end;
  68. function FileSetDate(Handle: LongInt; Age: Int64) : LongInt;
  69. begin
  70. result := -1;
  71. end;
  72. function FileCreate(const FileName: RawByteString) : LongInt;
  73. var
  74. SystemFileName: RawByteString;
  75. begin
  76. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  77. FileCreate:=_open(pointer(SystemFileName), O_RdWr or O_Creat or O_Trunc);
  78. end;
  79. function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
  80. var
  81. SystemFileName: RawByteString;
  82. begin
  83. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  84. FileCreate:=_Open(pointer(SystemFileName),O_RdWr or O_Creat or O_Trunc,Rights);
  85. end;
  86. function FileCreate(const FileName: RawByteString; ShareMode : Integer; Rights: integer): LongInt;
  87. begin
  88. result := FileCreate(FileName, Rights);
  89. end;
  90. function FileRead(Handle: LongInt; Out Buffer; Count: LongInt): LongInt;
  91. begin
  92. FileRead := _Read(Handle, Buffer, Count);
  93. end;
  94. function FileWrite(Handle: LongInt; const Buffer; Count: LongInt): LongInt;
  95. begin
  96. FileWrite := _Write(Handle, @Buffer, Count);
  97. end;
  98. function FileSeek(Handle, FOffset, Origin: LongInt) : LongInt;
  99. begin
  100. result := longint(FileSeek(Handle, int64(FOffset), Origin));
  101. end;
  102. function FileSeek(Handle: LongInt; FOffset: Int64; Origin: Longint): Int64;
  103. begin
  104. FileSeek := _lSeek(Handle, FOffset, Origin);
  105. end;
  106. procedure FileClose(Handle: LongInt);
  107. begin
  108. _close(Handle);
  109. end;
  110. function FileTruncate(Handle: THandle; Size: Int64): Boolean;
  111. begin
  112. if Size > high (longint) then
  113. FileTruncate := false
  114. else
  115. FileTruncate:=(_truncate(Handle,Size) = 0);
  116. end;
  117. function DeleteFile(const FileName: RawByteString) : Boolean;
  118. var
  119. SystemFileName: RawByteString;
  120. begin
  121. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  122. Result := _UnLink(pointer(SystemFileName))>= 0;
  123. end;
  124. function RenameFile(const OldName, NewName: RawByteString): Boolean;
  125. var
  126. OldSystemFileName, NewSystemFileName: RawByteString;
  127. begin
  128. OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
  129. NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
  130. RenameFile := _Rename(pointer(OldSystemFileName), pointer(NewSystemFileName)) >= 0;
  131. end;
  132. (****** end of non portable routines ******)
  133. Function FileAge (Const FileName : RawByteString): Int64;
  134. var
  135. info: Stat;
  136. SystemFileName: RawByteString;
  137. begin
  138. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  139. if (_stat(PAnsiChar(SystemFileName), Info) < 0) or S_ISDIR(info.st_mode) then
  140. exit(-1)
  141. else
  142. Result := (info.st_mtime);
  143. end;
  144. function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
  145. begin
  146. Result := False;
  147. end;
  148. Function FileExists (Const FileName : RawByteString; FollowLink : Boolean) : Boolean;
  149. var
  150. SystemFileName: RawByteString;
  151. begin
  152. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  153. FileExists := _Access(pointer(SystemFileName), F_OK) = 0;
  154. end;
  155. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  156. begin
  157. result := -1;
  158. end;
  159. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  160. begin
  161. result := -1;
  162. end;
  163. Procedure InternalFindClose(var Handle: THandle);
  164. begin
  165. end;
  166. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  167. var
  168. Info : TStat;
  169. SystemFileName: RawByteString;
  170. begin
  171. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  172. If _stat(PAnsiChar(SystemFileName), Info) <> 0 then
  173. Result := -1
  174. Else
  175. Result := (Info.st_mode shr 16) and $ffff;
  176. end;
  177. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  178. begin
  179. result := -1;
  180. end;
  181. {****************************************************************************
  182. Disk Functions
  183. ****************************************************************************}
  184. Procedure AddDisk(const path:string);
  185. begin
  186. end;
  187. Function DiskFree(Drive: Byte): int64;
  188. Begin
  189. result := -1;
  190. End;
  191. Function DiskSize(Drive: Byte): int64;
  192. Begin
  193. result := -1;
  194. End;
  195. function DirectoryExists(const Directory: RawByteString; FollowLink : Boolean): Boolean;
  196. begin
  197. result := false;
  198. end;
  199. {****************************************************************************
  200. Misc Functions
  201. ****************************************************************************}
  202. Procedure SysBeep;
  203. begin
  204. end;
  205. Procedure Sleep(Milliseconds : Cardinal);
  206. var
  207. i,j : Cardinal;
  208. calib : Cardinal;
  209. begin
  210. { $warning no idea if this calibration value is correct (FK) }
  211. { I estimated it roughly on the CPU clock of 16 MHz and 1+3 clock cycles for the loop }
  212. {
  213. calib:=4000000;
  214. for i:=1 to Milliseconds do
  215. asm
  216. ldr r0,calib
  217. .L1:
  218. sub r0,r0,#1
  219. bne .L1
  220. end;
  221. }
  222. end;
  223. {****************************************************************************
  224. Locale Functions
  225. ****************************************************************************}
  226. Procedure GetLocalTime(var SystemTime: TSystemTime);
  227. begin
  228. end ;
  229. function SysErrorMessage(ErrorCode: Integer): String;
  230. begin
  231. { Result:=StrError(ErrorCode);}
  232. result := '';
  233. end;
  234. {****************************************************************************
  235. OS utility functions
  236. ****************************************************************************}
  237. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  238. begin
  239. result := '';
  240. end;
  241. Function GetEnvironmentVariableCount : Integer;
  242. begin
  243. result := -1;
  244. end;
  245. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  246. begin
  247. result := '';
  248. end;
  249. function ExecuteProcess (const Path: RawByteString; const ComLine: RawByteString;Flags:TExecuteFlags=[]): integer;
  250. begin
  251. result := -1;
  252. end;
  253. function ExecuteProcess (const Path: RawByteString; const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
  254. begin
  255. result := -1;
  256. end;
  257. function ExecuteProcess(const Path: UnicodeString; const ComLine: UnicodeString;
  258. Flags: TExecuteFlags = []): Integer;
  259. begin
  260. { TODO : implement }
  261. result := -1;
  262. end;
  263. function ExecuteProcess(const Path: UnicodeString;
  264. const ComLine: Array of UnicodeString; Flags:TExecuteFlags = []): Integer;
  265. var
  266. CommandLine: UnicodeString;
  267. I: integer;
  268. begin
  269. Commandline := '';
  270. for I := 0 to High (ComLine) do
  271. if Pos (' ', ComLine [I]) <> 0 then
  272. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  273. else
  274. CommandLine := CommandLine + ' ' + Comline [I];
  275. ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
  276. end;
  277. function GetLastOSError: Integer;
  278. begin
  279. Result := -1;
  280. end;
  281. {****************************************************************************
  282. Initialization code
  283. ****************************************************************************}
  284. Initialization
  285. InitExceptions;
  286. Finalization
  287. FreeTerminateProcs;
  288. DoneExceptions;
  289. end.