unxfunc.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. { should probably be defined in ostypes.inc for all OSes }
  68. const
  69. F_RDLCK = 01; (* Read lock *)
  70. F_WRLCK = 02; (* Write lock *)
  71. F_UNLCK = 03; (* Remove lock(s) *)
  72. Function fpFlock (fd,mode : longint) : cint;
  73. var
  74. fl : flock;
  75. cmd : cint;
  76. begin
  77. { initialize the flock struct to set lock on entire file }
  78. fillchar(fl,sizeof(fl),0);
  79. { In non-blocking lock, use F_SETLK for cmd, F_SETLKW otherwise }
  80. if (mode and LOCK_NB)<>0 then
  81. begin
  82. cmd:=F_SETLK;
  83. { turn off this bit }
  84. mode:=mode and not(LOCK_NB);
  85. end
  86. else
  87. cmd:=F_SETLKW;
  88. case mode of
  89. LOCK_UN:
  90. fl.l_type:=fl.l_type or F_UNLCK;
  91. LOCK_SH:
  92. fl.l_type:=fl.l_type or F_RDLCK;
  93. LOCK_EX:
  94. fl.l_type:=fl.l_type or F_WRLCK;
  95. else
  96. begin
  97. errno:=ESysEINVAL;
  98. fpFlock:=-1;
  99. exit;
  100. end;
  101. end;
  102. fpFlock:=fpFcntl(fd,cmd,fl);
  103. if (fpFlock=-1) and (errno=ESysEACCES) then
  104. errno:=ESysEWOULDBLOCK;
  105. end;
  106. const
  107. SolarisTimeZoneFile = '/etc/default/init';
  108. SolarisTimeZoneDir = '/usr/share/lib/zoneinfo/';
  109. {$define FPC_HAS_GETTIMEZONEFILE}
  110. function GetTimezoneFile:shortstring;
  111. var
  112. s : shortstring;
  113. p : longint;
  114. ft : text;
  115. begin
  116. GetTimezoneFile:='';
  117. assign(ft,SolarisTimeZoneFile);
  118. {$push}
  119. {$I-}
  120. reset(ft);
  121. if IOResult=0 then
  122. begin
  123. while not eof(ft) do
  124. begin
  125. readln(ft,s);
  126. p:=pos('#',s);
  127. if p>0 then
  128. s[0]:=chr(p-1);
  129. p:=pos('TZ=',s);
  130. if p>0 then
  131. begin
  132. GetTimeZoneFile:=SolarisTimeZoneDir+copy(s,p+3,length(s));
  133. close(ft);
  134. exit;
  135. end;
  136. end;
  137. close(ft);
  138. end;
  139. {$pop}
  140. end;