sysutils.pp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 : String): Longint;
  120. var
  121. info: Stat;
  122. begin
  123. if (_stat(pchar(FileName), Info) < 0) or S_ISDIR(info.st_mode) then
  124. exit(-1)
  125. else
  126. Result := (info.st_mtime);
  127. end;
  128. Function FileExists (Const FileName : RawByteString) : Boolean;
  129. var
  130. SystemFileName: RawByteString;
  131. begin
  132. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  133. FileExists := _Access(pointer(SystemFileName), F_OK) = 0;
  134. end;
  135. Function FindFirst (Const Path : String; Attr : Longint; Out Rslt : TSearchRec) : Longint;
  136. begin
  137. result := -1;
  138. end;
  139. Function FindNext (Var Rslt : TSearchRec) : Longint;
  140. begin
  141. result := -1;
  142. end;
  143. Procedure FindClose (Var F : TSearchrec);
  144. begin
  145. end;
  146. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  147. var
  148. Info : TStat;
  149. SystemFileName: RawByteString;
  150. begin
  151. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  152. If _stat(pchar(SystemFileName), Info) <> 0 then
  153. Result := -1
  154. Else
  155. Result := (Info.st_mode shr 16) and $ffff;
  156. end;
  157. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  158. begin
  159. result := -1;
  160. end;
  161. {****************************************************************************
  162. Disk Functions
  163. ****************************************************************************}
  164. Procedure AddDisk(const path:string);
  165. begin
  166. end;
  167. Function DiskFree(Drive: Byte): int64;
  168. Begin
  169. result := -1;
  170. End;
  171. Function DiskSize(Drive: Byte): int64;
  172. Begin
  173. result := -1;
  174. End;
  175. function DirectoryExists(const Directory: RawByteString): Boolean;
  176. begin
  177. result := false;
  178. end;
  179. {****************************************************************************
  180. Misc Functions
  181. ****************************************************************************}
  182. Procedure SysBeep;
  183. begin
  184. end;
  185. {****************************************************************************
  186. Locale Functions
  187. ****************************************************************************}
  188. Procedure GetLocalTime(var SystemTime: TSystemTime);
  189. begin
  190. end ;
  191. function SysErrorMessage(ErrorCode: Integer): String;
  192. begin
  193. { Result:=StrError(ErrorCode);}
  194. result := '';
  195. end;
  196. {****************************************************************************
  197. OS utility functions
  198. ****************************************************************************}
  199. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  200. begin
  201. result := '';
  202. end;
  203. Function GetEnvironmentVariableCount : Integer;
  204. begin
  205. result := -1;
  206. end;
  207. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  208. begin
  209. result := '';
  210. end;
  211. function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]): integer;
  212. begin
  213. result := -1;
  214. end;
  215. function ExecuteProcess (const Path: AnsiString;
  216. const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
  217. begin
  218. result := -1;
  219. end;
  220. {****************************************************************************
  221. Initialization code
  222. ****************************************************************************}
  223. Initialization
  224. InitExceptions;
  225. Finalization
  226. DoneExceptions;
  227. end.