ossysc.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Marco van de Voort
  4. The base *BSD syscalls required to implement the system unit. These
  5. are aliased for use in other units (to avoid poluting the system units
  6. interface)
  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. }
  14. {$i ostypes.inc}
  15. {$ifdef FPC_USE_LIBC}
  16. {$Linklib c}
  17. // Out of date atm.
  18. {$ifdef FPC_IS_SYSTEM}
  19. {$i oscdeclh.inc}
  20. {$endif}
  21. {$I bunxmacr.inc}
  22. { var
  23. Errno : cint; external name 'errno';
  24. function Fptime(tloc:ptime_t): time_t; cdecl; external name 'time';
  25. function Fpopen(const path: pchar; flags : cint; mode: mode_t):cint; cdecl; external name 'open';
  26. function Fpclose(fd : cint): cint; cdecl; external name 'close';
  27. function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; cdecl; external name 'lseek';
  28. function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; cdecl; external name 'read';
  29. function Fpwrite(fd: cint;const buf:pchar; nbytes : size_t): ssize_t; cdecl; external name 'write';
  30. function Fpunlink(const path: pchar): cint; cdecl; external name 'unlink';
  31. function Fprename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
  32. function Fpstat(const path: pchar; var buf : stat): cint; cdecl; external name 'stat';
  33. function Fpchdir(const path : pchar): cint; cdecl; external name 'chdir';
  34. function Fpmkdir(const path : pchar; mode: mode_t):cint; cdecl; external name 'mkdir';
  35. function Fprmdir(const path : pchar): cint; cdecl; external name 'rmdir';
  36. function Fpopendir(const dirname : pchar): pdir; cdecl; external name 'opendir';
  37. function Fpreaddir(var dirp : dir) : pdirent;cdecl; external name 'readdir';
  38. function Fpclosedir(var dirp : dir): cint; cdecl; external name 'closedir';
  39. procedure Fpexit(status : cint); cdecl; external name '_exit';
  40. function Fpsigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint; cdecl; external name 'sigaction';
  41. function Fpftruncate(fd : cint; flength : off_t): cint; cdecl; external name 'ftruncate';
  42. function Fprename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
  43. function Fpfstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
  44. function Fpfork : pid_t; cdecl; external name 'fork';
  45. function Fpexecve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
  46. function Fpwaitpid(pid : pid_t; tat_loc : pcint; options: cint): pid_t; cdecl; external name 'waitpid';
  47. function Fpaccess(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
  48. function Fpuname(var name: utsname): cint; cdecl; external name 'uname';
  49. function FpDup(oldd:cint):cint; cdecl; external name 'dup';
  50. function FpDup2(oldd:cint;newd:cint):cint; cdecl; external name 'dup2';
  51. }
  52. {$else}
  53. {*****************************************************************************
  54. --- Main:The System Call Self ---
  55. *****************************************************************************}
  56. { The system designed for Linux can't be used for *BSD so easily, since
  57. *BSD pushes arguments, instead of loading them to registers.}
  58. // Var ErrNo : Longint;
  59. {$I syscallh.inc}
  60. {$I syscall.inc}
  61. {$I sysnr.inc}
  62. {$I bunxmacr.inc}
  63. // Should be moved to a FreeBSD specific unit in the future.
  64. function Fptime( tloc:ptime): time_t; [public, alias : 'FPC_SYSC_TIME'];
  65. VAR tv : timeval;
  66. tz : timezone;
  67. retval : longint;
  68. begin
  69. Retval:=do_syscall(syscall_nr_gettimeofday,TSysParam(@tv),TSysParam(@tz));
  70. If retval=-1 then
  71. Fptime:=-1
  72. else
  73. Begin
  74. If Assigned(tloc) Then
  75. TLoc^:=tv.tv_sec;
  76. Fptime:=tv.tv_sec;
  77. End;
  78. End;
  79. {*****************************************************************************
  80. --- File:File handling related calls ---
  81. *****************************************************************************}
  82. function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
  83. Begin
  84. Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags),TSysParam(mode));
  85. End;
  86. function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
  87. begin
  88. Fpclose:=do_syscall(syscall_nr_close,fd);
  89. end;
  90. {$ifdef netbsd}
  91. {$ifdef cpupowerpc}
  92. {$define netbsdmacppc}
  93. {$endif}
  94. {$endif}
  95. {$ifdef netbsdmacppc}
  96. {$i sysofft.inc} // odd ball calling convention.
  97. {$else}
  98. // generic versions.
  99. function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
  100. {
  101. this one is special for the return value being 64-bit..
  102. hi/lo offset not yet tested.
  103. NetBSD: ok, but implicit return value in edx:eax
  104. FreeBSD: same implementation as NetBSD.
  105. }
  106. begin
  107. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),0,lo(Offset),{0} hi(offset),Whence);
  108. end;
  109. function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
  110. begin
  111. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
  112. end;
  113. {$ifdef VER1_0}
  114. {$DEFINE FPC_LITTLE_ENDIAN}
  115. {$endif}
  116. Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; [public, alias: 'FPC_SYSC_MMAP'];
  117. begin
  118. Fpmmap:=pointer(longint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,
  119. {$ifdef FPC_BIG_ENDIAN} hi(offst),lo(offst){$endif}
  120. {$ifdef FPC_LITTLE_ENDIAN} lo(offst),hi(offst){$endif}
  121. )));
  122. end;
  123. {$endif}
  124. function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
  125. begin
  126. Fpread:=do_syscall(syscall_nr_read,Fd,TSysParam(buf),nbytes);
  127. end;
  128. function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
  129. begin
  130. Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
  131. end;
  132. function Fpunlink(const path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
  133. begin
  134. Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
  135. end;
  136. function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
  137. begin
  138. Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
  139. end;
  140. function Fpstat(const path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
  141. begin
  142. Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
  143. end;
  144. {*****************************************************************************
  145. --- Directory:Directory related calls ---
  146. *****************************************************************************}
  147. function Fpchdir(path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
  148. begin
  149. Fpchdir:=do_syscall(syscall_nr_chdir,TSysParam(path));
  150. end;
  151. function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
  152. begin {Mode is 16-bit on F-BSD 4!}
  153. Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),mode);
  154. end;
  155. function Fprmdir(path : pchar): cint; [public, alias : 'FPC_SYSC_RMDIR'];
  156. begin
  157. Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
  158. end;
  159. {$ifndef NewReaddir}
  160. const DIRBLKSIZ=1024;
  161. function Fpopendir(dirname : pchar): pdir; [public, alias : 'FPC_SYSC_OPENDIR'];
  162. var
  163. fd:longint;
  164. st:stat;
  165. ptr:pdir;
  166. begin
  167. Fpopendir:=nil;
  168. if Fpstat(dirname,st)<0 then
  169. exit;
  170. { Is it a dir ? }
  171. if not((st.st_mode and $f000)=$4000)then
  172. begin
  173. errno:=ESysENOTDIR;
  174. exit
  175. end;
  176. { Open it}
  177. fd:=Fpopen(dirname,O_RDONLY,438);
  178. if fd<0 then
  179. Begin
  180. Errno:=-1;
  181. exit;
  182. End;
  183. new(ptr);
  184. if ptr=nil then
  185. Begin
  186. Errno:=1;
  187. exit;
  188. End;
  189. Getmem(ptr^.dd_buf,2*DIRBLKSIZ);
  190. if ptr^.dd_buf=nil then
  191. exit;
  192. ptr^.dd_fd:=fd;
  193. ptr^.dd_loc:=-1;
  194. ptr^.dd_rewind:=longint(ptr^.dd_buf);
  195. ptr^.dd_size:=0;
  196. // ptr^.dd_max:=sizeof(ptr^.dd_buf^);
  197. Fpopendir:=ptr;
  198. end;
  199. function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
  200. begin
  201. Fpclosedir:=Fpclose(dirp^.dd_fd);
  202. Freemem(dirp^.dd_buf);
  203. dispose(dirp);
  204. end;
  205. function Fpreaddir(dirp : pdir) : pdirent; [public, alias : 'FPC_SYSC_READDIR'];
  206. {Different from Linux, Readdir on BSD is based on Getdents, due to the
  207. missing of the readdir syscall.
  208. Getdents requires the buffer to be larger than the blocksize.
  209. This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
  210. with blockmode have this higher?}
  211. function readbuffer:longint;
  212. var retval :longint;
  213. begin
  214. Retval:=do_syscall(syscall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
  215. dirp^.dd_rewind:=TSysParam(dirp^.dd_buf);
  216. if retval=0 then
  217. begin
  218. dirp^.dd_rewind:=0;
  219. dirp^.dd_loc:=0;
  220. end
  221. else
  222. dirP^.dd_loc:=retval;
  223. readbuffer:=retval;
  224. end;
  225. var
  226. FinalEntry : pdirent;
  227. novalid : boolean;
  228. Reclen : Longint;
  229. CurEntry : PDirent;
  230. begin
  231. if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
  232. exit(nil);
  233. if (dirp^.dd_loc=-1) OR {First readdir on this pdir. Initial fill of buffer}
  234. (dirp^.dd_rewind>=(longint(dirp^.dd_buf)+dirblksiz)) then {no more entries left?}
  235. Begin
  236. if readbuffer=0 then {succesful read?}
  237. Exit(NIL); {No more data}
  238. End;
  239. FinalEntry:=NIL;
  240. CurEntry:=nil;
  241. repeat
  242. novalid:=false;
  243. CurEntry:=pdirent(dirp^.dd_rewind);
  244. RecLen:=CurEntry^.d_reclen;
  245. if RecLen<>0 Then
  246. begin {valid direntry?}
  247. if CurEntry^.d_fileno<>0 then
  248. FinalEntry:=CurEntry;
  249. inc(dirp^.dd_rewind,Reclen);
  250. end
  251. else
  252. begin {block entirely searched or reclen=0}
  253. Novalid:=True;
  254. if dirp^.dd_loc<>0 THEN {blocks left?}
  255. if readbuffer()<>0 then {succesful read?}
  256. novalid:=false;
  257. end;
  258. until (FinalEntry<>nil) or novalid;
  259. If novalid then
  260. FinalEntry:=nil;
  261. FpReadDir:=FinalEntry;
  262. end;
  263. {$endif}
  264. {*****************************************************************************
  265. --- Process:Process & program handling - related calls ---
  266. *****************************************************************************}
  267. procedure Fpexit(status : cint); [public, alias : 'FPC_SYSC_EXIT'];
  268. begin
  269. do_syscall(syscall_nr_exit,status);
  270. end;
  271. {
  272. Change action of process upon receipt of a signal.
  273. Signum specifies the signal (all except SigKill and SigStop).
  274. If Act is non-nil, it is used to specify the new action.
  275. If OldAct is non-nil the previous action is saved there.
  276. }
  277. function Fpsigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint; [public, alias : 'FPC_SYSC_SIGACTION'];
  278. {
  279. Change action of process upon receipt of a signal.
  280. Signum specifies the signal (all except SigKill and SigStop).
  281. If Act is non-nil, it is used to specify the new action.
  282. If OldAct is non-nil the previous action is saved there.
  283. }
  284. begin
  285. do_syscall(syscall_nr_sigaction,TSysParam(sig),TSysParam(@act),TSysParam(@oact));
  286. end;
  287. (*=================== MOVED from sysunix.inc ========================*)
  288. function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
  289. begin
  290. fpFStat:=do_SysCall(syscall_nr_fstat,fd,TSysParam(@sb));
  291. end;
  292. {$ifdef NewReaddir}
  293. {$I readdir.inc}
  294. {$endif}
  295. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];
  296. {
  297. This function issues the 'fork' System call. the program is duplicated in memory
  298. and Execution continues in parent and child process.
  299. In the parent process, fork returns the PID of the child. In the child process,
  300. zero is returned.
  301. A negative value indicates that an error has occurred, the error is returned in
  302. LinuxError.
  303. }
  304. Begin
  305. Fpfork:=Do_syscall(SysCall_nr_fork);
  306. End;
  307. {
  308. function Fpexecve(const path : pathstr; const argv : ppchar; const envp: ppchar): cint;
  309. }
  310. {
  311. Replaces the current program by the program specified in path,
  312. arguments in args are passed to Execve.
  313. environment specified in ep is passed on.
  314. }
  315. {
  316. Begin
  317. path:=path+#0;
  318. do_syscall(syscall_nr_Execve,TSysParam(@path[1]),TSysParam(Argv),TSysParam(envp));
  319. End;
  320. }
  321. {
  322. function Fpexecve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; [public, alias : 'FPC_SYSC_EXECVE'];
  323. }
  324. {
  325. Replaces the current program by the program specified in path,
  326. arguments in args are passed to Execve.
  327. environment specified in ep is passed on.
  328. }
  329. {
  330. Begin
  331. do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
  332. End;
  333. }
  334. function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
  335. {
  336. Waits until a child with PID Pid exits, or returns if it is exited already.
  337. Any resources used by the child are freed.
  338. The exit status is reported in the adress referred to by Status. It should
  339. be a longint.
  340. }
  341. begin // actually a wait4() call with 4th arg 0.
  342. FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options,0);
  343. end;
  344. function Fpaccess(const pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
  345. {
  346. Test users access rights on the specified file.
  347. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  348. R,W,X stand for read,write and Execute access, simultaneously.
  349. F_OK checks whether the test would be allowed on the file.
  350. i.e. It checks the search permissions in all directory components
  351. of the path.
  352. The test is done with the real user-ID, instead of the effective.
  353. If access is denied, or an error occurred, false is returned.
  354. If access is granted, true is returned.
  355. Errors other than no access,are reported in unixerror.
  356. }
  357. begin
  358. FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
  359. end;
  360. {
  361. function Fpaccess(const pathname : pathstr; amode : cint): cint;
  362. {
  363. Test users access rights on the specified file.
  364. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  365. R,W,X stand for read,write and Execute access, simultaneously.
  366. F_OK checks whether the test would be allowed on the file.
  367. i.e. It checks the search permissions in all directory components
  368. of the path.
  369. The test is done with the real user-ID, instead of the effective.
  370. If access is denied, or an error occurred, false is returned.
  371. If access is granted, true is returned.
  372. Errors other than no access,are reported in unixerror.
  373. }
  374. begin
  375. pathname:=pathname+#0;
  376. Access:=do_syscall(syscall_nr_access, TSysParam(@pathname[1]),mode)=0;
  377. end;
  378. }
  379. Function FpDup(fildes:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
  380. begin
  381. Fpdup:=Do_syscall(syscall_nr_dup,TSysParam(fildes));
  382. end;
  383. Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
  384. begin
  385. Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
  386. end;
  387. Function Fpmunmap(start:pointer;len:size_t):cint; [public, alias :'FPC_SYSC_MUNMAP'];
  388. begin
  389. Fpmunmap:=do_syscall(syscall_nr_munmap,TSysParam(start),Len);
  390. end;
  391. {
  392. Interface to Unix ioctl call.
  393. Performs various operations on the filedescriptor Handle.
  394. Ndx describes the operation to perform.
  395. Data points to data needed for the Ndx function. The structure of this
  396. data is function-dependent.
  397. }
  398. Function FpIOCtl(Handle:cint;Ndx: culong;Data: Pointer):cint; [public, alias : 'FPC_SYSC_IOCTL'];
  399. // This was missing here, instead hardcoded in Do_IsDevice
  400. begin
  401. FpIOCtl:=do_SysCall(syscall_nr_ioctl,handle,Ndx,TSysParam(data));
  402. end;
  403. Function FpGetPid:LongInt; [public, alias : 'FPC_SYSC_GETPID'];
  404. {
  405. Get Process ID.
  406. }
  407. begin
  408. FpGetPID:=do_syscall(syscall_nr_getpid);
  409. end;
  410. function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; [public, alias: 'FPC_SYSC_GETTIMEOFDAY'];
  411. begin
  412. fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp));
  413. end;
  414. function FPSigProcMask(how:cint;nset : psigset;oset : psigset):cint; [public, alias : 'FPC_SYSC_SIGPROCMASK'];
  415. {
  416. Change the list of currently blocked signals.
  417. How determines which signals will be blocked :
  418. SigBlock : Add SSet to the current list of blocked signals
  419. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  420. SigSetMask : Set the list of blocked signals to SSet
  421. if OldSSet is non-null, the old set will be saved there.
  422. }
  423. begin
  424. FPsigprocmask:=do_syscall(syscall_nr_sigprocmask,longint(how),longint(nset),longint(oset));
  425. end;
  426. {$user BLA!}
  427. Function FpNanoSleep(req : ptimespec;rem : ptimespec) : cint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
  428. begin
  429. FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
  430. end;
  431. function Fpgetcwd(pt:pchar; _size:size_t):pchar;[public, alias :'FPC_SYSC_GETCWD'];
  432. const intpathmax = 1024-4; // didn't use POSIX data in libc
  433. // implementation.
  434. var ept,bpt : pchar;
  435. c : char;
  436. ret : cint;
  437. begin
  438. if pt=NIL Then
  439. begin
  440. // POSIX: undefined. (exit(nil) ?)
  441. // BSD : allocate mem for path.
  442. getmem(pt,intpathmax);
  443. if pt=nil Then
  444. exit(nil);
  445. ept:=pt+intpathmax;
  446. end
  447. else
  448. Begin
  449. if (_size=0) Then
  450. Begin
  451. seterrno(ESysEINVAL);
  452. exit(nil);
  453. End;
  454. if (_size=1) Then
  455. Begin
  456. seterrno(ESysERANGE);
  457. exit(nil);
  458. End;
  459. ept:=pt+_size;
  460. end;
  461. ret := do_syscall(syscall_nr___getcwd,TSysParam(pt),TSysParam( ept - pt));
  462. If (ret = 0) Then
  463. If (pt[0] <> '/') Then
  464. Begin
  465. bpt := pt;
  466. ept := pt + strlen(pt) - 1;
  467. While (bpt < ept) Do
  468. Begin
  469. c := bpt^;
  470. bpt^:=ept^;
  471. inc(bpt);
  472. ept^:=c;
  473. dec(ept);
  474. End;
  475. End;
  476. Fpgetcwd:=pt;
  477. end;
  478. Function fpReadLink(name,linkname:pchar;maxlen:size_t):cint; [public, alias : 'FPC_SYSC_READLINK'];
  479. begin
  480. fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
  481. end;
  482. {$endif}
  483. CONST
  484. IOCtl_TCGETS=$5401;
  485. Function Do_IsDevice(Handle:Longint):boolean;
  486. {
  487. Interface to Unix ioctl call.
  488. Performs various operations on the filedescriptor Handle.
  489. Ndx describes the operation to perform.
  490. Data points to data needed for the Ndx function. The structure of this
  491. data is function-dependent.
  492. }
  493. var
  494. Data : array[0..255] of byte; {Large enough for termios info}
  495. begin
  496. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  497. end;
  498. CONST
  499. { Constansts for MMAP }
  500. MAP_PRIVATE =2;
  501. MAP_ANONYMOUS =$1000;
  502. Function sbrk(size : cint) : pointer;
  503. begin
  504. sbrk:=Fpmmap(nil,cardinal(Size),3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0);
  505. if sbrk=pointer(-1) then
  506. sbrk:=nil
  507. else
  508. seterrno(0);
  509. end;
  510. {
  511. $Log$
  512. Revision 1.20 2004-11-14 12:21:08 marco
  513. * moved some calls from unix to baseunix. Darwin untested.
  514. Revision 1.19 2004/07/18 11:32:24 marco
  515. * small 1.0.x fix to earlier patch
  516. Revision 1.18 2004/07/17 16:02:58 marco
  517. * generalised the {$ifdef cpu_i386} ..powerpc stuff to FPC_BIG_ENDIAN and
  518. FPC_LITTLE_ENDIAN
  519. Revision 1.17 2004/02/06 20:47:00 jonas
  520. + fpnanosleep for oscdeclh.inc
  521. - removed obsolete darwin remarks from bsd/ossysc.inc
  522. Revision 1.16 2003/12/30 12:26:21 marco
  523. * FPC_USE_LIBC
  524. Revision 1.15 2003/12/16 19:43:59 marco
  525. * nil <-> 0 changes
  526. Revision 1.14 2003/10/26 17:01:04 marco
  527. * moved sigprocmask to system
  528. Revision 1.13 2003/10/17 22:10:30 olle
  529. * changed i386 to cpui386
  530. Revision 1.12 2003/09/27 13:45:58 peter
  531. * fpnanosleep exported in baseunix
  532. * fpnanosleep has pointer arguments to be C compliant
  533. Revision 1.10 2003/09/20 12:38:29 marco
  534. * FCL now compiles for FreeBSD with new 1.1. Now Linux.
  535. Revision 1.9 2003/09/17 16:02:31 marco
  536. * ostype include moved to top
  537. Revision 1.8 2003/09/16 12:45:49 marco
  538. * mmap typing fixes
  539. Revision 1.7 2003/09/15 20:08:49 marco
  540. * small fixes. FreeBSD now cycles
  541. Revision 1.6 2003/09/14 20:15:01 marco
  542. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  543. Revision 1.5 2003/08/21 22:23:34 olle
  544. - removed parameter from fpc_iocheck
  545. Revision 1.4 2003/05/29 21:45:23 marco
  546. * Some other workaround
  547. Revision 1.3 2003/05/29 20:52:55 marco
  548. * only moved around the off_t calls, and made an exception (includefile)
  549. for NetBSD/powerpc
  550. Revision 1.2 2003/05/26 21:29:16 jonas
  551. - disabled nanosleep for darwin for now
  552. + getcwd for darwin
  553. Revision 1.1 2003/01/05 19:01:28 marco
  554. * FreeBSD compiles now with baseunix mods.
  555. Revision 1.9 2002/11/13 18:15:08 marco
  556. * sigset functions more flexible, small changes to sys_ktime
  557. Revision 1.8 2002/10/27 17:21:29 marco
  558. * Only "difficult" functions + execvp + termios + rewinddir left to do
  559. Revision 1.7 2002/10/27 11:58:29 marco
  560. * Modifications from Saturday.
  561. Revision 1.6 2002/10/26 18:27:51 marco
  562. * First series POSIX calls commits. Including getcwd.
  563. Revision 1.5 2002/10/18 12:19:58 marco
  564. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  565. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  566. sysposix not yet commited
  567. Revision 1.4 2002/10/16 18:44:18 marco
  568. * Lseek and ftruncate 64-bit fix
  569. Revision 1.3 2002/09/07 16:01:17 peter
  570. * old logs removed and tabs fixed
  571. Revision 1.2 2002/08/21 07:03:16 marco
  572. * Fixes from Tuesday.
  573. Revision 1.1 2002/08/19 12:29:11 marco
  574. * First working POSIX *BSD system unit.
  575. Revision 1.2 2002/08/04 04:29:34 marco
  576. * More POSIX updates. Small changes to lseek and ftruncate in osposix.inc
  577. Initial versions of the type includefiles
  578. Revision 1.1 2002/08/03 19:34:19 marco
  579. * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
  580. NetBSD may need some fixes to stat record and ftruncate and lseek.
  581. It is all close together, and it should be doable to have just one copy
  582. of these for *BSD.
  583. }