ossysc.inc 21 KB

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