sysutils.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Sysutils unit for netware
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {currently nothing is implemented !}
  14. unit sysutils;
  15. interface
  16. {$MODE objfpc}
  17. { force ansistrings }
  18. {$H+}
  19. uses DOS;
  20. // Unix,errors;
  21. {$I nwsys.inc}
  22. {$I errno.inc}
  23. { Include platform independent interface part }
  24. {$i sysutilh.inc}
  25. implementation
  26. { Include platform independent implementation part }
  27. {$i sysutils.inc}
  28. {****************************************************************************
  29. File Functions
  30. ****************************************************************************}
  31. Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
  32. Var LinuxFlags : longint;
  33. BEGIN
  34. {LinuxFlags:=0;
  35. Case (Mode and 3) of
  36. 0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
  37. 1 : LinuxFlags:=LinuxFlags or Open_WrOnly;
  38. 2 : LinuxFlags:=LinuxFlags or Open_RdWr;
  39. end;
  40. FileOpen:=fdOpen (FileName,LinuxFlags);
  41. }
  42. //!! We need to set locking based on Mode !!
  43. end;
  44. Function FileCreate (Const FileName : String) : Longint;
  45. begin
  46. //FileCreate:=fdOpen(FileName,Open_RdWr or Open_Creat or Open_Trunc);
  47. end;
  48. Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
  49. begin
  50. //FileRead:=fdRead (Handle,Buffer,Count);
  51. end;
  52. Function FileWrite (Handle : Longint; const Buffer; Count : Longint) : Longint;
  53. begin
  54. //FileWrite:=fdWrite (Handle,Buffer,Count);
  55. end;
  56. Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;
  57. begin
  58. //FileSeek:=fdSeek (Handle,FOffset,Origin);
  59. end;
  60. Procedure FileClose (Handle : Longint);
  61. begin
  62. //fdclose(Handle);
  63. end;
  64. Function FileTruncate (Handle,Size: Longint) : boolean;
  65. begin
  66. //FileTruncate:=fdtruncate(Handle,Size);
  67. end;
  68. Function FileAge (Const FileName : String): Longint;
  69. //Var Info : Stat;
  70. // Y,M,D,hh,mm,ss : word;
  71. begin
  72. { If not fstat (FileName,Info) then
  73. exit(-1)
  74. else
  75. begin
  76. EpochToLocal(info.mtime,y,m,d,hh,mm,ss);
  77. Result:=DateTimeToFileDate(EncodeDate(y,m,d)+EncodeTime(hh,mm,ss,0));
  78. end;}
  79. end;
  80. Function FileExists (Const FileName : String) : Boolean;
  81. //Var Info : Stat;
  82. begin
  83. //FileExists:=fstat(filename,Info);
  84. end;
  85. {
  86. Function LinuxToWinAttr (FN : Pchar; Const Info : Stat) : Longint;
  87. begin
  88. Result:=faArchive;
  89. If (Info.Mode and STAT_IFDIR)=STAT_IFDIR then
  90. Result:=Result or faDirectory;
  91. If (FN[0]='.') and (not (FN[1] in [#0,'.'])) then
  92. Result:=Result or faHidden;
  93. If (Info.Mode and STAT_IWUSR)=0 Then
  94. Result:=Result or faReadOnly;
  95. If (Info.Mode and
  96. (STAT_IFSOCK or STAT_IFBLK or STAT_IFCHR or STAT_IFIFO))<>0 then
  97. Result:=Result or faSysFile;
  98. end;
  99. }
  100. {
  101. GlobToSearch takes a glob entry, stats the file.
  102. The glob entry is removed.
  103. If FileAttributes match, the entry is reused
  104. }
  105. {Type
  106. TGlobSearchRec = Record
  107. Path : String;
  108. GlobHandle : PGlob;
  109. end;
  110. PGlobSearchRec = ^TGlobSearchRec;}
  111. {Function GlobToTSearchRec (Var Info : TSearchRec) : Boolean;
  112. Var SInfo : Stat;
  113. p : Pglob;
  114. GlobSearchRec : PGlobSearchrec;
  115. begin
  116. GlobSearchRec:=PGlobSearchrec(Info.FindHandle);
  117. P:=GlobSearchRec^.GlobHandle;
  118. Result:=P<>Nil;
  119. If Result then
  120. begin
  121. GlobSearchRec^.GlobHandle:=P^.Next;
  122. Result:=Fstat(GlobSearchRec^.Path+StrPas(p^.name),SInfo);
  123. If Result then
  124. begin
  125. Info.Attr:=LinuxToWinAttr(p^.name,SInfo);
  126. Result:=(Info.ExcludeAttr and Info.Attr)=0;
  127. If Result Then
  128. With Info do
  129. begin
  130. Attr:=Info.Attr;
  131. If P^.Name<>Nil then
  132. Name:=strpas(p^.name);
  133. Time:=Sinfo.mtime;
  134. Size:=Sinfo.Size;
  135. end;
  136. end;
  137. P^.Next:=Nil;
  138. GlobFree(P);
  139. end;
  140. end;}
  141. Function DoFind(Var Rslt : TSearchRec) : Longint;
  142. //Var GlobSearchRec : PGlobSearchRec;
  143. begin
  144. Result:=-1;
  145. { GlobSearchRec:=PGlobSearchRec(Rslt.FindHandle);
  146. If (GlobSearchRec^.GlobHandle<>Nil) then
  147. While (GlobSearchRec^.GlobHandle<>Nil) and not (Result=0) do
  148. If GlobToTSearchRec(Rslt) Then Result:=0;}
  149. end;
  150. Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  151. //Var GlobSearchRec : PGlobSearchRec;
  152. begin
  153. {New(GlobSearchRec);
  154. GlobSearchRec^.Path:=ExpandFileName(ExtractFilePath(Path));
  155. GlobSearchRec^.GlobHandle:=Glob(Path);
  156. Rslt.ExcludeAttr:=Not Attr; //!! Not correct !!
  157. Rslt.FindHandle:=Longint(GlobSearchRec);
  158. Result:=DoFind (Rslt);}
  159. end;
  160. Function FindNext (Var Rslt : TSearchRec) : Longint;
  161. begin
  162. // Result:=DoFind (Rslt);
  163. end;
  164. Procedure FindClose (Var F : TSearchrec);
  165. //Var GlobSearchRec : PGlobSearchRec;
  166. begin
  167. {GlobSearchRec:=PGlobSearchRec(F.FindHandle);
  168. GlobFree (GlobSearchRec^.GlobHandle);
  169. Dispose(GlobSearchRec);}
  170. end;
  171. Function FileGetDate (Handle : Longint) : Longint;
  172. //Var Info : Stat;
  173. begin
  174. {If Not(FStat(Handle,Info)) then
  175. Result:=-1
  176. else
  177. Result:=Info.Mtime;}
  178. end;
  179. Function FileSetDate (Handle,Age : Longint) : Longint;
  180. begin
  181. // Impossible under Linux from FileHandle !!
  182. FileSetDate:=-1;
  183. end;
  184. Function FileGetAttr (Const FileName : String) : Longint;
  185. //Var Info : Stat;
  186. begin
  187. { If Not FStat (FileName,Info) then
  188. Result:=-1
  189. Else
  190. Result:=LinuxToWinAttr(Pchar(FileName),Info);}
  191. end;
  192. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  193. begin
  194. Result:=-1;
  195. end;
  196. Function DeleteFile (Const FileName : String) : Boolean;
  197. begin
  198. Result:= (_UnLink (pchar(FileName)) = 0);
  199. end;
  200. Function RenameFile (Const OldName, NewName : String) : Boolean;
  201. begin
  202. // RenameFile:=Unix.FRename(OldNAme,NewName);
  203. end;
  204. Function FileSearch (Const Name, DirList : String) : String;
  205. begin
  206. FileSearch:=Dos.FSearch(Name,Dirlist);
  207. end;
  208. {****************************************************************************
  209. Disk Functions
  210. ****************************************************************************}
  211. {
  212. The Diskfree and Disksize functions need a file on the specified drive, since this
  213. is required for the statfs system call.
  214. These filenames are set in drivestr[0..26], and have been preset to :
  215. 0 - '.' (default drive - hence current dir is ok.)
  216. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  217. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  218. 3 - '/' (C: equivalent of dos is the root partition)
  219. 4..26 (can be set by you're own applications)
  220. ! Use AddDisk() to Add new drives !
  221. They both return -1 when a failure occurs.
  222. }
  223. Const
  224. FixDriveStr : array[0..3] of pchar=(
  225. '.',
  226. '/fd0/.',
  227. '/fd1/.',
  228. '/.'
  229. );
  230. var
  231. Drives : byte;
  232. DriveStr : array[4..26] of pchar;
  233. Procedure AddDisk(const path:string);
  234. begin
  235. if not (DriveStr[Drives]=nil) then
  236. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  237. GetMem(DriveStr[Drives],length(Path)+1);
  238. StrPCopy(DriveStr[Drives],path);
  239. inc(Drives);
  240. if Drives>26 then
  241. Drives:=4;
  242. end;
  243. Function DiskFree(Drive: Byte): int64;
  244. //var fs : statfs;
  245. Begin
  246. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  247. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  248. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  249. else
  250. Diskfree:=-1;}
  251. End;
  252. Function DiskSize(Drive: Byte): int64;
  253. //var fs : statfs;
  254. Begin
  255. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  256. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  257. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  258. else
  259. DiskSize:=-1;}
  260. End;
  261. Function GetCurrentDir : String;
  262. begin
  263. GetDir (0,Result);
  264. end;
  265. Function SetCurrentDir (Const NewDir : String) : Boolean;
  266. begin
  267. {$I-}
  268. ChDir(NewDir);
  269. {$I+}
  270. result := (IOResult = 0);
  271. end;
  272. Function CreateDir (Const NewDir : String) : Boolean;
  273. begin
  274. {$I-}
  275. MkDir(NewDir);
  276. {$I+}
  277. result := (IOResult = 0);
  278. end;
  279. Function RemoveDir (Const Dir : String) : Boolean;
  280. begin
  281. {$I-}
  282. RmDir(Dir);
  283. {$I+}
  284. result := (IOResult = 0);
  285. end;
  286. {****************************************************************************
  287. Misc Functions
  288. ****************************************************************************}
  289. procedure Beep;
  290. begin
  291. end;
  292. {****************************************************************************
  293. Locale Functions
  294. ****************************************************************************}
  295. Procedure GetLocalTime(var SystemTime: TSystemTime);
  296. var xx : word;
  297. begin
  298. Dos.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, xx);
  299. Dos.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day, xx);
  300. SystemTime.MilliSecond := 0;
  301. end;
  302. Procedure InitAnsi;
  303. Var i : longint;
  304. begin
  305. { Fill table entries 0 to 127 }
  306. for i := 0 to 96 do
  307. UpperCaseTable[i] := chr(i);
  308. for i := 97 to 122 do
  309. UpperCaseTable[i] := chr(i - 32);
  310. for i := 123 to 191 do
  311. UpperCaseTable[i] := chr(i);
  312. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  313. for i := 0 to 64 do
  314. LowerCaseTable[i] := chr(i);
  315. for i := 65 to 90 do
  316. LowerCaseTable[i] := chr(i + 32);
  317. for i := 91 to 191 do
  318. LowerCaseTable[i] := chr(i);
  319. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  320. end;
  321. Procedure InitInternational;
  322. begin
  323. InitAnsi;
  324. end;
  325. function SysErrorMessage(ErrorCode: Integer): String;
  326. begin
  327. Result:=''; // StrError(ErrorCode);
  328. end;
  329. {****************************************************************************
  330. OS utility functions
  331. ****************************************************************************}
  332. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  333. begin
  334. // Result:=StrPas(Unix.Getenv(PChar(EnvVar)));
  335. end;
  336. {****************************************************************************
  337. Initialization code
  338. ****************************************************************************}
  339. Initialization
  340. InitExceptions; { Initialize exceptions. OS independent }
  341. InitInternational; { Initialize internationalization settings }
  342. Finalization
  343. OutOfMemory.Free;
  344. InValidPointer.Free;
  345. end.
  346. {
  347. $Log$
  348. Revision 1.1 2001-04-11 14:14:12 florian
  349. * initial commit, thanks to Armin Diehl (diehl@nordrhein)
  350. Revision 1.8 2001/02/20 22:19:38 peter
  351. * always test before commiting after merging, linux -> unix change
  352. Revision 1.7 2001/02/20 22:14:19 peter
  353. * merged getenvironmentvariable
  354. Revision 1.6 2001/01/21 20:21:40 marco
  355. * Rename fest II. Rtl OK
  356. Revision 1.5 2000/12/28 20:50:04 peter
  357. * merged fixes from 1.0.x
  358. Revision 1.4 2000/12/18 14:01:42 jonas
  359. * fixed constant range error
  360. Revision 1.3 2000/11/28 20:06:12 michael
  361. + merged fix for findfirst/findnext/findclose
  362. Revision 1.2 2000/09/18 13:14:51 marco
  363. * Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
  364. Revision 1.3 2000/08/29 17:58:13 michael
  365. Merged syserrormsg fix
  366. Revision 1.2 2000/08/20 15:46:46 peter
  367. * sysutils.pp moved to target and merged with disk.inc, filutil.inc
  368. Revision 1.1.2.2 2000/11/28 20:01:22 michael
  369. + Fixed findfirst/findnext/findclose
  370. Revision 1.1.2.1 2000/09/14 13:38:26 marco
  371. * Moved from Linux dir. now start of generic unix dir, from which the
  372. really exotic features should be moved to the target specific dirs.
  373. }