sysutils.pp 7.6 KB

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