baseunix.pp 4.1 KB

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