baseunix.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Carl Eric Codere development team
  4. Base Unix unit modelled after POSIX 2001.
  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. Unit BaseUnix;
  12. Interface
  13. {$inline on}
  14. Uses UnixType;
  15. {$i osdefs.inc} { Compile time defines }
  16. {$i aliasptp.inc}
  17. {$packrecords C}
  18. {$ifndef FPC_USE_LIBC}
  19. {$define FPC_USE_SYSCALL}
  20. {$endif}
  21. {$i errno.inc} { Error numbers }
  22. {$i ostypes.inc}
  23. {$ifdef FPC_USE_LIBC}
  24. const clib = 'root';
  25. const netlib = 'network';
  26. {$i oscdeclh.inc}
  27. {$ELSE}
  28. {$i bunxh.inc} { Functions}
  29. {$ENDIF}
  30. function fpgeterrno:longint;
  31. procedure fpseterrno(err:longint);
  32. {$ifndef ver1_0}
  33. property errno : cint read fpgeterrno write fpseterrno;
  34. {$endif}
  35. {$i bunxovlh.inc}
  36. {$ifdef FPC_USE_LIBC}
  37. {$ifdef beos}
  38. function fpsettimeofday(tp:ptimeval;tzp:ptimezone):cint;
  39. Function fpFlock (var fd : text; mode : longint) : cint;
  40. Function fpFlock (var fd : File; mode : longint) : cint;
  41. Function fpFlock (fd, mode : longint) : cint;
  42. Function FpNanoSleep (req : ptimespec;rem : ptimespec):cint;
  43. {$endif}
  44. {$endif}
  45. {$i genfunch.inc}
  46. { Fairly portable constants. I'm not going to waste time to duplicate and alias
  47. them anywhere}
  48. Const
  49. MAP_FAILED = pointer(-1); { mmap() has failed }
  50. MAP_SHARED = $1; { Share changes }
  51. MAP_PRIVATE = $2; { Changes are private }
  52. MAP_TYPE = $f; { Mask for type of mapping }
  53. MAP_FIXED = $10; { Interpret addr exactly }
  54. // MAP_ANON(YMOUS) is OS dependant but used in the RTL and in ostypes.inc
  55. // Under BSD without -YMOUS, so alias it:
  56. MAP_ANON = MAP_ANONYMOUS;
  57. PROT_READ = $1; { page can be read }
  58. PROT_WRITE = $2; { page can be written }
  59. PROT_EXEC = $4; { page can be executed }
  60. PROT_NONE = $0; { page can not be accessed }
  61. implementation
  62. {$ifdef hassysctl}
  63. Uses Sysctl;
  64. {$endif}
  65. {$i genfuncs.inc} // generic calls. (like getenv)
  66. {$I gensigset.inc} // general sigset funcs implementation.
  67. {$I genfdset.inc} // general fdset funcs.
  68. {$ifdef FPC_USE_LIBC}
  69. {$i oscdecl.inc} // implementation of wrappers in oscdeclh.inc
  70. {$else}
  71. {$i syscallh.inc} // do_syscall declarations themselves
  72. {$i sysnr.inc} // syscall numbers.
  73. {$i bsyscall.inc} // cpu specific syscalls
  74. {$i bunxsysc.inc} // syscalls in system unit.
  75. // {$i settimeo.inc}
  76. {$endif}
  77. {$i settimeo.inc}
  78. {$i osmacro.inc} { macro implenenations }
  79. {$i bunxovl.inc} { redefs and overloads implementation }
  80. {$ifndef ver1_0}
  81. function fpgeterrno:longint; external name 'FPC_SYS_GETERRNO';
  82. procedure fpseterrno(err:longint); external name 'FPC_SYS_SETERRNO';
  83. {$else}
  84. // workaround for 1.0.10 bugs.
  85. function intgeterrno:longint; external name 'FPC_SYS_GETERRNO';
  86. procedure intseterrno(err:longint); external name 'FPC_SYS_SETERRNO';
  87. function fpgeterrno:longint;
  88. begin
  89. fpgeterrno:=intgeterrno;
  90. end;
  91. procedure fpseterrno(err:longint);
  92. begin
  93. intseterrno(err);
  94. end;
  95. {$endif}
  96. function fpsettimeofday(tp:ptimeval;tzp:ptimezone):cint;
  97. begin
  98. fpsettimeofday := settimeofday(tp, tzp);
  99. end;
  100. Function fpFlock (var fd : File; mode : longint) : cint;
  101. begin
  102. {$warning TODO BeOS fpFlock implementation}
  103. end;
  104. Function fpFlock (var fd : Text; mode : longint) : cint;
  105. begin
  106. {$warning TODO BeOS fpFlock implementation}
  107. end;
  108. Function fpFlock (fd, mode : longint) : cint;
  109. begin
  110. {$warning TODO BeOS fpFlock implementation}
  111. end;
  112. function snooze(microseconds : bigtime_t) : status_t; cdecl; external 'root' name 'snooze';
  113. Function FpNanoSleep (req : ptimespec;rem : ptimespec):cint;
  114. begin
  115. case snooze((req^.tv_nsec div 1000) + (req^.tv_sec * 1000 * 1000)) of
  116. B_OK : FpNanoSleep := 0;
  117. B_INTERRUPTED : FpNanoSleep := - 1;
  118. else
  119. FpNanoSleep := - 1;
  120. end;
  121. end;
  122. end.