ossysc.inc 21 KB

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