sysutils.pp 8.0 KB

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