sysutils.pp 8.9 KB

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