2
0

osposix.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. {
  2. $Id: osposix.inc,v 1.1.2.2 2002/04/17 17:16:14 carl Exp $
  3. Copyright (c) 2001 by Carl Eric Codere
  4. Implements POSIX 1003.1 conforming interface
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02111-1301 USA.
  17. ****************************************************************************
  18. }
  19. {$Linklib c}
  20. function int_fork : pid_t; cdecl; external name 'fork';
  21. function int_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
  22. function int_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
  23. function int_uname(var name: utsname): cint; cdecl; external name 'uname';
  24. procedure sys_exit(status : cint); cdecl; external name '_exit';
  25. function int_opendir(const dirname : pchar): pdir; cdecl; external name 'opendir';
  26. function int_readdir(dirp : pdir) : pdirent;cdecl; external name 'readdir';
  27. function int_closedir(dirp : pdir): cint; cdecl; external name 'closedir';
  28. function int_chdir(const path : pchar): cint; cdecl; external name 'chdir';
  29. function int_open(const path: pchar; flags : cint; mode: mode_t):cint; cdecl; external name 'open';
  30. function int_mkdir(const path : pchar; mode: mode_t):cint; cdecl; external name 'mkdir';
  31. function int_unlink(const path: pchar): cint; cdecl; external name 'unlink';
  32. function int_rmdir(const path : pchar): cint; cdecl; external name 'rmdir';
  33. function int_rename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
  34. function int_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
  35. function int_close(fd : cint): cint; cdecl; external name 'close';
  36. function int_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t; cdecl; external name 'read';
  37. function int_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t; cdecl; external name 'write';
  38. function int_lseek(fd : cint; offset : off_t; whence : cint): off_t; cdecl; external name 'lseek';
  39. function int_time(var tloc:time_t): time_t; cdecl; external name 'time';
  40. function int_ftruncate(fd : cint; flength : off_t): cint; cdecl; external name 'ftruncate';
  41. function int_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint; cdecl; external name 'sigaction';
  42. function int_fstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
  43. function int_stat(const path: pchar; var buf : stat): cint; cdecl; external name 'stat';
  44. function sys_fork : pid_t;
  45. begin
  46. sys_fork := int_fork;
  47. if sys_fork <> - 1 then
  48. begin
  49. errno := 0; { reset errno when the call succeeds, contrary to libc }
  50. end;
  51. end;
  52. function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint;
  53. begin
  54. sys_execve := int_execve(path, argv, envp);
  55. if sys_execve <> - 1 then
  56. begin
  57. errno := 0; { reset errno when the call succeeds, contrary to libc }
  58. end;
  59. end;
  60. function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t;
  61. begin
  62. sys_waitpid := int_waitpid(pid, stat_loc, options);
  63. if sys_waitpid <> - 1 then
  64. begin
  65. errno := 0; { reset errno when the call succeeds, contrary to libc }
  66. end;
  67. end;
  68. function sys_uname(var name: utsname): cint;
  69. begin
  70. sys_uname := int_uname(name);
  71. if sys_uname <> - 1 then
  72. begin
  73. errno := 0; { reset errno when the call succeeds, contrary to libc }
  74. end;
  75. end;
  76. function sys_opendir(const dirname : pchar): pdir;
  77. begin
  78. sys_opendir := int_opendir(dirname);
  79. if sys_opendir <> nil then
  80. begin
  81. errno := 0; { reset errno when the call succeeds, contrary to libc }
  82. end;
  83. end;
  84. function sys_readdir(dirp : pdir) : pdirent;
  85. begin
  86. sys_readdir := int_readdir(dirp);
  87. if sys_readdir <> nil then
  88. begin
  89. errno := 0; { reset errno when the call succeeds, contrary to libc }
  90. end;
  91. end;
  92. function sys_closedir(dirp : pdir): cint;
  93. begin
  94. sys_closedir := int_closedir(dirp);
  95. if sys_closedir <> -1 then
  96. begin
  97. errno := 0; { reset errno when the call succeeds, contrary to libc }
  98. end;
  99. end;
  100. function sys_chdir(const path : pchar): cint;
  101. begin
  102. sys_chdir := int_chdir(path);
  103. if sys_chdir <> -1 then
  104. begin
  105. errno := 0; { reset errno when the call succeeds, contrary to libc }
  106. end;
  107. end;
  108. function sys_open(const path: pchar; flags : cint; mode: mode_t):cint;
  109. begin
  110. sys_open:= int_open(path, flags, mode);
  111. if sys_open <> -1 then
  112. begin
  113. errno := 0; { reset errno when the call succeeds, contrary to libc }
  114. end;
  115. end;
  116. function sys_mkdir(const path : pchar; mode: mode_t):cint;
  117. begin
  118. sys_mkdir:= int_mkdir(path, mode);
  119. if sys_mkdir <> -1 then
  120. begin
  121. errno := 0; { reset errno when the call succeeds, contrary to libc }
  122. end;
  123. end;
  124. function sys_unlink(const path: pchar): cint;
  125. begin
  126. sys_unlink := int_unlink(path);
  127. if sys_unlink <> -1 then
  128. begin
  129. errno := 0; { reset errno when the call succeeds, contrary to libc }
  130. end;
  131. end;
  132. function sys_rmdir(const path : pchar): cint;
  133. begin
  134. sys_rmdir := int_rmdir(path);
  135. if sys_rmdir <> -1 then
  136. begin
  137. errno := 0; { reset errno when the call succeeds, contrary to libc }
  138. end;
  139. end;
  140. function sys_rename(const old : pchar; const newpath: pchar): cint;
  141. begin
  142. sys_rename := int_rename(old, newpath);
  143. if sys_rename <> -1 then
  144. begin
  145. errno := 0; { reset errno when the call succeeds, contrary to libc }
  146. end;
  147. end;
  148. function sys_access(const pathname : pchar; amode : cint): cint;
  149. begin
  150. sys_access := int_access(pathname, amode);
  151. if sys_access <> -1 then
  152. begin
  153. errno := 0; { reset errno when the call succeeds, contrary to libc }
  154. end;
  155. end;
  156. function sys_close(fd : cint): cint;
  157. begin
  158. sys_close := int_close(fd);
  159. if sys_close <> -1 then
  160. begin
  161. errno := 0; { reset errno when the call succeeds, contrary to libc }
  162. end;
  163. end;
  164. function sys_read(fd: cint; buf: pchar; nbytes : size_t): ssize_t;
  165. begin
  166. sys_read := int_read(fd, buf, nbytes);
  167. if sys_read <> -1 then
  168. begin
  169. errno := 0; { reset errno when the call succeeds, contrary to libc }
  170. end;
  171. end;
  172. function sys_write(fd: cint;const buf:pchar; nbytes : size_t): ssize_t;
  173. begin
  174. sys_write := int_write(fd, buf, nbytes);
  175. if sys_write <> -1 then
  176. begin
  177. errno := 0; { reset errno when the call succeeds, contrary to libc }
  178. end;
  179. end;
  180. function sys_lseek(fd : cint; offset : off_t; whence : cint): off_t;
  181. begin
  182. sys_lseek := int_lseek(fd, offset, whence);
  183. if sys_lseek <> -1 then
  184. begin
  185. errno := 0; { reset errno when the call succeeds, contrary to libc }
  186. end;
  187. end;
  188. function sys_time(var tloc:time_t): time_t;
  189. begin
  190. sys_time := int_time(tloc);
  191. if sys_time <> -1 then
  192. begin
  193. errno := 0; { reset errno when the call succeeds, contrary to libc }
  194. end;
  195. end;
  196. function sys_ftruncate(fd : cint; flength : off_t): cint;
  197. begin
  198. sys_ftruncate := int_ftruncate(fd, flength);
  199. if sys_ftruncate <> -1 then
  200. begin
  201. errno := 0; { reset errno when the call succeeds, contrary to libc }
  202. end;
  203. end;
  204. function sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionrec): cint;
  205. begin
  206. sys_sigaction := int_sigaction(sig, act, oact);
  207. if sys_sigaction <> -1 then
  208. begin
  209. errno := 0; { reset errno when the call succeeds, contrary to libc }
  210. end;
  211. end;
  212. function sys_fstat(fd : cint; var sb : stat): cint;
  213. begin
  214. sys_fstat := int_fstat(fd, sb);
  215. if sys_fstat <> -1 then
  216. begin
  217. errno := 0; { reset errno when the call succeeds, contrary to libc }
  218. end;
  219. end;
  220. function sys_stat(const path: pchar; var buf : stat): cint;
  221. begin
  222. sys_stat := int_stat(path, buf);
  223. if sys_stat <> -1 then
  224. begin
  225. errno := 0; { reset errno when the call succeeds, contrary to libc }
  226. end;
  227. end;
  228. const
  229. _S_IFMT = $F000; (* Type of file *)
  230. _S_IFIFO = $1000; (* FIFO *)
  231. _S_IFCHR = $2000; (* Character special *)
  232. _S_IFDIR = $4000; (* Directory *)
  233. _S_IFNAM = $5000; (* Special named file *)
  234. _S_IFBLK = $6000; (* Block special *)
  235. _S_IFREG = $8000; (* Regular *)
  236. _S_IFLNK = $A000; (* Symbolic link *)
  237. _S_IFSOCK = $C000; (* Socket *)
  238. function S_ISDIR(m : mode_t): boolean;
  239. begin
  240. if (m and _S_IFMT) = _S_IFDIR then
  241. S_ISDIR := true
  242. else
  243. S_ISDIR := false;
  244. end;
  245. function S_ISCHR(m : mode_t): boolean;
  246. begin
  247. if (m and _S_IFMT) = _S_IFCHR then
  248. S_ISCHR := true
  249. else
  250. S_ISCHR := false;
  251. end;
  252. function S_ISBLK(m : mode_t): boolean;
  253. begin
  254. if (m and _S_IFMT) = _S_IFBLK then
  255. S_ISBLK := true
  256. else
  257. S_ISBLK := false;
  258. end;
  259. function S_ISREG(m : mode_t): boolean;
  260. begin
  261. if (m and _S_IFMT) = _S_IFREG then
  262. S_ISREG := true
  263. else
  264. S_ISREG := false;
  265. end;
  266. function S_ISFIFO(m : mode_t): boolean;
  267. begin
  268. if (m and _S_IFMT) = _S_IFIFO then
  269. S_ISFIFO := true
  270. else
  271. S_ISFIFO := false;
  272. end;
  273. function wifexited(status : cint): cint;
  274. begin
  275. wifexited := longint((status and $FF) = 0);
  276. end;
  277. function wexitstatus(status : cint): cint;
  278. begin
  279. wexitstatus := (((status) shr 8) and $FF);
  280. end;
  281. function wstopsig(status : cint): cint;
  282. begin
  283. wstopsig := (((status) shr 8) and $FF);
  284. end;
  285. function wifsignaled(status : cint): cint;
  286. begin
  287. if ((status and $FF) <> 0) and ((status and $FF00)=0) then
  288. wifsignaled := 1
  289. else
  290. wifsignaled := 0;
  291. end;
  292. {
  293. $Log: osposix.inc,v $
  294. Revision 1.1.2.2 2002/04/17 17:16:14 carl
  295. * more fixes for QNX target
  296. Revision 1.1.2.1 2001/12/20 02:55:01 carl
  297. + QNX versions (still untested)
  298. }