ossysc.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. {
  2. Copyright (c) 2002 by Marco van de Voort
  3. The base *BSD syscalls required to implement the system unit. These
  4. are aliased for use in other units (to avoid poluting the system units
  5. interface)
  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. }
  13. function Fptime( tloc:ptime): time_t; [public, alias : 'FPC_SYSC_TIME'];
  14. VAR tv : timeval;
  15. tz : timezone;
  16. retval : longint;
  17. begin
  18. Retval:=do_syscall(syscall_nr_gettimeofday,TSysParam(@tv),TSysParam(@tz));
  19. If retval=-1 then
  20. Fptime:=-1
  21. else
  22. Begin
  23. If Assigned(tloc) Then
  24. TLoc^:=tv.tv_sec;
  25. Fptime:=tv.tv_sec;
  26. End;
  27. End;
  28. {*****************************************************************************
  29. --- File:File handling related calls ---
  30. *****************************************************************************}
  31. function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
  32. Begin
  33. Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags),TSysParam(mode));
  34. End;
  35. function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
  36. begin
  37. Fpclose:=do_syscall(syscall_nr_close,fd);
  38. end;
  39. {$ifdef netbsd}
  40. {$ifdef cpupowerpc}
  41. {$define netbsdmacppc}
  42. {$endif}
  43. {$endif}
  44. {$ifdef netbsdmacppc}
  45. {$i sysofft.inc} // odd ball calling convention.
  46. {$else}
  47. // generic versions.
  48. function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
  49. {
  50. this one is special for the return value being 64-bit..
  51. hi/lo offset not yet tested.
  52. NetBSD: ok, but implicit return value in edx:eax
  53. FreeBSD: same implementation as NetBSD.
  54. }
  55. begin
  56. {$ifdef CPU64}
  57. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,TSysParam(fd),0,Offset,whence);
  58. {$else}
  59. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),0,lo(Offset),{0} hi(offset),Whence);
  60. {$endif}
  61. end;
  62. function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
  63. begin
  64. {$ifdef CPU64}
  65. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate, fd ,0 ,flength);
  66. {$else}
  67. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
  68. {$endif}
  69. end;
  70. Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; [public, alias: 'FPC_SYSC_MMAP'];
  71. begin
  72. {$ifdef CPU64}
  73. Fpmmap:=pointer(ptruint(do_syscall(TSysParam(syscall_nr_mmap),TSysParam(Start),TSysParam(Len),TSysParam(Prot),TSysParam(Flags),TSysParam(fd),0,TSysParam(offst))));
  74. {$else}
  75. Fpmmap:=pointer(ptruint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,0,
  76. {$ifdef FPC_BIG_ENDIAN} hi(offst),lo(offst){$endif}
  77. {$ifdef FPC_LITTLE_ENDIAN} lo(offst),hi(offst){$endif}
  78. )));
  79. {$endif}
  80. end;
  81. {$endif}
  82. function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
  83. begin
  84. Fpread:=do_syscall(syscall_nr_read,Fd,TSysParam(buf),nbytes);
  85. end;
  86. function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
  87. begin
  88. Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
  89. end;
  90. function Fpunlink(const path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
  91. begin
  92. Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
  93. end;
  94. function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
  95. begin
  96. Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
  97. end;
  98. function Fpstat(const path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
  99. begin
  100. Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
  101. end;
  102. {*****************************************************************************
  103. --- Directory:Directory related calls ---
  104. *****************************************************************************}
  105. function Fpchdir(path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
  106. begin
  107. Fpchdir:=do_syscall(syscall_nr_chdir,TSysParam(path));
  108. end;
  109. function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
  110. begin {Mode is 16-bit on F-BSD 4!}
  111. Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),mode);
  112. end;
  113. function Fprmdir(path : pchar): cint; [public, alias : 'FPC_SYSC_RMDIR'];
  114. begin
  115. Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
  116. end;
  117. {$ifndef NewReaddir}
  118. const DIRBLKSIZ=1024;
  119. function Fpopendir(dirname : pchar): pdir; [public, alias : 'FPC_SYSC_OPENDIR'];
  120. var
  121. fd:longint;
  122. st:stat;
  123. ptr:pdir;
  124. begin
  125. Fpopendir:=nil;
  126. if Fpstat(dirname,st)<0 then
  127. exit;
  128. { Is it a dir ? }
  129. if not((st.st_mode and $f000)=$4000)then
  130. begin
  131. errno:=ESysENOTDIR;
  132. exit
  133. end;
  134. { Open it}
  135. fd:=Fpopen(dirname,O_RDONLY,438);
  136. if fd<0 then
  137. Begin
  138. Errno:=-1;
  139. exit;
  140. End;
  141. new(ptr);
  142. if ptr=nil then
  143. Begin
  144. Errno:=1;
  145. exit;
  146. End;
  147. Getmem(ptr^.dd_buf,2*DIRBLKSIZ);
  148. if ptr^.dd_buf=nil then
  149. exit;
  150. ptr^.dd_fd:=fd;
  151. ptr^.dd_loc:=-1;
  152. ptr^.dd_rewind:=ptrint(ptr^.dd_buf);
  153. ptr^.dd_size:=0;
  154. // ptr^.dd_max:=sizeof(ptr^.dd_buf^);
  155. Fpopendir:=ptr;
  156. end;
  157. function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
  158. begin
  159. Fpclosedir:=Fpclose(dirp^.dd_fd);
  160. Freemem(dirp^.dd_buf);
  161. dispose(dirp);
  162. end;
  163. var
  164. use_openbsd_getdirentries_49 : boolean = false;
  165. use_getdirentries_syscall : boolean = true;
  166. function Fpreaddir(dirp : pdir) : pdirent; [public, alias : 'FPC_SYSC_READDIR'];
  167. {Different from Linux, Readdir on BSD is based on Getdents, due to the
  168. missing of the readdir syscall.
  169. Getdents requires the buffer to be larger than the blocksize.
  170. This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
  171. with blockmode have this higher?}
  172. function readbuffer:longint;
  173. var retval :longint;
  174. {$ifdef FPC_USE_GETDIRENTRIES_SYSCALL}
  175. basepp : pointer;
  176. {$ifdef FPC_USE_GETDIRENTRIES_I49_SYSCALL}
  177. { OpenBSD i49 getDirEntries system call uses off_t type for last parameter }
  178. basep_off_t : off_t;
  179. {$endif not FPC_USE_GETDIRENTRIES_I49_SYSCALL}
  180. basep : clong;
  181. {$endif FPC_USE_GETDIRENTRIES_SYSCALL}
  182. begin
  183. {$ifdef FPC_USE_GETDIRENTRIES_SYSCALL}
  184. {$ifdef FPC_USE_GETDIRENTRIES_I49_SYSCALL}
  185. if use_openbsd_getdirentries_49 then
  186. basepp:=@basep_off_t
  187. else
  188. {$endif FPC_USE_GETDIRENTRIES_I49_SYSCALL}
  189. basepp:=@basep;
  190. if use_getdirentries_syscall then
  191. Retval:=do_syscall(syscall_nr_getdirentries,TSysParam(dirp^.dd_fd),TSysParam(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)},TSysParam(basepp))
  192. else
  193. Retval:=do_syscall(syscall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
  194. {$else not FPC_USE_GETDIRENTRIES_SYSCALL}
  195. Retval:=do_syscall(syscall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
  196. {$endif not FPC_USE_GETDIRENTRIES_SYSCALL}
  197. dirp^.dd_rewind:=TSysParam(dirp^.dd_buf);
  198. if retval=0 then
  199. begin
  200. dirp^.dd_rewind:=0;
  201. dirp^.dd_loc:=0;
  202. end
  203. else
  204. dirP^.dd_loc:=retval;
  205. dirP^.dd_size:=retval;
  206. readbuffer:=retval;
  207. end;
  208. var
  209. FinalEntry : pdirent;
  210. novalid : boolean;
  211. Reclen : Longint;
  212. CurEntry : PDirent;
  213. begin
  214. if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
  215. exit(nil);
  216. if (dirp^.dd_loc=-1) OR {First readdir on this pdir. Initial fill of buffer}
  217. (dirp^.dd_rewind>=(ptrint(dirp^.dd_buf)+dirp^.dd_size)) then {no more entries left?}
  218. Begin
  219. if readbuffer=0 then {succesful read?}
  220. Exit(NIL); {No more data}
  221. End;
  222. FinalEntry:=NIL;
  223. CurEntry:=nil;
  224. repeat
  225. novalid:=false;
  226. CurEntry:=pdirent(dirp^.dd_rewind);
  227. {$ifdef dragonfly}
  228. RecLen:=(CurEntry^.d_namlen + 24) and $FFFFFFF8;
  229. {$else}
  230. RecLen:=CurEntry^.d_reclen;
  231. {$endif}
  232. if RecLen<>0 Then
  233. begin {valid direntry?}
  234. if CurEntry^.d_fileno<>0 then
  235. FinalEntry:=CurEntry;
  236. inc(dirp^.dd_rewind,Reclen);
  237. end
  238. else
  239. begin {block entirely searched or reclen=0}
  240. Novalid:=True;
  241. if dirp^.dd_loc<>0 THEN {blocks left?}
  242. if readbuffer()<>0 then {succesful read?}
  243. novalid:=false;
  244. end;
  245. until (FinalEntry<>nil) or novalid;
  246. If novalid then
  247. FinalEntry:=nil;
  248. FpReadDir:=FinalEntry;
  249. end;
  250. {$endif}
  251. {*****************************************************************************
  252. --- Process:Process & program handling - related calls ---
  253. *****************************************************************************}
  254. procedure Fpexit(status : cint); [public, alias : 'FPC_SYSC_EXIT'];
  255. begin
  256. do_syscall(syscall_nr_exit,status);
  257. end;
  258. {
  259. Change action of process upon receipt of a signal.
  260. Signum specifies the signal (all except SigKill and SigStop).
  261. If Act is non-nil, it is used to specify the new action.
  262. If OldAct is non-nil the previous action is saved there.
  263. }
  264. {$ifdef USE_SIGACTION_SIGTRAMP}
  265. procedure signal_trampoline; cdecl; forward;
  266. {$endif def USE_SIGACTION_SIGTRAMP}
  267. function Fpsigaction(sig: cint; act, oact: psigactionrec): cint; [public, alias : 'FPC_SYSC_SIGACTION'];
  268. {
  269. Change action of process upon receipt of a signal.
  270. Signum specifies the signal (all except SigKill and SigStop).
  271. If Act is non-nil, it is used to specify the new action.
  272. If OldAct is non-nil the previous action is saved there.
  273. }
  274. begin
  275. {$ifdef USE_SIGACTION_SIGTRAMP}
  276. fpsigaction:=do_syscall(syscall_nr___sigaction_sigtramp,TSysParam(sig),TSysParam(act),TSysParam(oact),
  277. TSysParam(@signal_trampoline),2);
  278. {$else not USE_SIGACTION_SIGTRAMP}
  279. fpsigaction:=do_syscall(syscall_nr_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact));
  280. {$endif not USE_SIGACTION_SIGTRAMP}
  281. end;
  282. (*=================== MOVED from sysunix.inc ========================*)
  283. function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
  284. begin
  285. fpFStat:=do_SysCall(syscall_nr_fstat,fd,TSysParam(@sb));
  286. end;
  287. {$ifdef NewReaddir}
  288. {$I readdir.inc}
  289. {$endif}
  290. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];
  291. {
  292. This function issues the 'fork' System call. the program is duplicated in memory
  293. and Execution continues in parent and child process.
  294. In the parent process, fork returns the PID of the child. In the child process,
  295. zero is returned.
  296. A negative value indicates that an error has occurred, the error is returned in
  297. LinuxError.
  298. }
  299. Begin
  300. Fpfork:=Do_syscall(SysCall_nr_fork);
  301. End;
  302. {
  303. function Fpexecve(const path : pathstr; const argv : ppchar; const envp: ppchar): cint;
  304. }
  305. {
  306. Replaces the current program by the program specified in path,
  307. arguments in args are passed to Execve.
  308. environment specified in ep is passed on.
  309. }
  310. {
  311. Begin
  312. path:=path+#0;
  313. do_syscall(syscall_nr_Execve,TSysParam(@path[1]),TSysParam(Argv),TSysParam(envp));
  314. End;
  315. }
  316. {
  317. function Fpexecve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; [public, alias : 'FPC_SYSC_EXECVE'];
  318. }
  319. {
  320. Replaces the current program by the program specified in path,
  321. arguments in args are passed to Execve.
  322. environment specified in ep is passed on.
  323. }
  324. {
  325. Begin
  326. do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
  327. End;
  328. }
  329. function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
  330. {
  331. Waits until a child with PID Pid exits, or returns if it is exited already.
  332. Any resources used by the child are freed.
  333. The exit status is reported in the adress referred to by Status. It should
  334. be a longint.
  335. }
  336. begin // actually a wait4() call with 4th arg 0.
  337. FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options,0);
  338. end;
  339. function Fpaccess(const pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
  340. {
  341. Test users access rights on the specified file.
  342. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  343. R,W,X stand for read,write and Execute access, simultaneously.
  344. F_OK checks whether the test would be allowed on the file.
  345. i.e. It checks the search permissions in all directory components
  346. of the path.
  347. The test is done with the real user-ID, instead of the effective.
  348. If access is denied, or an error occurred, false is returned.
  349. If access is granted, true is returned.
  350. Errors other than no access,are reported in unixerror.
  351. }
  352. begin
  353. FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
  354. end;
  355. (*
  356. function Fpaccess(const pathname : pathstr; amode : cint): cint;
  357. {
  358. Test users access rights on the specified file.
  359. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  360. R,W,X stand for read,write and Execute access, simultaneously.
  361. F_OK checks whether the test would be allowed on the file.
  362. i.e. It checks the search permissions in all directory components
  363. of the path.
  364. The test is done with the real user-ID, instead of the effective.
  365. If access is denied, or an error occurred, false is returned.
  366. If access is granted, true is returned.
  367. Errors other than no access,are reported in unixerror.
  368. }
  369. begin
  370. pathname:=pathname+#0;
  371. Access:=do_syscall(syscall_nr_access, TSysParam(@pathname[1]),mode)=0;
  372. end;
  373. *)
  374. Function FpDup(fildes:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
  375. begin
  376. Fpdup:=Do_syscall(syscall_nr_dup,TSysParam(fildes));
  377. end;
  378. Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
  379. begin
  380. Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
  381. end;
  382. Function Fpmunmap(start:pointer;len:size_t):cint; [public, alias :'FPC_SYSC_MUNMAP'];
  383. begin
  384. Fpmunmap:=do_syscall(syscall_nr_munmap,TSysParam(start),Len);
  385. end;
  386. {
  387. Interface to Unix ioctl call.
  388. Performs various operations on the filedescriptor Handle.
  389. Ndx describes the operation to perform.
  390. Data points to data needed for the Ndx function. The structure of this
  391. data is function-dependent.
  392. }
  393. Function FpIOCtl(Handle:cint;Ndx: TIOCtlRequest;Data: Pointer):cint; [public, alias : 'FPC_SYSC_IOCTL'];
  394. // This was missing here, instead hardcoded in Do_IsDevice
  395. begin
  396. FpIOCtl:=do_SysCall(syscall_nr_ioctl,handle,Ndx,TSysParam(data));
  397. end;
  398. Function FpGetPid:LongInt; [public, alias : 'FPC_SYSC_GETPID'];
  399. {
  400. Get Process ID.
  401. }
  402. begin
  403. FpGetPID:=do_syscall(syscall_nr_getpid);
  404. end;
  405. function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; [public, alias: 'FPC_SYSC_GETTIMEOFDAY'];
  406. begin
  407. fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp));
  408. end;
  409. function FPSigProcMask(how:cint;nset : psigset;oset : psigset):cint; [public, alias : 'FPC_SYSC_SIGPROCMASK'];
  410. {
  411. Change the list of currently blocked signals.
  412. How determines which signals will be blocked :
  413. SigBlock : Add SSet to the current list of blocked signals
  414. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  415. SigSetMask : Set the list of blocked signals to SSet
  416. if OldSSet is non-null, the old set will be saved there.
  417. }
  418. {$ifdef OpenBSD}
  419. { OpenBSD sigprocmask signal uses
  420. sigset_t that are cint type
  421. the value of nset^[0] must be passed as second parameter
  422. the old mask value is in return value }
  423. { How do we know if the call failed... PM }
  424. {$define OS_SIGPROCMASK_RETURNS_OVAL}
  425. {$endif}
  426. {$ifdef OS_SIGPROCMASK_RETURNS_OVAL}
  427. var
  428. res : cint;
  429. {$endif OS_SIGPROCMASK_RETURNS_OVAL}
  430. begin
  431. {$ifdef OS_SIGPROCMASK_RETURNS_OVAL}
  432. res:=do_syscall(syscall_nr_sigprocmask,tsysparam(how),TSysParam(nset^[0]));
  433. if assigned(oset) then
  434. oset^[0]:=res;
  435. FPsigprocmask:=0;
  436. {$else OS_SIGPROCMASK_RETURNS_OVAL}
  437. FPsigprocmask:=do_syscall(syscall_nr_sigprocmask,tsysparam(how),TSysParam(nset),TSysParam(oset));
  438. {$endif OS_SIGPROCMASK_RETURNS_OVAL}
  439. end;
  440. {$warning user BLA!}
  441. Function FpNanoSleep(req : ptimespec;rem : ptimespec) : cint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
  442. begin
  443. FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
  444. end;
  445. function Fpgetcwd(pt:pchar; _size:size_t):pchar;[public, alias :'FPC_SYSC_GETCWD'];
  446. const intpathmax = 1024-4; // didn't use POSIX data in libc
  447. // implementation.
  448. var ept,bpt : pchar;
  449. c : char;
  450. ret : cint;
  451. begin
  452. if pt=NIL Then
  453. begin
  454. // POSIX: undefined. (exit(nil) ?)
  455. // BSD : allocate mem for path.
  456. getmem(pt,intpathmax);
  457. if pt=nil Then
  458. exit(nil);
  459. ept:=pt+intpathmax;
  460. end
  461. else
  462. Begin
  463. if (_size=0) Then
  464. Begin
  465. seterrno(ESysEINVAL);
  466. exit(nil);
  467. End;
  468. if (_size=1) Then
  469. Begin
  470. seterrno(ESysERANGE);
  471. exit(nil);
  472. End;
  473. ept:=pt+_size;
  474. end;
  475. ret := do_syscall(syscall_nr___getcwd,TSysParam(pt),TSysParam( ept - pt));
  476. If (ret = 0) Then
  477. begin
  478. If (pt[0] <> '/') Then
  479. Begin
  480. bpt := pt;
  481. ept := pt + strlen(pt) - 1;
  482. While (bpt < ept) Do
  483. Begin
  484. c := bpt^;
  485. bpt^:=ept^;
  486. inc(bpt);
  487. ept^:=c;
  488. dec(ept);
  489. End;
  490. End
  491. end
  492. {$if defined(openbsd) or defined (netbsd)}
  493. { At least for openbsd, a positive return value is
  494. the length of the returned pchar }
  495. else if (ret<0) then
  496. {$else not opensd}
  497. else
  498. {$endif openbsd}
  499. begin
  500. seterrno(-ret);
  501. pt:=nil;
  502. end;
  503. Fpgetcwd:=pt;
  504. end;
  505. Function fpReadLink(name,linkname:pchar;maxlen:size_t):cint; [public, alias : 'FPC_SYSC_READLINK'];
  506. begin
  507. fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
  508. end;
  509. function FpGetRLimit(resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_GETRLIMIT'];
  510. begin
  511. fpgetrlimit:=do_syscall(syscall_nr_getrlimit,TSysParam(Resource),TSysParam(rlim));
  512. end;
  513. function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
  514. begin
  515. fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
  516. end;