unxfunc.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY;without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifndef HAS_LIBC_PIPING}
  12. Function PClose(Var F:file) : cint;
  13. var
  14. pl : ^cint;
  15. res : cint;
  16. pid: cint;
  17. begin
  18. fpclose(filerec(F).Handle);
  19. { closed our side, Now wait for the other - this appears to be needed ?? }
  20. pl:=@(filerec(f).userdata[2]);
  21. { avoid alignment error on sparc }
  22. move(pl^,pid,sizeof(pid));
  23. fpwaitpid(pid,@res,0);
  24. pclose:=res shr 8;
  25. end;
  26. Function PClose(Var F:text) :cint;
  27. var
  28. pl : ^cint;
  29. res : cint;
  30. pid: cint;
  31. begin
  32. fpclose(Textrec(F).Handle);
  33. { closed our side, Now wait for the other - this appears to be needed ?? }
  34. pl:=@(textrec(f).userdata[2]);
  35. { avoid alignment error on sparc }
  36. move(pl^,pid,sizeof(pid));
  37. fpwaitpid(pid,@res,0);
  38. pclose:=res shr 8;
  39. end;
  40. {$ENDIF}
  41. Function AssignPipe(var pipe_in,pipe_out:cint):cint; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
  42. {
  43. Sets up a pair of file variables, which act as a pipe. The first one can
  44. be read from, the second one can be written to.
  45. If the operation was unsuccesful, linuxerror is set.
  46. }
  47. var
  48. ret : longint;
  49. errn : cint;
  50. {$ifdef FPC_USE_LIBC}
  51. fdis : array[0..1] of cint;
  52. {$endif}
  53. begin
  54. {$ifndef FPC_USE_LIBC}
  55. ret:=intAssignPipe(pipe_in,pipe_out,errn);
  56. if ret=-1 Then
  57. fpseterrno(errn);
  58. {$ELSE}
  59. fdis[0]:=pipe_in;
  60. fdis[1]:=pipe_out;
  61. ret:=pipe(fdis);
  62. pipe_in:=fdis[0];
  63. pipe_out:=fdis[1];
  64. {$ENDIF}
  65. AssignPipe:=ret;
  66. end;
  67. Function fpFlock (fd,mode : longint) : cint;
  68. {
  69. var
  70. fl : flock;
  71. cmd : cint;
  72. }
  73. begin
  74. {
  75. { initialize the flock struct to set lock on entire file }
  76. fillchar(fl,sizeof(fl),0);
  77. { In non-blocking lock, use F_SETLK for cmd, F_SETLKW otherwise }
  78. if (operation and LOCK_NB)<>0 then
  79. begin
  80. cmd:=F_SETLK;
  81. { turn off this bit }
  82. operation:=operation and not(LOCK_NB);
  83. end
  84. else
  85. cmd:=F_SETLKW;
  86. case operation of
  87. LOCK_UN:
  88. fl.l_type:=fl.l_type or F_UNLCK;
  89. LOCK_SH:
  90. fl.l_type:=fl.l_type or F_RDLCK;
  91. LOCK_EX:
  92. fl.l_type:=fl.l_type or F_WRLCK;
  93. else
  94. begin
  95. errno:=EINVAL;
  96. result:=-1
  97. exit;
  98. end;
  99. end;
  100. result:=fpFcntl(fd,cmd,@fl);
  101. if (result=-1) and (errno=EACCES)
  102. errno:=EWOULDBLOCK;
  103. }
  104. end;