unixsysc.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. //- libc funktions
  13. const _MKNOD_VER=2;
  14. Function cFork:longint;cdecl; external name 'fork1'; // fork1 is better here then fork
  15. Procedure cExecve(path:pchar;args:ppchar;ep:ppchar); cdecl; external name 'execve';
  16. Function cWaitPid(Pid:longint;Status:pointer;Options:Longint):Longint; cdecl; external name 'waitpid';
  17. Function cGetTimeOfDay(var tv:timeval;var tz:timezone):integer;cdecl;external name 'gettimeofday';
  18. Function cNice(n:LongInt):LongInt; cdecl; external name 'nice';
  19. Function cGetPid:LongInt;cdecl; external name 'getpid';
  20. Function cGetPPid:LongInt;cdecl; external name 'getppid';
  21. Function cGetUid:Longint;cdecl; external name 'getuid';
  22. Function cGetEUid:Longint;cdecl; external name 'geteuid';
  23. Function cGetGid:Longint;cdecl; external name 'getgid';
  24. Function cGetEGid:Longint;cdecl; external name 'getgid';
  25. Function cSetUid(aUID:longint):longint;cdecl; external name 'setuid';
  26. Function cSetGid(aGID:longint):longint;cdecl; external name 'setuid';
  27. function cSetreUid(aRealUID,aEffUid:Longint):Longint; cdecl; external name 'setreuid';
  28. function cSetreGid(aRealGID,aEffGid:Longint):Longint; cdecl; external name 'setreuid';
  29. Function cfTruncate(fd,size:longint):Longint;cdecl; external name 'ftruncate';
  30. Function cfSync (fd : Longint) : Longint; cdecl; external name 'fsync';
  31. Function cChmod(path:pathstr;Newmode:longint):Longint; cdecl; external name 'chmod';
  32. Function cChown(path:pathstr;NewUid,NewGid:longint):Longint;cdecl; external name 'chown';
  33. Function cUmask(Mask:Longint):Longint;cdecl;external name 'umask';
  34. //Function cFlock (fd,mode : longint) : longint; cdecl; external name 'flock';
  35. Function cDup(oldfile:longint):longint;cdecl;external name 'dup';
  36. Function cDup2(oldfile,newfile:longint):longint;cdecl;external name 'dup2';
  37. Function cGetPriority(Which,Who:LongInt):LongInt;cdecl; external name 'getpriority';
  38. Function cSetPriority(Which:LongInt;Who:LongInt;What:LongInt):LongInt;cdecl; external name 'setpriority';
  39. Function cFcntl(Fd:longint;Cmd:LongInt):LongInt;cdecl;external name 'fcntl';
  40. Function cFcntlArg(Fd:longint;Cmd:LongInt; arg:LongInt):LongInt;cdecl;external name 'fcntl';
  41. Function cAccess(Path:pCHar; mode:LongInt):LongInt; cdecl; external name 'access';
  42. Function cPipe(var pip:tpipe):LongInt; cdecl; external name 'pipe';
  43. Function cUtime(path:pchar; var utim:utimebuf):LongInt; cdecl; external name 'utime';
  44. Function cSelect(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):LongInt;cdecl; external name 'select';
  45. Function cKill(Pid:longint;Sig:longint):LongINt;cdecl; external name 'kill';
  46. Function cIOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; cdecl; external name 'ioctl';
  47. Function cAlarm(Sec : Longint) : longint;cdecl; external name 'alarm';
  48. Function cmknod(Vers:LongInt;pathname:pchar;mode,dev:longint):longint; cdecl; external name '_xmknod';
  49. Function clStat(Vers:LongInt; Filename:pchar;var Buffer: Stat):longint; cdecl; external name '_lxstat';
  50. Function cfStatfs(fd:LongInt; var Info:StatFs):LongInt; cdecl; external name 'fstatvfs';
  51. Function cStatfs(Filename:pchar;var Buffer: StatFs):longint; cdecl; external name 'statvfs';
  52. function cMUnMap(p:pointer;size:longint):integer;cdecl;external name 'munmap';
  53. function cNanoSleep(const req : timespec;var rem : timespec) : longint; cdecl;external name 'nanosleep';
  54. function cPause:longint; cdecl; external name 'pause';
  55. function cSigProcMask(How:longint;SSet,OldSSet:PSigSet):longint; cdecl; external name 'sigprocmask';
  56. function cSigPending(var s:SigSet):integer;cdecl; external name 'sigpending';
  57. function cSigSuspend(s:PSigSet):longint;cdecl;external name 'sigsuspend';
  58. function _cSignal(Signum:longint;Handler:Longint):SignalHandler; cdecl; external name 'signal';
  59. function cSysInfo(cmd:longint; buff:pchar; len:longint):longint; cdecl; external name 'sysinfo';
  60. {$LinkLib rt} // nanosleep
  61. procedure libcerrorfix(fl:boolean); inline;
  62. begin
  63. if fl then
  64. begin
  65. Linuxerror:=libcerrno;
  66. errno:=liberrno;
  67. end
  68. else
  69. begin
  70. Linuxerror:=0;
  71. ErrNo:=0;
  72. end;
  73. end;
  74. Function Fork:longint;
  75. {
  76. This function issues the 'fork' System call. the program is duplicated in memory
  77. and Execution continues in parent and child process.
  78. In the parent process, fork returns the PID of the child. In the child process,
  79. zero is returned.
  80. A negative value indicates that an error has occurred, the error is returned in
  81. LinuxError.
  82. }
  83. var r : LongInt;
  84. begin
  85. r:=cFork; Fork:=r;
  86. libcerrorfix((r=-1));
  87. end;
  88. { Solaris has no clone, there thread funktion (libthread), like thr_create, but they haven't
  89. the same options with flags and return a TID istead of a PID.
  90. If one is interestet he might look to a Hack for lxrun which is contributed as diff.
  91. Allthough the lxrun-hack dos not work at all, it shows what to take care of }
  92. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  93. var pid : Longint;
  94. begin // Quick Hack, never tested, but should work if func does not believe on the Stack
  95. if (pointer(func)=nil) or (sp=nil) then
  96. begin
  97. LinuxError:=Sys_EInval;
  98. Errno:=sys_einval;
  99. exit(-1);
  100. end;
  101. pid:=fork;
  102. if (pid=0) then begin //Child
  103. func(args) ;
  104. ExitProcess(0);
  105. end;
  106. clone:=pid;
  107. end;
  108. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  109. {
  110. Replaces the current program by the program specified in path,
  111. arguments in args are passed to Execve.
  112. environment specified in ep is passed on.
  113. }
  114. begin
  115. cExecve(path,args,ep);
  116. { This only gets set when the call fails, otherwise we don't get here ! }
  117. Linuxerror:=libcerrno;
  118. errno:=libcerrno;
  119. end;
  120. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  121. {
  122. Replaces the current program by the program specified in path,
  123. arguments in args are passed to Execve.
  124. environment specified in ep is passed on.
  125. }
  126. begin
  127. path:=path+#0; cExecve(@path[1],args,ep);
  128. { This only gets set when the call fails, otherwise we don't get here ! }
  129. Linuxerror:=libcerrno;
  130. errno:=libcerrno;
  131. end;
  132. Procedure ExitProcess(val:longint);external name '_exit'; // not 'exit' ('exit' close the shared handle)
  133. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
  134. {
  135. Waits until a child with PID Pid exits, or returns if it is exited already.
  136. Any resources used by the child are freed.
  137. The exit status is reported in the adress referred to by Status. It should
  138. be a longint.
  139. }
  140. begin
  141. WaitPid:=cWaitPid(Pid,Status,Options); { =>PID, -1+errno=eintr: Signal, -1+errno, 0=Ok }
  142. libcerrorfix(WaitPid=-1));
  143. end;
  144. Procedure GetTimeOfDay(var tv:timeval);
  145. {
  146. Get the number of seconds since 00:00, January 1 1970, GMT
  147. the time NOT corrected any way
  148. }
  149. var tz : timezone;
  150. r : Integer;
  151. begin
  152. r:=cGetTimeOfDay(tv,tz);
  153. libcerrorfix (r=-1);
  154. end;
  155. Function GetTimeOfDay: longint;
  156. {
  157. Get the number of seconds since 00:00, January 1 1970, GMT
  158. the time NOT corrected any way
  159. }
  160. var tz : timezone;
  161. tv : timeval;
  162. begin
  163. libcerrorfix(cGetTimeOfDay(tv,tz)=-1);
  164. GetTimeOfDay:=tv.sec;
  165. end;
  166. Function GetPriority(Which,Who:Integer):integer;
  167. {
  168. Get Priority of process, process group, or user.
  169. Which : selects what kind of priority is used.
  170. can be one of the following predefined Constants :
  171. Prio_User.
  172. Prio_PGrp.
  173. Prio_Process.
  174. Who : depending on which, this is , respectively :
  175. Uid
  176. Pid
  177. Process Group id
  178. Errors are reported in linuxerror _only_. (priority can be negative)
  179. }
  180. begin
  181. errno:=0;
  182. if (which<prio_process) or (which>prio_user) then
  183. begin
  184. { We can save an interrupt here }
  185. getpriority:=0;
  186. linuxerror:=Sys_einval;
  187. Errno:=sys_einval;
  188. end
  189. else
  190. begin
  191. GetPriority:=cGetPriority(Which,Who);
  192. libcerrorfix(getpriority=-1);
  193. end;
  194. end;
  195. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  196. {
  197. Set Priority of process, process group, or user.
  198. Which : selects what kind of priority is used.
  199. can be one of the following predefined Constants :
  200. Prio_User.
  201. Prio_PGrp.
  202. Prio_Process.
  203. Who : depending on value of which, this is, respectively :
  204. Uid
  205. Pid
  206. Process Group id
  207. what : A number between -20 and 20. -20 is most favorable, 20 least.
  208. 0 is the default.
  209. }
  210. var r : Integer;
  211. begin
  212. errno:=0;
  213. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  214. begin
  215. linuxerror:=Sys_einval { We can save an interrupt here }
  216. errno:=libcerrno;
  217. end
  218. else
  219. begin
  220. r:=cSetPriority(Which,Who,What);
  221. libcerrorfix(r=-1);
  222. end;
  223. end;
  224. Procedure Nice(N:integer);
  225. {
  226. Set process priority. A positive N means a lower priority.
  227. A negative N decreases priority.
  228. }
  229. begin
  230. libcerrorfix(cNice(n)=-1);
  231. end;
  232. Function GetPid:LongInt;
  233. {
  234. Get Process ID.
  235. }
  236. begin
  237. GetPid:=cGetPid;
  238. libcerrorfix(GetPID=-1);
  239. end;
  240. Function GetPPid:LongInt;
  241. {
  242. Get Process ID of parent process.
  243. }
  244. begin
  245. GetPPid:=cGetPPid;
  246. libcerrorfix(GetPPID=-1);
  247. end;
  248. Function GetUid:Longint;
  249. {
  250. Get User ID.
  251. }
  252. begin
  253. GetUid:=cGetUid;
  254. libcerrorfix (GetUid=-1);
  255. end;
  256. Function GetEUid:Longint;
  257. {
  258. Get _effective_ User ID.
  259. }
  260. begin
  261. GetEUid:=cGetEUid;
  262. libcerrorfix(GetEUid=-1);
  263. end;
  264. Function GetGid:Longint;
  265. {
  266. Get Group ID.
  267. }
  268. begin
  269. GetGid:=cGetGid;
  270. libcerrorfix(GetGid=-1);
  271. end;
  272. Function GetEGid:Longint;
  273. {
  274. Get _effective_ Group ID.
  275. }
  276. begin
  277. GetEGid:=cGetEGid;
  278. libcerrorfix (GetEGid=-1);
  279. end;
  280. // Set the real userid/groupid (uid/gid from calling process)
  281. function SetUid(aUID:Longint):Boolean;
  282. begin
  283. SetUid:=(cSetUid(aUid)=0);
  284. libcerrorfix( not(SetUid));
  285. end;
  286. function SetGid(aGID:Longint):Boolean;
  287. begin
  288. SetGid:=(cSetGid(aGid)=0);
  289. libcerrorfix( not(SetGid));
  290. end;
  291. // Set the real and effective userid/groupid (like setuid/setgid bit in file permissions)
  292. function SetreUid(aRealUID,aEffUid:Longint):Boolean;
  293. begin
  294. SetreUid:=(cSetreUid(aRealUID,aEffUID)=0);
  295. libcerrorfix( not(SetreUid));
  296. end;
  297. function SetreUid(aUID:Longint):Boolean;
  298. begin
  299. SetreUid:=SetreUid(aUID,aUID);
  300. end;
  301. function SetreGid(aRealGid,aEffGid:Longint):Boolean; overload;
  302. begin
  303. SetreGid:=(cSetreUid(aRealGID,aEffGID)=0);
  304. libcerrorfix(not(SetreGid));
  305. end;
  306. function SetreGid(aGid:Longint):Boolean;overload;
  307. begin
  308. SetreGid:=SetreGid(aGID,aGID);
  309. end;
  310. Function fdTruncate(fd,size:longint):boolean;
  311. begin
  312. fdTruncate:=cfTruncate(fd,size)<>-1;
  313. libcerrorfix(not fdTruncate);
  314. end;
  315. Function fdFlush (fd : Longint) : Boolean;
  316. begin
  317. fdFlush:=cfSync(fd)<>-1;
  318. libcerrorfix( not fdFlush);
  319. end;
  320. Function Fcntl(Fd:longint;Cmd:integer):integer;
  321. {
  322. Read or manipulate a file.(See also fcntl (2) )
  323. Possible values for Cmd are :
  324. F_GetFd,F_GetFl,F_GetOwn F_DUPFd, F_Dup2FD...
  325. Errors are reported in Linuxerror;
  326. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  327. }
  328. begin
  329. // the retun is not compatible to the linux-definition (returning 0 on -1 (err)), but 0 may be a valid return
  330. if (cmd in [F_GetFd,F_GetFl,F_GetOwn, {solaris:} F_DupFd]) then
  331. begin
  332. Fcntl:=cFcntl(fd,Cmd);
  333. libcerrorfix(Fcntl=-1);
  334. end
  335. else
  336. begin
  337. linuxerror:=Sys_einval;
  338. Errno:=sys_einval;
  339. Fcntl:=-1;
  340. end;
  341. end;
  342. Procedure Fcntl(Fd:longint;Cmd:Integer;Arg:Longint);
  343. {
  344. Read or manipulate a file. (See also fcntl (2) )
  345. Possible values for Cmd are :
  346. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  347. Errors are reported in Linuxerror;
  348. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  349. F_DupFD is not allowed, due to the structure of Files in Pascal.
  350. }
  351. begin
  352. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn {Solaris:} ,F_Dup2Fd,F_FreeSp{,F_GetLk64,F_SetLk64,F_SetLkw64}]) then
  353. begin
  354. libcerrorfix( cFcntlArg(fd,Cmd,Arg)=-1);
  355. end
  356. else begin
  357. linuxerror:=Sys_einval;
  358. errno:=sys_einval;
  359. end;
  360. end;
  361. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  362. {
  363. Changes the permissions of a file.
  364. }
  365. begin
  366. Chmod:=cChmod(path,NewMode)=0;
  367. libcerrorfix( not Chmod);
  368. end;
  369. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  370. {
  371. Change the owner and group of a file.
  372. A user can only change the group to a group of which he is a member.
  373. The super-user can change uid and gid of any file.
  374. }
  375. begin
  376. Chown:=cChown(path,NewUid,NewGid)=0;
  377. libcerrorfix(not Chown);
  378. end;
  379. Function Utime(path:pathstr;utim:utimebuf):boolean;
  380. begin
  381. path:=path+#0;
  382. UTime:=cUtime(@Path[1],utim)=0;
  383. libcerrorfix( not UTime);
  384. end;
  385. Function Flock (fd,mode : longint) : boolean;
  386. begin
  387. FLock:=TRUE;
  388. // FLock:=cFLock(fd,mode)=0;
  389. libcerrorfix(not FLock);
  390. end;
  391. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  392. {
  393. Get all information on a file descriptor, and return it in info.
  394. }
  395. begin
  396. FStat:=Sys_fstat(fd,Info)=0;
  397. libcerrorfix( not FStat);
  398. end;
  399. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  400. {
  401. Get all information on a link (the link itself), and return it in info.
  402. }
  403. begin
  404. FileName:=FileName+#0;
  405. LStat:=clstat(STAT_VERS,@FileName[1],Info)=0;
  406. libcerrorfix( not LStat);
  407. end;
  408. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  409. {
  410. Get all information on a fileSystem, and return it in Info.
  411. Path is the name of a file/directory on the fileSystem you wish to
  412. investigate.
  413. }
  414. begin
  415. path:=path+#0;
  416. FSStat:=cstatfs(@path[1],Info)=0;
  417. libcerrorfix(not FSStat);
  418. end;
  419. Function FSStat(Fd:Longint;Var Info:statfs):Boolean;
  420. {
  421. Get all information on a fileSystem, and return it in Info.
  422. Fd is the file descriptor of a file/directory on the fileSystem
  423. you wish to investigate.
  424. }
  425. begin
  426. FSStat:=cfstatfs(fd,Info)=0;
  427. libcerrorfix( not FSStat);
  428. end;
  429. Function Link(OldPath,NewPath:pathstr):boolean;
  430. {
  431. Proceduces a hard link from new to old.
  432. In effect, new will be the same file as old.
  433. }
  434. begin
  435. OldPath:=OldPath+#0; NewPath:=NewPath+#0;
  436. Link:=Sys_SymLink(@OldPath[1],@NewPath[1])<>-1;
  437. libcerrorfix( not Link);
  438. end;
  439. Function Umask(Mask:Integer):integer;
  440. {
  441. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  442. previous value.
  443. }
  444. begin
  445. Umask:=cUmask(Mask);
  446. libcerrorfix (Umask=-1);
  447. end;
  448. Function Access(Path:Pathstr ;mode:integer):boolean;
  449. {
  450. Test users access rights on the specified file.
  451. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  452. R,W,X stand for read,write and Execute access, simultaneously.
  453. F_OK checks whether the test would be allowed on the file.
  454. i.e. It checks the search permissions in all directory components
  455. of the path.
  456. The test is done with the real user-ID, instead of the effective.
  457. If access is denied, or an error occurred, false is returned.
  458. If access is granted, true is returned.
  459. Errors other than no access,are reported in linuxerror.
  460. }
  461. begin
  462. path:=path+#0;
  463. Access:=cAccess(@Path[1],mode)=0;
  464. libcerrorfix( not Access);
  465. end;
  466. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  467. {
  468. Copies the filedescriptor oldfile to newfile
  469. }
  470. begin
  471. NewFile:=cDup(OldFile);
  472. Dup:=(NewFile<>-1);
  473. libcerrorfix( not Dup);
  474. end;
  475. Function Dup2(oldfile,newfile:longint):Boolean;
  476. {
  477. Copies the filedescriptor oldfile to newfile
  478. }
  479. begin
  480. Dup2:=cDup2(OldFile,NewFile)<>-1;
  481. libcerrorfix( not Dup2);
  482. end;
  483. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  484. {
  485. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  486. have changed.
  487. }
  488. Var
  489. SelectArray : Array[1..5] of longint;
  490. begin
  491. Select:=cSelect(N,readfds,writefds,exceptfds,TimeOut);
  492. libcerrorfix( Select=-1);
  493. end;
  494. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  495. {
  496. Sets up a pair of file variables, which act as a pipe. The first one can
  497. be read from, the second one can be written to.
  498. If the operation was unsuccesful, linuxerror is set.
  499. }
  500. var
  501. pip : tpipe;
  502. begin
  503. AssignPipe:=cPipe(pip)=0;
  504. if AssignPipe then begin
  505. pipe_in:=pip[1];
  506. pipe_out:=pip[2];
  507. LinuxError:=0;
  508. Errno:=0;
  509. end
  510. else
  511. begin
  512. LinuxError:=libcErrNo;
  513. Errno:=libcerrno;
  514. end;
  515. end;
  516. Function PClose(Var F:text) :longint;
  517. var
  518. pl : ^longint;
  519. begin
  520. Sys_Close(Textrec(F).Handle);
  521. { closed our side, Now wait for the other - this appears to be needed ?? }
  522. pl:=@(textrec(f).userdata[2]);
  523. pclose:=WaitProcess(pl^);
  524. end;
  525. Function PClose(Var F:file) : longint;
  526. var
  527. pl : ^longint;
  528. begin
  529. Sys_Close(Filerec(F).Handle);
  530. { closed our side, Now wait for the other - this appears to be needed ?? }
  531. pl:=@(filerec(f).userdata[2]);
  532. pclose:=WaitProcess(pl^);
  533. end;
  534. Function Sysinfo(var Info:TSysinfo):Boolean; // ToDO
  535. {
  536. Get system info
  537. (Mvdv:Linux specific, not implemented under FreeBSD too.
  538. Under FreeBSD I will simply implement a sysctl unit)
  539. }
  540. var
  541. regs : SysCallregs;
  542. Begin
  543. (* regs.reg2:=longint(@info);
  544. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;*)
  545. WriteLN('SysInfo not supported yet ');
  546. End;
  547. Function mkFifo(pathname:string;mode:longint):boolean;
  548. begin
  549. pathname:=pathname+#0;
  550. mode:=mode or STAT_IFIFO;
  551. mkFifo:=cmknod(_MKNOD_VER,@pathname[1],mode,0)=0;
  552. libcerrorfix(not mkFifo);
  553. end;
  554. {
  555. Function Uname(var unamerec:utsname):Boolean; // ToDo
  556. {
  557. Get machine's names
  558. }
  559. var
  560. regs : SysCallregs;
  561. Begin
  562. Errno:=0;
  563. cSysInfo(SI_SYSNAME,@unamerec.sysname,SizeOf(unamerec.sysname));
  564. cSysInfo(SI_HOSTNAME,@unamerec.nodename,SizeOf(unamerec.nodename));
  565. cSysInfo(SI_RELEASE,@unamerec.release,SizeOf(unamerec.release));
  566. cSysInfo(SI_VERSION,@unamerec.version,SizeOf(unamerec.version));
  567. cSysInfo(SI_MACHINE,@unamerec.machine,SizeOf(unamerec.machine));
  568. cSysInfo(SI_SRPC_DOMAIN,@unamerec.domainname,SizeOf(unamerec.domainname));
  569. LinuxError:=Errno;
  570. End;
  571. }
  572. Function Kill(Pid:longint;Sig:longint):integer;
  573. {
  574. Send signal 'sig' to a process, or a group of processes.
  575. If Pid > 0 then the signal is sent to pid
  576. pid=-1 to all processes except process 1
  577. pid < -1 to process group -pid
  578. Return value is zero, except for case three, where the return value
  579. is the number of processes to which the signal was sent.
  580. }
  581. begin
  582. Kill:=cKill(PID,Sig);
  583. libcerrorfix( Kill=-1);
  584. if kill<0 then Kill:=0; // from the linux source
  585. end;
  586. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet); //ToDo
  587. {
  588. Change the list of currently blocked signals.
  589. How determines which signals will be blocked :
  590. SigBlock : Add SSet to the current list of blocked signals
  591. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  592. SigSetMask : Set the list of blocked signals to SSet
  593. if OldSSet is non-null, the old set will be saved there.
  594. }
  595. begin
  596. libcerrorfix( cSigProcMask(How,SSet,OldSSet)=0);
  597. end;
  598. Function SigPending:SigSet;
  599. {
  600. Allows examination of pending signals. The signal mask of pending
  601. signals is set in SSet
  602. }
  603. Var
  604. dummy : Sigset;
  605. begin
  606. libcerrorfix(cSigPending(dummy)=0);
  607. Sigpending:=dummy;
  608. end;
  609. Procedure SigSuspend(Mask:Sigset); // ToDo
  610. {
  611. Set the signal mask with Mask, and suspend the program until a signal
  612. is received.
  613. }
  614. begin
  615. libcerrorfix (cSigSuspend(@Mask)=0);
  616. end;
  617. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  618. {
  619. Install a new handler for signal Signum.
  620. The old signal handler is returned.
  621. This call does, in fact, the same as SigAction.
  622. }
  623. var
  624. r :LongInt;
  625. begin
  626. Signal:=NIL;
  627. r:=longint(_cSignal(Signum,longint(Handler)));
  628. if (r=-1) then begin
  629. Signal:=nil;
  630. LinuxError:=libcerrno;
  631. Errno:=libcerrno;
  632. end
  633. else
  634. begin
  635. Signal:=signalhandler(r);
  636. LinuxError:=0;
  637. ErrNo:=0;
  638. end;
  639. exit;
  640. end;
  641. Function Alarm(Sec : Longint) : longint;
  642. begin
  643. Alarm:=cAlarm(Sec);
  644. LinuxError:=0; // no error
  645. Errno:=0;
  646. end;
  647. Procedure Pause;
  648. begin cPause;end;
  649. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  650. begin
  651. NanoSleep:=cNanoSleep(req,rem);
  652. Libcerrorfix( NanoSleep=-1);
  653. end;
  654. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  655. {
  656. Interface to Unix ioctl call.
  657. Performs various operations on the filedescriptor Handle.
  658. Ndx describes the operation to perform.
  659. Data points to data needed for the Ndx function. The structure of this
  660. data is function-dependent.
  661. }
  662. begin
  663. IOCtl:=cIOCtl(Handle,Ndx,Data)<>-1;
  664. libcerrorfix( not IOCtl);
  665. end;
  666. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  667. begin
  668. MUnMap:=cMUnMap(p,size)=0;
  669. libcerrorfix( not MUnMap);
  670. end;
  671. {--------------------------------
  672. Port IO functions
  673. --------------------------------}
  674. {
  675. // all of them has to be checked for soalris
  676. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  677. {
  678. Set permissions on NUM ports starting with port FROM to VALUE
  679. this works ONLY as root.
  680. }
  681. Var
  682. Sr : Syscallregs;
  683. begin
  684. (* Sr.Reg2:=From;
  685. Sr.Reg3:=Num;
  686. Sr.Reg4:=Value;
  687. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  688. LinuxError:=Errno;*)
  689. WriteLN('IOperm not suppoted yet');
  690. end;
  691. Function IoPL(Level : longint) : Boolean;
  692. Var
  693. Sr : Syscallregs;
  694. begin
  695. (* Sr.Reg2:=Level;
  696. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  697. LinuxError:=Errno;*)
  698. WriteLN('IoPL not suppoted yet');
  699. end;
  700. {
  701. $Log$
  702. Revision 1.3 2002-09-07 16:01:26 peter
  703. * old logs removed and tabs fixed
  704. }