add listen-timeout to function as an accept timeout
[socat/sam.git] / sycls.c
blobfa9f1f9070786abaf362a02bcbbc14bd8cbd36a9
1 /* source: sycls.c */
2 /* Copyright Gerhard Rieger 2001-2008 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* explicit system call and C library trace function, for those who miss strace
6 */
8 #include "config.h"
9 #include "xioconfig.h" /* what features are enabled */
11 #if WITH_SYCLS
13 #include "sysincludes.h"
15 #include "mytypes.h"
16 #include "compat.h"
17 #include "errno.h"
19 #include "error.h"
20 #include "filan.h"
21 #include "sysutils.h"
22 #include "sycls.h"
25 mode_t Umask(mode_t mask) {
26 mode_t result;
27 int _errno;
28 Debug1("umask("F_mode")", mask);
29 result = umask(mask);
30 _errno = errno;
31 Debug1("umask() -> "F_mode, result);
32 errno = _errno;
33 return result;
36 int Open(const char *pathname, int flags, mode_t mode) {
37 int result, _errno;
38 Debug3("open(\"%s\", 0%o, 0%03o)", pathname, flags, mode);
39 result = open(pathname, flags, mode);
40 _errno = errno;
41 Info4("open(\"%s\", 0%o, 0%03o) -> %d", pathname, flags, mode, result);
42 errno = _errno;
43 return result;
46 int Creat(const char *pathname, mode_t mode) {
47 int result, _errno;
48 Debug2("creat(\"%s\", 0%03o)", pathname, mode);
49 result = creat(pathname, mode);
50 _errno = errno;
51 Info3("creat(\"%s\", 0%03o) -> %d", pathname, mode, result);
52 errno = _errno;
53 return result;
56 off_t Lseek(int fildes, off_t offset, int whence) {
57 int _errno;
58 off_t result;
59 Debug3("lseek(%d, "F_off", %d)", fildes, offset, whence);
60 result = lseek(fildes, offset, whence);
61 _errno = errno;
62 Debug1("lseek() -> "F_off, result);
63 errno = _errno;
64 return result;
67 #if HAVE_LSEEK64
68 off64_t Lseek64(int fildes, off64_t offset, int whence) {
69 int _errno;
70 off64_t result;
71 Debug3("lseek64(%d, "F_off64", %d)", fildes, offset, whence);
72 result = lseek64(fildes, offset, whence);
73 _errno = errno;
74 Debug1("lseek64() -> "F_off64, result);
75 errno = _errno;
76 return result;
78 #endif /* HAVE_LSEEK64 */
80 pid_t Getpid(void) {
81 pid_t result;
82 int _errno;
83 Debug("getpid()");
84 result = getpid();
85 _errno = errno;
86 Debug1("getpid() -> "F_pid, result);
87 errno = _errno;
88 return result;
91 pid_t Getppid(void) {
92 pid_t result;
93 int _errno;
94 Debug("getppid()");
95 result = getppid();
96 _errno = errno;
97 Debug1("getppid() -> "F_pid, result);
98 errno = _errno;
99 return result;
102 pid_t Getpgrp(void) {
103 pid_t result;
104 int _errno;
105 Debug("getpgrp()");
106 result = getpgrp();
107 _errno = errno;
108 Debug1("getpgrp() -> "F_pid, result);
109 errno = _errno;
110 return result;
113 #if 0 /* does not compile for FreeBSD */
114 /* setpgrp() is not BSD compatible, needs setpgid(..., ...) instead */
115 int Setpgrp(void) {
116 int result, _errno;
117 Debug("setpgrp()");
118 result = setpgrp();
119 _errno = errno;
120 Debug1("setpgrp() -> %d", result);
121 errno = _errno;
122 return result;
124 #endif
126 #if HAVE_GETPGID
127 int Getpgid(pid_t pid) {
128 pid_t result;
129 int _errno;
130 Debug1("getpgid("F_pid")", pid);
131 result = getpgid(pid);
132 _errno = errno;
133 Debug1("getpgid() -> "F_pid, result);
134 errno = _errno;
135 return result;
137 #endif
139 int Setpgid(pid_t pid, pid_t pgid) {
140 int result, _errno;
141 Debug2("setpgid("F_pid", "F_pid")", pid, pgid);
142 result = setpgid(pid, pgid);
143 _errno = errno;
144 Debug1("setpgid() -> %d", result);
145 errno = _errno;
146 return result;
149 pid_t Tcgetpgrp(int fd) {
150 int result, _errno;
151 Debug1("tcgetpgrp(%d)", fd);
152 result = tcgetpgrp(fd);
153 _errno = errno;
154 Debug1("tcgetpgrp() -> %d", result);
155 errno = _errno;
156 return result;
159 int Tcsetpgrp(int fd, pid_t pgrpid) {
160 int result, _errno;
161 Debug2("tcsetpgrp(%d, "F_pid")", fd, pgrpid);
162 result = tcsetpgrp(fd, pgrpid);
163 _errno = errno;
164 Debug1("tcsetpgrp() -> %d", result);
165 errno = _errno;
166 return result;
169 #if HAVE_GETSID
170 pid_t Getsid(pid_t pid) {
171 int result, _errno;
172 Debug1("getsid("F_pid")", pid);
173 result = getsid(pid);
174 _errno = errno;
175 Debug1("getsid() -> "F_pid, result);
176 errno = _errno;
177 return result;
179 #endif
181 pid_t Setsid(void) {
182 int result, _errno;
183 Debug("setsid()");
184 result = setsid();
185 _errno = errno;
186 Debug1("setsid() -> "F_pid, result);
187 errno = _errno;
188 return result;
191 uid_t Getuid(void) {
192 uid_t result;
193 int _errno;
194 Debug("getuid()");
195 result = getuid();
196 _errno = errno;
197 Debug1("getuid() -> "F_uid, result);
198 errno = _errno;
199 return result;
202 uid_t Geteuid(void) {
203 uid_t result;
204 int _errno;
205 Debug("geteuid()");
206 result = geteuid();
207 _errno = errno;
208 Debug1("geteuid() -> "F_uid, result);
209 errno = _errno;
210 return result;
213 int Setuid(uid_t uid) {
214 int result, _errno;
215 Debug1("setuid("F_uid")", uid);
216 result = setuid(uid);
217 _errno = errno;
218 Debug1("setuid() -> %d", result);
219 errno = _errno;
220 return result;
223 gid_t Getgid(void) {
224 gid_t result;
225 int _errno;
226 Debug("getgid()");
227 result = getgid();
228 _errno = errno;
229 Debug1("getgid() -> "F_gid, result);
230 errno = _errno;
231 return result;
234 gid_t Getegid(void) {
235 gid_t result;
236 int _errno;
237 Debug("getegid()");
238 result = getegid();
239 _errno = errno;
240 Debug1("getegid() -> "F_gid, result);
241 errno = _errno;
242 return result;
245 int Setgid(gid_t gid) {
246 int result, _errno;
247 Debug1("setgid("F_gid")", gid);
248 result = setgid(gid);
249 _errno = errno;
250 Debug1("setgid() -> %d", result);
251 errno = _errno;
252 return result;
255 int Initgroups(const char *user, gid_t group) {
256 int result, _errno;
257 Debug2("initgroups(\"%s\", "F_gid")", user, group);
258 result = initgroups(user, group);
259 _errno = errno;
260 Debug1("initgroups() -> %d", result);
261 errno = _errno;
262 return result;
265 int Getgroups(int size, gid_t list[]) {
266 int result, _errno;
267 Debug2("getgroups(%d, "F_gid",...)", size, list[0]);
268 result = getgroups(size, list);
269 _errno = errno;
270 Debug1("getgroups() -> %d", result);
271 errno = _errno;
272 return result;
275 #if HAVE_SETGROUPS
276 int Setgroups(size_t size, const gid_t *list) {
277 int result, _errno;
278 Debug2("setgroups("F_Zu", "F_gid",...)", size, list[0]);
279 result = setgroups(size, list);
280 _errno = errno;
281 Debug1("setgroups() -> %d", result);
282 errno = _errno;
283 return result;
285 #endif
287 int Chdir(const char *path) {
288 int result, _errno;
289 Debug1("chdir(\"%s\")", path);
290 result = chdir(path);
291 _errno = errno;
292 Debug1("chdir() -> %d", result);
293 errno = _errno;
294 return result;
297 int Chroot(const char *path) {
298 int result, _errno;
299 Debug1("chroot(\"%s\")", path);
300 result = chroot(path);
301 _errno = errno;
302 Debug1("chroot() -> %d", result);
303 errno = _errno;
304 return result;
307 int Gettimeofday(struct timeval *tv, struct timezone *tz) {
308 int result, _errno;
309 #if WITH_MSGLEVEL <= E_DEBUG
310 if (tz) {
311 Debug3("gettimeofday(%p, {%d,%d})",
312 tv, tz->tz_minuteswest, tz->tz_dsttime);
313 } else {
314 Debug1("gettimeofday(%p, NULL)", tv);
316 #endif /* WITH_MSGLEVEL <= E_DEBUG */
317 result = gettimeofday(tv, tz);
318 _errno = errno;
319 #if WITH_MSGLEVEL <= E_DEBUG
320 if (tz) {
321 Debug5("gettimeofday({%ld,%ld}, {%d,%d}) -> %d",
322 tv->tv_sec, tv->tv_usec, tz->tz_minuteswest, tz->tz_dsttime,
323 result);
324 } else {
325 Debug3("gettimeofday({%ld,%ld},) -> %d",
326 tv->tv_sec, tv->tv_usec, result);
328 #endif /* WITH_MSGLEVEL <= E_DEBUG */
329 errno = _errno;
330 return result;
333 int Mknod(const char *pathname, mode_t mode, dev_t dev) {
334 int result, _errno;
335 Debug3("mknod(\"%s\", 0%o, %d)", pathname, mode, dev);
336 result = mknod(pathname, mode, dev);
337 _errno = errno;
338 Debug1("mknod() -> %d", result);
339 errno = _errno;
340 return result;
343 int Mkfifo(const char *pathname, mode_t mode) {
344 int result, _errno;
345 Debug2("mkfifo(\"%s\", 0%o)", pathname, mode);
346 result = mkfifo(pathname, mode);
347 _errno = errno;
348 Debug1("mkfifo() -> %d", result);
349 errno = _errno;
350 return result;
353 static void prtstat(const char *func, struct stat *buf, int result) {
354 char txt[256], *t = txt;
356 t += sprintf(t, "%s(, {"F_st_dev","F_st_ino","F_mode","F_st_nlink","F_uid","F_gid,
357 func, buf->st_dev, buf->st_ino,
358 buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
359 #if HAVE_ST_RDEV
360 t += sprintf(t, ","F_st_dev, buf->st_rdev);
361 #endif
362 t += sprintf(t, ","F_st_size, buf->st_size);
363 #if HAVE_ST_BLKSIZE
364 t += sprintf(t, ","F_st_blksize, buf->st_blksize);
365 #endif
366 #if HAVE_ST_BLOCKS
367 t += sprintf(t, ","F_st_blocks, buf->st_blocks);
368 #endif
369 sprintf(t, ",...}) -> %d", result);
370 Debug(txt);
373 #if defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64)
374 static void prtstat64(const char *func, struct stat64 *buf, int result) {
375 char txt[256], *t = txt;
377 if (result < 0) {
378 sprintf(t, "%s(, {}) -> %d", func, result);
379 } else {
380 t += sprintf(t, "%s(, {"F_st_dev","F_st64_ino","F_mode","F_st_nlink","F_uid","F_gid,
381 func, buf->st_dev, buf->st_ino,
382 buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
383 #if HAVE_ST_RDEV
384 t += sprintf(t, ","F_st_dev, buf->st_rdev);
385 #endif
386 t += sprintf(t, ","F_st64_size, buf->st_size);
387 #if HAVE_ST_BLKSIZE
388 t += sprintf(t, ","F_st_blksize, buf->st_blksize);
389 #endif
390 #if HAVE_ST_BLOCKS
391 t += sprintf(t, ","F_st64_blocks, buf->st_blocks);
392 #endif
393 sprintf(t, ",...}) -> %d", result);
395 Debug(txt);
397 #endif /* defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64) */
399 int Stat(const char *file_name, struct stat *buf) {
400 int result, _errno;
401 Debug2("stat(%s, %p)", file_name, buf);
402 result = stat(file_name, buf);
403 _errno = errno;
404 prtstat("stat", buf, result);
405 errno = _errno;
406 return result;
409 #if HAVE_STAT64
410 int Stat64(const char *file_name, struct stat64 *buf) {
411 int result, _errno;
412 Debug2("stat64(%s, %p)", file_name, buf);
413 result = stat64(file_name, buf);
414 _errno = errno;
415 prtstat64("stat64", buf, result);
416 errno = _errno;
417 return result;
419 #endif /* HAVE_STAT64 */
421 int Fstat(int filedes, struct stat *buf) {
422 int result, _errno;
423 Debug2("fstat(%d, %p)", filedes, buf);
424 result = fstat(filedes, buf);
425 _errno = errno;
426 prtstat("fstat", buf, result);
427 errno = _errno;
428 return result;
431 #if HAVE_FSTAT64
432 int Fstat64(int filedes, struct stat64 *buf) {
433 int result, _errno;
434 Debug2("fstat64(%d, %p)", filedes, buf);
435 result = fstat64(filedes, buf);
436 _errno = errno;
437 prtstat64("fstat64", buf, result);
438 errno = _errno;
439 return result;
441 #endif /* HAVE_FSTAT64 */
443 int Lstat(const char *file_name, struct stat *buf) {
444 int result, _errno;
445 Debug2("lstat(%s, %p)", file_name, buf);
446 result = lstat(file_name, buf);
447 _errno = errno;
448 prtstat("lstat", buf, result);
449 errno = _errno;
450 return result;
453 #if HAVE_LSTAT64
454 int Lstat64(const char *file_name, struct stat64 *buf) {
455 int result, _errno;
456 Debug2("lstat64(%s, %p)", file_name, buf);
457 result = lstat64(file_name, buf);
458 _errno = errno;
459 prtstat64("lstat64", buf, result);
460 errno = _errno;
461 return result;
463 #endif /* HAVE_LSTAT64 */
465 int Dup(int oldfd) {
466 int newfd, _errno;
467 Debug1("dup(%d)", oldfd);
468 newfd = dup(oldfd);
469 _errno = errno;
470 Info2("dup(%d) -> %d", oldfd, newfd);
471 errno = _errno;
472 return newfd;
475 int Dup2(int oldfd, int newfd) {
476 int result, _errno;
477 Debug2("dup2(%d, %d)", oldfd, newfd);
478 result = dup2(oldfd, newfd);
479 _errno = errno;
480 Info3("dup2(%d, %d) -> %d", oldfd, newfd, result);
481 errno = _errno;
482 return result;
485 int Pipe(int filedes[2]) {
486 int result, _errno;
487 Debug1("pipe(%p)", filedes);
488 result = pipe(filedes);
489 _errno = errno;
490 Info3("pipe({%d,%d}) -> %d", filedes[0], filedes[1], result);
491 errno = _errno;
492 return result;
495 ssize_t Read(int fd, void *buf, size_t count) {
496 ssize_t result;
497 int _errno;
498 Debug3("read(%d, %p, "F_Zu")", fd, buf, count);
499 result = read(fd, buf, count);
500 _errno = errno;
501 Debug1("read -> "F_Zd, result);
502 errno = _errno;
503 return result;
506 ssize_t Write(int fd, const void *buf, size_t count) {
507 ssize_t result;
508 int _errno;
509 Debug3("write(%d, %p, "F_Zu")", fd, buf, count);
510 result = write(fd, buf, count);
511 _errno = errno;
512 Debug1("write -> "F_Zd, result);
513 errno = _errno;
514 return result;
517 int Fcntl(int fd, int cmd) {
518 int result, _errno;
519 Debug2("fcntl(%d, %d)", fd, cmd);
520 result = fcntl(fd, cmd);
521 _errno = errno;
522 Debug1("fcntl() -> %d", result);
523 errno = _errno;
524 return result;
527 int Fcntl_l(int fd, int cmd, long arg) {
528 int result, _errno;
529 Debug3("fcntl(%d, %d, %ld)", fd, cmd, arg);
530 result = fcntl(fd, cmd, arg);
531 _errno = errno;
532 Debug1("fcntl() -> %d", result);
533 errno = _errno;
534 return result;
537 int Fcntl_lock(int fd, int cmd, struct flock *l) {
538 int result, _errno;
539 Debug7("fcntl(%d, %d, {type=%hd,whence=%hd,start="F_off",len="F_off",pid="F_pid"})",
540 fd, cmd, l->l_type, l->l_whence, l->l_start, l->l_len, l->l_pid);
541 result = fcntl(fd, cmd, l);
542 _errno = errno;
543 Debug1("fcntl() -> %d", result);
544 errno = _errno;
545 return result;
548 int Ftruncate(int fd, off_t length) {
549 int retval, _errno;
550 Debug2("ftruncate(%d, "F_off")", fd, length);
551 retval = ftruncate(fd, length);
552 _errno = errno;
553 Debug1("ftruncate() -> %d", retval);
554 errno = _errno;
555 return retval;
558 #if HAVE_FTRUNCATE64
559 int Ftruncate64(int fd, off64_t length) {
560 int retval, _errno;
561 Debug2("ftruncate64(%d, "F_off64")", fd, length);
562 retval = ftruncate64(fd, length);
563 _errno = errno;
564 Debug1("ftruncate64() -> %d", retval);
565 errno = _errno;
566 return retval;
568 #endif /* HAVE_FTRUNCATE64 */
570 #if HAVE_FLOCK
571 int Flock(int fd, int operation) {
572 int retval, _errno;
573 Debug2("flock(%d, %d)", fd, operation);
574 retval = flock(fd, operation);
575 _errno = errno;
576 Debug1("flock() -> %d", retval);
577 errno = _errno;
578 return retval;
580 #endif /* HAVE_FLOCK */
582 int Ioctl(int d, int request, void *argp) {
583 int retval, _errno;
584 if (argp > (void *)0x10000) { /* fuzzy...*/
585 Debug4("ioctl(%d, 0x%x, %p{%lu})", d, request, argp, *(unsigned long *)argp);
586 } else {
587 Debug3("ioctl(%d, 0x%x, 0x%p)", d, request, argp);
589 retval = ioctl(d, request, argp);
590 _errno = errno;
591 Debug1("ioctl() -> %d", retval);
592 errno = _errno;
593 return retval;
596 int Ioctl_int(int d, int request, int arg) {
597 int retval, _errno;
598 Debug3("ioctl(%d, 0x%x, %d)", d, request, arg);
599 retval = ioctl(d, request, arg);
600 _errno = errno;
601 Debug1("ioctl() -> %d", retval);
602 errno = _errno;
603 return retval;
606 int Close(int fd) {
607 int retval, _errno;
608 Info1("close(%d)", fd);
609 retval = close(fd);
610 _errno = errno;
611 Debug1("close() -> %d", retval);
612 errno = _errno;
613 return retval;
616 int Fchown(int fd, uid_t owner, gid_t group) {
617 int retval, _errno;
618 Debug3("fchown(%d, "F_uid", "F_gid")", fd, owner, group);
619 retval = fchown(fd, owner, group);
620 _errno = errno;
621 Debug1("fchown() -> %d", retval);
622 errno = _errno;
623 return retval;
626 int Fchmod(int fd, mode_t mode) {
627 int retval, _errno;
628 Debug2("fchmod(%d, 0%o)", fd, mode);
629 retval = fchmod(fd, mode);
630 _errno = errno;
631 Debug1("fchmod() -> %d", retval);
632 errno = _errno;
633 return retval;
636 int Unlink(const char *pathname) {
637 int retval, _errno;
638 Debug1("unlink(\"%s\")", pathname);
639 retval = unlink(pathname);
640 _errno = errno;
641 Debug1("unlink() -> %d", retval);
642 errno = _errno;
643 return retval;
646 int Symlink(const char *oldpath, const char *newpath) {
647 int retval, _errno;
648 Debug2("symlink(\"%s\", \"%s\")", oldpath, newpath);
649 retval = symlink(oldpath, newpath);
650 _errno = errno;
651 Debug1("symlink() -> %d", retval);
652 errno = _errno;
653 return retval;
656 int Readlink(const char *path, char *buf, size_t bufsiz) {
657 int retval, _errno;
658 Debug3("readlink(\"%s\", %p, "F_Zu")", path, buf, bufsiz);
659 retval = readlink(path, buf, bufsiz);
660 _errno = errno;
661 Debug1("readlink() -> %d", retval);
662 errno = _errno;
663 return retval;
666 int Chown(const char *path, uid_t owner, gid_t group) {
667 int retval, _errno;
668 Debug3("chown(\"%s\", "F_uid", "F_gid")", path, owner, group);
669 retval = chown(path, owner, group);
670 _errno = errno;
671 Debug1("chown() -> %d", retval);
672 errno = _errno;
673 return retval;
676 int Chmod(const char *path, mode_t mode) {
677 int retval, _errno;
678 Debug2("chmod(\"%s\", 0%o)", path, mode);
679 retval = chmod(path, mode);
680 _errno = errno;
681 Debug1("chmod() -> %d", retval);
682 errno = _errno;
683 return retval;
686 #if HAVE_POLL
687 /* we only show the first struct pollfd; hope this is enough for most cases. */
688 int Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
689 int result;
690 if (nfds == 4) {
691 Debug10("poll({%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}, %u, %d)",
692 ufds[0].fd, ufds[0].events, ufds[1].fd, ufds[1].events,
693 ufds[2].fd, ufds[2].events, ufds[3].fd, ufds[3].events,
694 nfds, timeout);
695 } else {
696 Debug4("poll({%d,0x%02hx,}, , %u, %d)", ufds[0].fd, ufds[0].events, nfds, timeout);
698 result = poll(ufds, nfds, timeout);
699 if (nfds == 4) {
700 Debug5("poll(, {,,0x%02hx}{,,0x%02hx}{,,0x%02hx}{,,0x%02hx}) -> %d",
701 ufds[0].revents, ufds[1].revents, ufds[2].revents, ufds[3].revents, result);
702 } else {
703 Debug2("poll(, {,,0x%02hx}) -> %d", ufds[0].revents, result);
705 return result;
707 #endif /* HAVE_POLL */
709 /* we only show the first word of the fd_set's; hope this is enough for most
710 cases. */
711 int Select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
712 struct timeval *timeout) {
713 int result, _errno;
714 #if HAVE_FDS_BITS
715 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu."F_tv_usec")",
716 n, readfds->fds_bits[0], writefds->fds_bits[0],
717 exceptfds->fds_bits[0],
718 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
719 timeout?timeout->tv_usec:0);
720 #else
721 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu.%06u)",
722 n, readfds->__fds_bits[0], writefds->__fds_bits[0],
723 exceptfds->__fds_bits[0],
724 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
725 timeout?timeout->tv_usec:0);
726 #endif
727 result = select(n, readfds, writefds, exceptfds, timeout);
728 _errno = errno;
729 #if HAVE_FDS_BITS
730 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu."F_tv_usec"), %d",
731 readfds->fds_bits[0], writefds->fds_bits[0], exceptfds->fds_bits[0],
732 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
733 timeout?timeout->tv_usec:0, result);
734 #else
735 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu.%06u), %d",
736 readfds->__fds_bits[0], writefds->__fds_bits[0],
737 exceptfds->__fds_bits[0],
738 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
739 timeout?timeout->tv_usec:0, result);
740 #endif
741 errno = _errno;
742 return result;
745 pid_t Fork(void) {
746 pid_t pid;
747 int _errno;
748 Debug("fork()");
749 pid = fork();
750 _errno = errno;
751 Debug1("fork() -> %d", pid); /* attention: called twice! */
752 errno = _errno;
753 return pid;
756 pid_t Waitpid(pid_t pid, int *status, int options) {
757 int _errno;
758 pid_t retval;
759 Debug3("waitpid("F_pid", %p, %d)", pid, status, options);
760 retval = waitpid(pid, status, options);
761 _errno = errno;
762 Debug2("waitpid(, {%d}, ) -> "F_pid, *status, retval);
763 errno = _errno;
764 return retval;
767 sighandler_t Signal(int signum, sighandler_t handler) {
768 int _errno;
769 sighandler_t retval;
770 Debug2("signal(%d, %p)", signum, handler);
771 retval = signal(signum, handler);
772 _errno = errno;
773 Debug1("signal() -> %p", retval);
774 errno = _errno;
775 return retval;
778 #if HAVE_SIGACTION
779 int Sigaction(int signum, const struct sigaction *act,
780 struct sigaction *oldact) {
781 int retval;
782 Debug3("sigaction(%d, %p, %p)", signum, act, oldact);
783 retval = sigaction(signum, act, oldact);
784 Debug1("sigaction() -> %d", retval);
785 return retval;
787 #endif /* HAVE_SIGACTION */
789 int Sigprocmask(int how, const sigset_t *set, sigset_t *oset) {
790 int retval;
791 Debug3("sigprocmask(%d, %p, %p)", how, set, oset);
792 retval = sigprocmask(how, set, oset);
793 Debug1("sigprocmask() -> %d", retval);
794 return retval;
797 unsigned int Alarm(unsigned int seconds) {
798 unsigned int retval;
799 Debug1("alarm(%u)", seconds);
800 retval = alarm(seconds);
801 Debug1("alarm() -> %u", retval);
802 return retval;
805 int Kill(pid_t pid, int sig) {
806 int retval, _errno;
807 Debug2("kill("F_pid", %d)", pid, sig);
808 retval = kill(pid, sig);
809 _errno = errno;
810 Debug1("kill() -> %d", retval);
811 errno = _errno;
812 return retval;
815 int Link(const char *oldpath, const char *newpath) {
816 int retval, _errno;
817 Debug2("link(\"%s\", \"%s\")", oldpath, newpath);
818 retval = link(oldpath, newpath);
819 _errno = errno;
820 Debug1("link() -> %d", retval);
821 errno = _errno;
822 return retval;
825 int Execvp(const char *file, char *const argv[]) {
826 int result, _errno;
827 if (argv[1] == NULL)
828 Debug2("execvp(\"%s\", \"%s\")", file, argv[0]);
829 else if (argv[2] == NULL)
830 Debug3("execvp(\"%s\", \"%s\" \"%s\")", file, argv[0], argv[1]);
831 else if (argv[3] == NULL)
832 Debug4("execvp(\"%s\", \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2]);
833 else if (argv[4] == NULL)
834 Debug5("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3]);
835 else if (argv[5] == NULL)
836 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
837 else
838 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" ...)", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
840 result = execvp(file, argv);
841 _errno = errno;
842 Debug1("execvp() -> %d", result);
843 errno = _errno;
844 return result;
847 int System(const char *string) {
848 int result, _errno;
849 Debug1("system(\"%s\")", string);
850 result = system(string);
851 _errno = errno;
852 Debug1("system() -> %d", result);
853 errno = _errno;
854 return result;
857 int Socketpair(int d, int type, int protocol, int sv[2]) {
858 int result, _errno;
859 Debug4("socketpair(%d, %d, %d, %p)", d, type, protocol, sv);
860 result = socketpair(d, type, protocol, sv);
861 _errno = errno;
862 Info6("socketpair(%d, %d, %d, {%d,%d}) -> %d", d, type, protocol, sv[0], sv[1], result);
863 errno = _errno;
864 return result;
867 #if _WITH_SOCKET
868 int Socket(int domain, int type, int protocol) {
869 int result, _errno;
870 Debug3("socket(%d, %d, %d)", domain, type, protocol);
871 result = socket(domain, type, protocol);
872 _errno = errno;
873 Info4("socket(%d, %d, %d) -> %d", domain, type, protocol, result);
874 errno = _errno;
875 return result;
877 #endif /* _WITH_SOCKET */
879 #if _WITH_SOCKET
880 int Bind(int sockfd, struct sockaddr *my_addr, int addrlen) {
881 int result, _errno;
882 char infobuff[256];
884 sockaddr_info(my_addr, addrlen, infobuff, sizeof(infobuff));
885 Debug3("bind(%d, %s, "F_Zd")", sockfd, infobuff, addrlen);
886 result = bind(sockfd, my_addr, addrlen);
887 _errno = errno;
888 Debug1("bind() -> %d", result);
889 errno = _errno;
890 return result;
892 #endif /* _WITH_SOCKET */
894 #if _WITH_SOCKET
895 int Connect(int sockfd, const struct sockaddr *serv_addr, int addrlen) {
896 int result, _errno;
897 char infobuff[256];
899 /*sockaddr_info(serv_addr, infobuff, sizeof(infobuff));
900 Debug3("connect(%d, %s, "F_Zd")", sockfd, infobuff, addrlen);*/
901 #if 0
902 Debug18("connect(%d,{0x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x}, "F_Zd")",
903 sockfd,
904 ((unsigned char *)serv_addr)[0], ((unsigned char *)serv_addr)[1],
905 ((unsigned char *)serv_addr)[2], ((unsigned char *)serv_addr)[3],
906 ((unsigned char *)serv_addr)[4], ((unsigned char *)serv_addr)[5],
907 ((unsigned char *)serv_addr)[6], ((unsigned char *)serv_addr)[7],
908 ((unsigned char *)serv_addr)[8], ((unsigned char *)serv_addr)[9],
909 ((unsigned char *)serv_addr)[10], ((unsigned char *)serv_addr)[11],
910 ((unsigned char *)serv_addr)[12], ((unsigned char *)serv_addr)[13],
911 ((unsigned char *)serv_addr)[14], ((unsigned char *)serv_addr)[15],
912 addrlen);
913 #else
914 Debug4("connect(%d, {%d,%s}, "F_Zd")",
915 sockfd, serv_addr->sa_family,
916 sockaddr_info(serv_addr, addrlen, infobuff, sizeof(infobuff)),
917 addrlen);
918 #endif
919 result = connect(sockfd, serv_addr, addrlen);
920 _errno = errno;
921 Debug1("connect() -> %d", result);
922 errno = _errno;
923 return result;
925 #endif /* _WITH_SOCKET */
927 #if _WITH_SOCKET
928 int Listen(int s, int backlog) {
929 int result, _errno;
930 Debug2("listen(%d, %d)", s, backlog);
931 result = listen(s, backlog);
932 _errno = errno;
933 Debug1("listen() -> %d", result);
934 errno = _errno;
935 return result;
937 #endif /* _WITH_SOCKET */
939 #if _WITH_SOCKET
940 /* don't forget to handle EINTR when using Accept() ! */
941 int Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
942 int result, _errno;
944 Debug3("accept(%d, %p, %p)", s, addr, addrlen);
945 result = accept(s, addr, addrlen);
946 _errno = errno;
947 if (result >= 0) {
948 char infobuff[256];
949 sockaddr_info(addr, *addrlen, infobuff, sizeof(infobuff));
950 Info5("accept(%d, {%d, %s}, "F_Zd") -> %d", s,
951 addr->sa_family,
952 sockaddr_info(addr, *addrlen, infobuff, sizeof(infobuff)),
953 *addrlen, result);
954 } else {
955 Debug1("accept(,,) -> %d", result);
957 errno = _errno;
958 return result;
960 #endif /* _WITH_SOCKET */
962 #if _WITH_SOCKET
963 int Getsockname(int s, struct sockaddr *name, socklen_t *namelen) {
964 int result, _errno;
965 char infobuff[256];
967 Debug4("getsockname(%d, %p, %p{"F_socklen"})", s, name, namelen, *namelen);
968 result = getsockname(s, name, namelen);
969 _errno = errno;
970 /*Debug2("getsockname(,, {"F_socklen"}) -> %d",
971 *namelen, result);*/
972 Debug3("getsockname(, {%s}, {"F_socklen"}) -> %d",
973 sockaddr_info(name, *namelen, infobuff, sizeof(infobuff)),
974 *namelen, result);
975 errno = _errno;
976 return result;
978 #endif /* _WITH_SOCKET */
980 #if _WITH_SOCKET
981 int Getpeername(int s, struct sockaddr *name, socklen_t *namelen) {
982 int result, _errno;
983 char infobuff[256];
985 Debug4("getpeername(%d, %p, %p{"F_socklen"})", s, name, namelen, *namelen);
986 result = getpeername(s, name, namelen);
987 _errno = errno;
988 sockaddr_info(name, *namelen, infobuff, sizeof(infobuff));
989 Debug3("getpeername(, {%s}, {"F_socklen"}) -> %d",
990 infobuff, *namelen, result);
991 errno = _errno;
992 return result;
994 #endif /* _WITH_SOCKET */
996 #if _WITH_SOCKET
997 int Getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) {
998 int result, _errno;
999 Debug5("getsockopt(%d, %d, %d, %p, {"F_Zd"})",
1000 s, level, optname, optval, *optlen);
1001 result = getsockopt(s, level, optname, optval, optlen);
1002 _errno = errno;
1003 Debug3("getsockopt() -> (,,, 0x%08x, %d), %d",
1004 *(int *)optval, *optlen, result);
1005 errno = _errno;
1006 return result;
1008 #endif /* _WITH_SOCKET */
1010 #if _WITH_SOCKET
1011 int Setsockopt(int s, int level, int optname, const void *optval, int optlen) {
1012 int result, _errno;
1013 if (optlen <= sizeof(int)) {
1014 Debug5("setsockopt(%d, %d, %d, {0x%x}, %d)",
1015 s, level, optname, *(unsigned int *)optval, optlen);
1016 } else {
1017 Debug6("setsockopt(%d, %d, %d, {0x%08x,%08x}, %d)",
1018 s, level, optname,
1019 ((unsigned int *)optval)[0], ((unsigned int *)optval)[1],
1020 optlen);
1022 result = setsockopt(s, level, optname, optval, optlen);
1023 _errno = errno;
1024 Debug1("setsockopt() -> %d", result);
1025 errno = _errno;
1026 return result;
1028 #endif /* _WITH_SOCKET */
1030 #if _WITH_SOCKET
1031 int Recv(int s, void *buf, size_t len, int flags) {
1032 int retval, _errno;
1033 Debug4("recv(%d, %p, "F_Zu", %d)", s, buf, len, flags);
1034 retval = recv(s, buf, len, flags);
1035 _errno = errno;
1036 Debug1("recv() -> %d", retval);
1037 errno = _errno;
1038 return retval;
1040 #endif /* _WITH_SOCKET */
1042 #if _WITH_SOCKET
1043 int Recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from,
1044 socklen_t *fromlen) {
1045 int retval, _errno;
1046 char infobuff[256];
1047 Debug6("recvfrom(%d, %p, "F_Zu", %d, %p, "F_Zu")",
1048 s, buf, len, flags, from, *fromlen);
1049 retval = recvfrom(s, buf, len, flags, from, fromlen);
1050 _errno = errno;
1051 if (from) {
1052 Debug4("recvfrom(,,,, {%d,%s}, "F_Zd") -> %d",
1053 from->sa_family,
1054 sockaddr_info(from, *fromlen, infobuff, sizeof(infobuff)),
1055 *fromlen, retval);
1056 } else {
1057 Debug1("recvfrom(,,,, NULL, NULL) -> %d", retval);
1059 errno = _errno;
1060 return retval;
1062 #endif /* _WITH_SOCKET */
1064 #if _WITH_SOCKET
1065 int Recvmsg(int s, struct msghdr *msgh, int flags) {
1066 int retval, _errno;
1067 char infobuff[256];
1068 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROL) && defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN) && defined(HAVE_STRUCT_MSGHDR_MSGFLAGS)
1069 Debug10("recvmsg(%d, %p{%p,%u,%p,%u,%p,%u,%d}, %d)", s, msgh,
1070 msgh->msg_name, msgh->msg_namelen, msgh->msg_iov, msgh->msg_iovlen,
1071 msgh->msg_control, msgh->msg_controllen, msgh->msg_flags, flags);
1072 #else
1073 Debug7("recvmsg(%d, %p{%p,%u,%p,%u}, %d)", s, msgh,
1074 msgh->msg_name, msgh->msg_namelen, msgh->msg_iov, msgh->msg_iovlen,
1075 flags);
1076 #endif
1077 retval = recvmsg(s, msgh, flags);
1078 _errno = errno;
1079 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN)
1080 Debug5("recvmsg(, {%s,%u,,%u,,%u,}, ) -> %d",
1081 msgh->msg_name?sockaddr_info(msgh->msg_name, msgh->msg_namelen, infobuff, sizeof(infobuff)):"NULL",
1082 msgh->msg_namelen, msgh->msg_iovlen, msgh->msg_controllen,
1083 retval);
1084 #else
1085 Debug4("recvmsg(, {%s,%u,,%u,,}, ) -> %d",
1086 msgh->msg_name?sockaddr_info(msgh->msg_name, msgh->msg_namelen, infobuff, sizeof(infobuff)):"NULL",
1087 msgh->msg_namelen, msgh->msg_iovlen,
1088 retval);
1089 #endif
1090 errno = _errno;
1091 return retval;
1093 #endif /* _WITH_SOCKET */
1095 #if _WITH_SOCKET
1096 int Send(int s, const void *mesg, size_t len, int flags) {
1097 int retval, _errno;
1098 Debug5("send(%d, %p[%08x...], "F_Zu", %d)",
1099 s, mesg, ntohl(*(unsigned long *)mesg), len, flags);
1100 retval = send(s, mesg, len, flags);
1101 _errno = errno;
1102 Debug1("send() -> %d", retval);
1103 errno = _errno;
1104 return retval;
1106 #endif /* _WITH_SOCKET */
1108 #if _WITH_SOCKET
1109 int Sendto(int s, const void *mesg, size_t len, int flags,
1110 const struct sockaddr *to, socklen_t tolen) {
1111 int retval, _errno;
1112 char infobuff[256];
1114 sockaddr_info(to, tolen, infobuff, sizeof(infobuff));
1115 Debug7("sendto(%d, %p[%08x...], "F_Zu", %d, {%s}, %d)",
1116 s, mesg, htonl(*(unsigned long *)mesg), len, flags, infobuff, tolen);
1117 retval = sendto(s, mesg, len, flags, to, tolen);
1118 _errno = errno;
1119 Debug1("sendto() -> %d", retval);
1120 errno = _errno;
1121 return retval;
1123 #endif /* _WITH_SOCKET */
1125 #if _WITH_SOCKET
1126 int Shutdown(int fd, int how) {
1127 int retval, _errno;
1128 Info2("shutdown(%d, %d)", fd, how);
1129 retval = shutdown(fd, how);
1130 _errno = errno;
1131 Debug1("shutdown() -> %d", retval);
1132 errno = _errno;
1133 return retval;
1135 #endif /* _WITH_SOCKET */
1137 unsigned int Sleep(unsigned int seconds) {
1138 unsigned int retval;
1139 Debug1("sleep(%u)", seconds);
1140 retval = sleep(seconds);
1141 Debug1("sleep() -> %u", retval);
1142 return retval;
1145 void Usleep(unsigned long usec) {
1146 Debug1("usleep(%lu)", usec);
1147 usleep(usec);
1148 Debug("usleep() ->");
1149 return;
1152 #if HAVE_NANOSLEEP
1153 unsigned int Nanosleep(const struct timespec *req, struct timespec *rem) {
1154 int retval, _errno;
1155 Debug3("nanosleep({"F_time",%ld},%p)", req->tv_sec, req->tv_nsec, rem);
1156 retval = nanosleep(req, rem);
1157 _errno = errno;
1158 if (rem) {
1159 Debug3("nanosleep(,{"F_time",%ld}) -> %d",
1160 rem->tv_sec, rem->tv_nsec, retval);
1161 } else {
1162 Debug1("nanosleep() -> %d", retval);
1164 errno = _errno;
1165 return retval;
1167 #endif /* HAVE_NANOSLEEP */
1169 int Pause(void) {
1170 int retval, _errno;
1171 Debug("pause()");
1172 retval = pause();
1173 _errno = errno;
1174 Debug1("pause() -> %d", retval);
1175 errno = _errno;
1176 return retval;
1179 #if WITH_IP4 || WITH_IP6
1180 struct hostent *Gethostbyname(const char *name) {
1181 struct hostent *hent;
1182 Debug1("gethostbyname(\"%s\")", name);
1183 hent = gethostbyname(name);
1184 if (hent == NULL) {
1185 Debug("gethostbyname() -> NULL");
1186 } else {
1187 Debug4("gethostbyname() -> %d.%d.%d.%d",
1188 ((unsigned char *)hent->h_addr_list[0])[0],
1189 ((unsigned char *)hent->h_addr_list[0])[1],
1190 ((unsigned char *)hent->h_addr_list[0])[2],
1191 ((unsigned char *)hent->h_addr_list[0])[3]);
1193 return hent;
1195 #endif /* WITH_IP4 || WITH_IP6 */
1197 #if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
1198 int Getaddrinfo(const char *node, const char *service,
1199 const struct addrinfo *hints, struct addrinfo **res) {
1200 int result;
1201 Debug15("getaddrinfo(%s%s%s, %s%s%s, {%d,%d,%d,%d,"F_Zu",%p,%p,%p}, %p)",
1202 node?"\"":"", node?node:"NULL", node?"\"":"",
1203 service?"\"":"", service?service:"NULL", service?"\"":"",
1204 hints->ai_flags, hints->ai_family, hints->ai_socktype,
1205 hints->ai_protocol, hints->ai_addrlen, hints->ai_addr,
1206 hints->ai_canonname, hints->ai_next, res);
1207 result = getaddrinfo(node, service, hints, res);
1208 if (result == 0) {
1209 char sockbuff[256];
1210 sockaddr_info((*res)->ai_addr, hints->ai_addrlen, sockbuff, sizeof(sockbuff));
1211 Debug2("getaddrinfo(,,,{{%s, %s}) -> 0",
1212 sockbuff,
1213 (*res)->ai_canonname?(*res)->ai_canonname:"");
1214 } else {
1215 Debug2("getaddrinfo(,,,{%p}) -> %d", *res, result);
1217 return result;
1219 #endif /* (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO */
1221 #if (WITH_IP4 || WITH_IP6) && HAVE_GETIPNODEBYNAME
1222 struct hostent *Getipnodebyname(const char *name, int af, int flags,
1223 int *error_num) {
1224 struct hostent *result;
1225 Debug4("getipnodebyname(\"%s\", %d, %d, %p)", name, af, flags, error_num);
1226 result = getipnodebyname(name, af, flags, error_num);
1227 if (result == NULL) {
1228 Debug1("getipnodebyname(,,, {%d}) -> NULL", *error_num);
1229 } else {
1230 Debug4("getipnodebyname() -> {\"%s\", %p, %d, %d, ???}",
1231 result->h_name, result->h_aliases, result->h_addrtype,
1232 result->h_length);
1234 return result;
1236 #endif /* (WITH_IP4 || WITH_IP6) && HAVE_GETIPNODEBYNAME */
1238 void *Malloc(size_t size) {
1239 void *result;
1240 Debug1("malloc("F_Zd")", size);
1241 result = malloc(size);
1242 Debug1("malloc() -> %p", result);
1243 if (result == NULL) {
1244 Error1("malloc("F_Zd"): out of memory", size);
1245 return NULL;
1247 return result;
1250 void *Calloc(size_t nmemb, size_t size) {
1251 void *result;
1252 Debug2("calloc("F_Zd", "F_Zd")", nmemb, size);
1253 result = calloc(nmemb, size);
1254 Debug1("calloc() -> %p", result);
1255 if (result == NULL) {
1256 Error2("calloc("F_Zd", "F_Zd"): out of memory", nmemb, size);
1257 return NULL;
1259 return result;
1262 void *Realloc(void *ptr, size_t size) {
1263 void *result;
1264 Debug2("realloc(%p, "F_Zd")", ptr, size);
1265 result = realloc(ptr, size);
1266 Debug1("realloc() -> %p", result);
1267 if (result == NULL) {
1268 Error2("realloc(%p, "F_Zd"): out of memory", ptr, size);
1269 return NULL;
1271 return result;
1274 #if _WITH_TERMIOS
1275 int Tcgetattr(int fd, struct termios *termios_p) {
1276 int i, result, _errno;
1277 char chars[5*NCCS], *cp = chars;
1279 Debug2("tcgetattr(%d, %p)", fd, termios_p);
1280 result = tcgetattr(fd, termios_p);
1281 _errno = errno;
1283 for (i = 0; i < NCCS-1; ++i) {
1284 cp += sprintf(cp, "%02x,", termios_p->c_cc[i]);
1286 sprintf(cp, "%02x", termios_p->c_cc[i]);
1287 Debug6("tcgetattr(, {%08x,%08x,%08x,%08x,%s}) -> %d",
1288 termios_p->c_iflag, termios_p->c_oflag,
1289 termios_p->c_cflag, termios_p->c_lflag,
1290 chars, result);
1291 errno = _errno;
1292 return result;
1294 #endif /* _WITH_TERMIOS */
1296 #if _WITH_TERMIOS
1297 int Tcsetattr(int fd, int optional_actions, struct termios *termios_p) {
1298 int i, result, _errno;
1299 char chars[5*NCCS], *cp = chars;
1301 for (i = 0; i < NCCS-1; ++i) {
1302 cp += sprintf(cp, "%02x,", termios_p->c_cc[i]);
1304 sprintf(cp, "%02x", termios_p->c_cc[i]);
1305 Debug7("tcsetattr(%d, %d, {%08x,%08x,%08x,%08x,%s})", fd, optional_actions,
1306 termios_p->c_iflag, termios_p->c_oflag,
1307 termios_p->c_cflag, termios_p->c_lflag, chars);
1308 result = tcsetattr(fd, optional_actions, termios_p);
1309 _errno = errno;
1310 Debug1("tcsetattr() -> %d", result);
1311 errno = _errno;
1312 return result;
1314 #endif /* _WITH_TERMIOS */
1316 char *Ttyname(int fd) {
1317 char *result;
1318 int _errno;
1319 Debug1("ttyname(%d)", fd);
1320 result = ttyname(fd);
1321 _errno = errno;
1322 if (result)
1323 Debug1("ttyname() -> %s", result);
1324 else
1325 Debug("ttyname() -> NULL");
1326 errno = _errno;
1327 return result;
1330 int Isatty(int fd) {
1331 int result, _errno;
1332 Debug1("isatty(%d)", fd);
1333 result = isatty(fd);
1334 _errno = errno;
1335 Debug1("isatty() -> %d", result);
1336 errno = _errno;
1337 return result;
1340 #if HAVE_OPENPTY
1341 int Openpty(int *ptyfd, int *ttyfd, char *ptyname, struct termios *termp,
1342 struct winsize *winp) {
1343 int result, _errno;
1344 Debug5("openpty(%p, %p, %p, %p, %p)", ptyfd, ttyfd, ptyname, termp, winp);
1345 result = openpty(ptyfd, ttyfd, ptyname, termp, winp);
1346 _errno = errno;
1347 Info4("openpty({%d}, {%d}, {\"%s\"},,) -> %d", *ptyfd, *ttyfd, ptyname,
1348 result);
1349 errno = _errno;
1350 return result;
1352 #endif /* HAVE_OPENPTY */
1354 #if HAVE_GRANTPT
1355 int Grantpt(int fd) {
1356 int result, _errno;
1357 Debug1("grantpt(%d)", fd);
1358 result = grantpt(fd);
1359 _errno = errno;
1360 Debug1("grantpt() -> %d", result);
1361 errno = _errno;
1362 return result;
1364 #endif /* HAVE_GRANTPT */
1366 #if HAVE_UNLOCKPT
1367 int Unlockpt(int fd) {
1368 int result, _errno;
1369 Debug1("unlockpt(%d)", fd);
1370 result = unlockpt(fd);
1371 _errno = errno;
1372 Debug1("unlockpt() -> %d", result);
1373 errno = _errno;
1374 return result;
1376 #endif /* HAVE_UNLOCKPT */
1378 #if HAVE_PTSNAME /* AIX, not Linux */
1379 char *Ptsname(int fd) {
1380 char *result;
1381 int _errno;
1382 Debug1("ptsname(%d)", fd);
1383 result = ptsname(fd);
1384 _errno = errno;
1385 if (result)
1386 Debug1("ptsname() -> %s", result);
1387 else
1388 Debug("ptsname() -> NULL");
1389 errno = _errno;
1390 return result;
1392 #endif /* HAVE_PTSNAME */
1394 int Uname(struct utsname *buf) {
1395 int result, _errno;
1396 Debug1("uname(%p)", buf);
1397 result = uname(buf);
1398 _errno = errno;
1399 #if UNAME_DOMAINNAME
1400 Debug6("uname({%s, %s, %s, %s, %s, %s})",
1401 buf->sysname, buf->nodename, buf->release,
1402 buf->version, buf->machine, buf->domainname);
1403 #else
1404 Debug5("uname({%s, %s, %s, %s, %s})",
1405 buf->sysname, buf->nodename, buf->release,
1406 buf->version, buf->machine);
1407 #endif
1408 errno = _errno;
1409 return result;
1412 int Gethostname(char *name, size_t len) {
1413 int result, _errno;
1414 Debug2("gethostname(%p, "F_Zu")", name, len);
1415 result = gethostname(name, len);
1416 _errno = errno;
1417 Debug2("gethostname(\"%s\", ) -> %d", name, result);
1418 errno = _errno;
1419 return result;
1422 /* due to Linux docu, it does not set errno */
1423 int Atexit(void (*func)(void)) {
1424 int result;
1425 Debug1("atexit(%p)", func);
1426 result = atexit(func);
1427 Debug1("atexit() -> %d", result);
1428 return result;
1432 void Exit(int status) {
1433 Debug1("exit(%d)", status);
1434 exit(status);
1437 void Abort(void) {
1438 Debug("abort()");
1439 abort();
1442 int Mkstemp(char *template) {
1443 int result, _errno;
1444 Debug1("mkstemp(\"%s\")", template);
1445 result = mkstemp(template);
1446 _errno = errno;
1447 Info2("mkstemp({%s}) -> %d", template, result);
1448 errno = _errno;
1449 return result;
1452 int Setenv(const char *name, const char *value, int overwrite) {
1453 int result, _errno;
1454 Debug3("setenv(\"%s\", \"%s\", %d)", name, value, overwrite);
1455 result = setenv(name, value, overwrite);
1456 _errno = errno;
1457 Debug1("setenv() -> %d", result);
1458 errno = _errno;
1459 return result;
1462 #if HAVE_UNSETENV
1463 /* on Linux it returns int but on FreeBSD void.
1464 we do not expect many errors, so we take void which works on all systems. */
1465 void Unsetenv(const char *name) {
1466 int _errno;
1467 Debug1("unsetenv(\"%s\")", name);
1468 unsetenv(name);
1469 _errno = errno;
1470 Debug("unsetenv() ->");
1471 errno = _errno;
1472 return;
1474 #endif
1476 #if WITH_READLINE
1478 char *Readline(const char *prompt) {
1479 char *result;
1481 if (prompt) {
1482 Debug1("readline(\"%s\")", prompt);
1483 } else {
1484 Debug("readline(NULL)");
1486 result = readline(prompt);
1487 if (result) {
1488 Debug("readline() -> \"...\"");
1489 } else {
1490 Debug("readline() -> NULL");
1492 return result;
1495 void Using_history(void) {
1496 Debug("using_history()");
1497 using_history();
1498 Debug("using_history() ->");
1501 int Read_history(const char *filename) {
1502 int result;
1504 if (filename) {
1505 Debug1("read_history(\"%s\")", filename);
1506 } else {
1507 Debug("read_history(NULL)");
1509 result = read_history(filename);
1510 if (result) {
1511 Debug1("read_history() -> %d", result);
1512 } else {
1513 Debug("read_history() -> 0");
1515 return result;
1518 int Write_history(const char *filename) {
1519 int result;
1521 if (filename) {
1522 Debug1("write_history(\"%s\")", filename);
1523 } else {
1524 Debug("write_history(NULL)");
1526 result = write_history(filename);
1527 if (result) {
1528 Debug1("write_history() -> %d", result);
1529 } else {
1530 Debug("write_history() -> 0");
1532 return result;
1535 int Append_history(int nelements, const char *filename) {
1536 int result;
1538 if (filename) {
1539 Debug2("append_history(%d, \"%s\")", nelements, filename);
1540 } else {
1541 Debug1("append_history(%d, NULL)", nelements);
1543 result = append_history(nelements, filename);
1544 if (result) {
1545 Debug1("append_history() -> %d", result);
1546 } else {
1547 Debug("append_history() -> 0");
1549 return result;
1552 int Where_history(void) {
1553 int result;
1555 Debug("where_history()");
1556 result = where_history();
1557 Debug1("where_history() -> %d", result);
1558 return result;
1561 void Add_history(const char *string) {
1562 Debug1("add_history(\"%s\")", string);
1563 add_history(string);
1564 Debug("add_history() ->");
1567 #endif /* WITH_READLINE */
1569 #endif /* WITH_SYCLS */