sysutils.pp 9.0 KB

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