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