unixsysc.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Function fdFlush (fd : Longint) : Boolean;
  13. var
  14. SR: SysCallRegs;
  15. begin
  16. SR.reg2 := fd;
  17. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  18. LinuxError:=fpgetErrno;
  19. end;
  20. Function Flock (fd,mode : longint) : boolean;
  21. var
  22. sr : Syscallregs;
  23. begin
  24. sr.reg2:=fd;
  25. sr.reg3:=mode;
  26. flock:=Syscall(Syscall_nr_flock,sr)=0;
  27. LinuxError:=fpgeterrno;
  28. end;
  29. Function StatFS(Path:Pathstr;Var Info:tstatfs):Boolean;
  30. {
  31. Get all information on a fileSystem, and return it in Info.
  32. Path is the name of a file/directory on the fileSystem you wish to
  33. investigate.
  34. }
  35. var
  36. regs : SysCallregs;
  37. begin
  38. path:=path+#0;
  39. regs.reg2:=longint(@path[1]);
  40. regs.reg3:=longint(@Info);
  41. StatFS:=(SysCall(SysCall_nr_statfs,regs)=0);
  42. LinuxError:=fpgeterrno;
  43. end;
  44. Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
  45. {
  46. Get all information on a fileSystem, and return it in Info.
  47. Fd is the file descriptor of a file/directory on the fileSystem
  48. you wish to investigate.
  49. }
  50. var
  51. regs : SysCallregs;
  52. begin
  53. regs.reg2:=Fd;
  54. regs.reg3:=longint(@Info);
  55. StatFS:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  56. LinuxError:=fpgeterrno;
  57. end;
  58. Function AssignPipe(var pipe_in,pipe_out:longint):boolean; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
  59. {
  60. Sets up a pair of file variables, which act as a pipe. The first one can
  61. be read from, the second one can be written to.
  62. If the operation was unsuccesful, linuxerror is set.
  63. }
  64. var
  65. pip : tpipe;
  66. regs : SysCallregs;
  67. begin
  68. regs.reg2:=longint(@pip);
  69. SysCall(SysCall_nr_pipe,regs);
  70. pipe_in:=pip[1];
  71. pipe_out:=pip[2];
  72. linuxerror:=fpgeterrno;
  73. AssignPipe:=(LinuxError=0);
  74. end;
  75. Function PClose(Var F:text) :longint;
  76. var
  77. sr : syscallregs;
  78. pl : ^longint;
  79. res : longint;
  80. begin
  81. sr.reg2:=Textrec(F).Handle;
  82. SysCall (syscall_nr_close,sr);
  83. { closed our side, Now wait for the other - this appears to be needed ?? }
  84. pl:=@(textrec(f).userdata[2]);
  85. fpwaitpid(pl^,@res,0);
  86. pclose:=res shr 8;
  87. end;
  88. Function PClose(Var F:file) : longint;
  89. var
  90. sr : syscallregs;
  91. pl : ^longint;
  92. res : longint;
  93. begin
  94. sr.reg2:=FileRec(F).Handle;
  95. SysCall (Syscall_nr_close,sr);
  96. { closed our side, Now wait for the other - this appears to be needed ?? }
  97. pl:=@(filerec(f).userdata[2]);
  98. fpwaitpid(pl^,@res,0);
  99. pclose:=res shr 8;
  100. end;
  101. {--------------------------------
  102. Port IO functions
  103. --------------------------------}
  104. {$ifdef cpui386}
  105. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  106. {
  107. Set permissions on NUM ports starting with port FROM to VALUE
  108. this works ONLY as root.
  109. }
  110. Var
  111. Sr : Syscallregs;
  112. begin
  113. Sr.Reg2:=From;
  114. Sr.Reg3:=Num;
  115. Sr.Reg4:=Value;
  116. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  117. LinuxError:=fpgetErrno;
  118. end;
  119. Function IoPL(Level : longint) : Boolean;
  120. Var
  121. Sr : Syscallregs;
  122. begin
  123. Sr.Reg2:=Level;
  124. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  125. LinuxError:=fpgetErrno;
  126. end;
  127. {$endif cpui386}
  128. {
  129. $Log$
  130. Revision 1.14 2003-10-17 22:11:28 olle
  131. * changed i386 to cpui386
  132. Revision 1.13 2003/09/20 12:45:34 marco
  133. * Small fix. Cycle works
  134. Revision 1.12 2003/09/16 21:46:27 marco
  135. * small fixes, checking things on linux
  136. Revision 1.11 2003/09/15 21:07:32 marco
  137. * second round of linux fixes. oldlinux now works
  138. Revision 1.10 2003/09/14 20:15:01 marco
  139. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  140. Revision 1.9 2003/07/08 21:23:24 peter
  141. * sparc fixes
  142. Revision 1.8 2002/12/18 16:43:26 marco
  143. * new unix rtl, linux part.....
  144. Revision 1.7 2002/09/07 16:01:20 peter
  145. * old logs removed and tabs fixed
  146. Revision 1.6 2002/03/05 20:04:25 michael
  147. + Patch from Sebastian for FCNTL call
  148. }