sysutils.pp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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) : LongInt;
  55. begin
  56. result := -1;
  57. end;
  58. function FileSetDate(Handle, Age: LongInt) : 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): Longint;
  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 FileExists (Const FileName : RawByteString) : Boolean;
  135. var
  136. SystemFileName: RawByteString;
  137. begin
  138. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  139. FileExists := _Access(pointer(SystemFileName), F_OK) = 0;
  140. end;
  141. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  142. begin
  143. result := -1;
  144. end;
  145. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  146. begin
  147. result := -1;
  148. end;
  149. Procedure InternalFindClose(var Handle: THandle);
  150. begin
  151. end;
  152. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  153. var
  154. Info : TStat;
  155. SystemFileName: RawByteString;
  156. begin
  157. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  158. If _stat(pchar(SystemFileName), Info) <> 0 then
  159. Result := -1
  160. Else
  161. Result := (Info.st_mode shr 16) and $ffff;
  162. end;
  163. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  164. begin
  165. result := -1;
  166. end;
  167. {****************************************************************************
  168. Disk Functions
  169. ****************************************************************************}
  170. Procedure AddDisk(const path:string);
  171. begin
  172. end;
  173. Function DiskFree(Drive: Byte): int64;
  174. Begin
  175. result := -1;
  176. End;
  177. Function DiskSize(Drive: Byte): int64;
  178. Begin
  179. result := -1;
  180. End;
  181. function DirectoryExists(const Directory: RawByteString): Boolean;
  182. begin
  183. result := false;
  184. end;
  185. {****************************************************************************
  186. Misc Functions
  187. ****************************************************************************}
  188. Procedure SysBeep;
  189. begin
  190. end;
  191. Procedure Sleep(Milliseconds : Cardinal);
  192. var
  193. i,j : Cardinal;
  194. calib : Cardinal;
  195. begin
  196. { $warning no idea if this calibration value is correct (FK) }
  197. { I estimated it roughly on the CPU clock of 16 MHz and 1+3 clock cycles for the loop }
  198. {
  199. calib:=4000000;
  200. for i:=1 to Milliseconds do
  201. asm
  202. ldr r0,calib
  203. .L1:
  204. sub r0,r0,#1
  205. bne .L1
  206. end;
  207. }
  208. end;
  209. {****************************************************************************
  210. Locale Functions
  211. ****************************************************************************}
  212. Procedure GetLocalTime(var SystemTime: TSystemTime);
  213. begin
  214. end ;
  215. function SysErrorMessage(ErrorCode: Integer): String;
  216. begin
  217. { Result:=StrError(ErrorCode);}
  218. result := '';
  219. end;
  220. {****************************************************************************
  221. OS utility functions
  222. ****************************************************************************}
  223. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  224. begin
  225. result := '';
  226. end;
  227. Function GetEnvironmentVariableCount : Integer;
  228. begin
  229. result := -1;
  230. end;
  231. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  232. begin
  233. result := '';
  234. end;
  235. function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]): integer;
  236. begin
  237. result := -1;
  238. end;
  239. function ExecuteProcess (const Path: AnsiString; const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
  240. begin
  241. result := -1;
  242. end;
  243. function GetLastOSError: Integer;
  244. begin
  245. Result := -1;
  246. end;
  247. {****************************************************************************
  248. Initialization code
  249. ****************************************************************************}
  250. Initialization
  251. InitExceptions;
  252. Finalization
  253. DoneExceptions;
  254. end.