Solve a problem with overlapping socket and openssl parameters
[socat.git] / sycls.c
blob249a3aec5c4549447a06b3fb72521d30b5ad8c30
1 /* source: sycls.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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 #include "sysincludes.h"
13 #include "mytypes.h"
14 #include "compat.h"
15 #include "errno.h"
17 #include "error.h"
18 #include "filan.h"
19 #include "utils.h"
20 #include "sysutils.h"
21 #include "sycls.h"
24 #if WITH_SYCLS
26 #if HAVE_PROTOTYPE_LIB_posix_memalign
27 int Posix_memalign(void **memptr, size_t alignment, size_t size) {
28 int result;
29 Debug3("posix_memalign(%p, "F_Zu", "F_Zu")", memptr, alignment, size);
30 result = posix_memalign(memptr, alignment, size);
31 Debug1("posix_memalign(...) -> %d", result);
32 return result;
34 #endif /* HAVE_PROTOTYPE_LIB_posix_memalign */
36 mode_t Umask(mode_t mask) {
37 mode_t result;
38 int _errno;
39 Debug1("umask("F_mode")", mask);
40 result = umask(mask);
41 _errno = errno;
42 Debug1("umask() -> "F_mode, result);
43 errno = _errno;
44 return result;
47 #endif /* WITH_SYCLS */
50 int Open(const char *pathname, int flags, mode_t mode) {
51 int result, _errno;
52 if (!diag_in_handler) diag_flush();
53 #if WITH_SYCLS
54 Debug3("open(\"%s\", 0%o, 0%03o)", pathname, flags, mode);
55 #endif /* WITH_SYCLS */
56 result = open(pathname, flags, mode);
57 _errno = errno;
58 if (!diag_in_handler) diag_flush();
59 #if WITH_SYCLS
60 Info4("open(\"%s\", 0%o, 0%03o) -> %d", pathname, flags, mode, result);
61 #endif /* WITH_SYCLS */
62 errno = _errno;
63 return result;
66 #if WITH_SYCLS
68 int Creat(const char *pathname, mode_t mode) {
69 int result, _errno;
70 Debug2("creat(\"%s\", 0%03o)", pathname, mode);
71 result = creat(pathname, mode);
72 _errno = errno;
73 Info3("creat(\"%s\", 0%03o) -> %d", pathname, mode, result);
74 errno = _errno;
75 return result;
78 off_t Lseek(int fildes, off_t offset, int whence) {
79 int _errno;
80 off_t result;
81 Debug3("lseek(%d, "F_off", %d)", fildes, offset, whence);
82 result = lseek(fildes, offset, whence);
83 _errno = errno;
84 Debug1("lseek() -> "F_off, result);
85 errno = _errno;
86 return result;
89 #if HAVE_LSEEK64
90 off64_t Lseek64(int fildes, off64_t offset, int whence) {
91 int _errno;
92 off64_t result;
93 Debug3("lseek64(%d, "F_off64", %d)", fildes, offset, whence);
94 result = lseek64(fildes, offset, whence);
95 _errno = errno;
96 Debug1("lseek64() -> "F_off64, result);
97 errno = _errno;
98 return result;
100 #endif /* HAVE_LSEEK64 */
102 pid_t Getpid(void) {
103 pid_t result;
104 int _errno;
105 Debug("getpid()");
106 result = getpid();
107 _errno = errno;
108 Debug1("getpid() -> "F_pid, result);
109 errno = _errno;
110 return result;
113 pid_t Getppid(void) {
114 pid_t result;
115 int _errno;
116 Debug("getppid()");
117 result = getppid();
118 _errno = errno;
119 Debug1("getppid() -> "F_pid, result);
120 errno = _errno;
121 return result;
124 pid_t Getpgrp(void) {
125 pid_t result;
126 int _errno;
127 Debug("getpgrp()");
128 result = getpgrp();
129 _errno = errno;
130 Debug1("getpgrp() -> "F_pid, result);
131 errno = _errno;
132 return result;
135 #if 0 /* does not compile for FreeBSD */
136 /* setpgrp() is not BSD compatible, needs setpgid(..., ...) instead */
137 int Setpgrp(void) {
138 int result, _errno;
139 Debug("setpgrp()");
140 result = setpgrp();
141 _errno = errno;
142 Debug1("setpgrp() -> %d", result);
143 errno = _errno;
144 return result;
146 #endif
148 #if HAVE_GETPGID
149 int Getpgid(pid_t pid) {
150 pid_t result;
151 int _errno;
152 Debug1("getpgid("F_pid")", pid);
153 result = getpgid(pid);
154 _errno = errno;
155 Debug1("getpgid() -> "F_pid, result);
156 errno = _errno;
157 return result;
159 #endif
161 int Setpgid(pid_t pid, pid_t pgid) {
162 int result, _errno;
163 Debug2("setpgid("F_pid", "F_pid")", pid, pgid);
164 result = setpgid(pid, pgid);
165 _errno = errno;
166 Debug1("setpgid() -> %d", result);
167 errno = _errno;
168 return result;
171 pid_t Tcgetpgrp(int fd) {
172 int result, _errno;
173 Debug1("tcgetpgrp(%d)", fd);
174 result = tcgetpgrp(fd);
175 _errno = errno;
176 Debug1("tcgetpgrp() -> %d", result);
177 errno = _errno;
178 return result;
181 int Tcsetpgrp(int fd, pid_t pgrpid) {
182 int result, _errno;
183 Debug2("tcsetpgrp(%d, "F_pid")", fd, pgrpid);
184 result = tcsetpgrp(fd, pgrpid);
185 _errno = errno;
186 Debug1("tcsetpgrp() -> %d", result);
187 errno = _errno;
188 return result;
191 #if HAVE_GETSID
192 pid_t Getsid(pid_t pid) {
193 int result, _errno;
194 Debug1("getsid("F_pid")", pid);
195 result = getsid(pid);
196 _errno = errno;
197 Debug1("getsid() -> "F_pid, result);
198 errno = _errno;
199 return result;
201 #endif
203 pid_t Setsid(void) {
204 int result, _errno;
205 Debug("setsid()");
206 result = setsid();
207 _errno = errno;
208 Debug1("setsid() -> "F_pid, result);
209 errno = _errno;
210 return result;
213 uid_t Getuid(void) {
214 uid_t result;
215 int _errno;
216 Debug("getuid()");
217 result = getuid();
218 _errno = errno;
219 Debug1("getuid() -> "F_uid, result);
220 errno = _errno;
221 return result;
224 uid_t Geteuid(void) {
225 uid_t result;
226 int _errno;
227 Debug("geteuid()");
228 result = geteuid();
229 _errno = errno;
230 Debug1("geteuid() -> "F_uid, result);
231 errno = _errno;
232 return result;
235 int Setuid(uid_t uid) {
236 int result, _errno;
237 Debug1("setuid("F_uid")", uid);
238 result = setuid(uid);
239 _errno = errno;
240 Debug1("setuid() -> %d", result);
241 errno = _errno;
242 return result;
245 gid_t Getgid(void) {
246 gid_t result;
247 int _errno;
248 Debug("getgid()");
249 result = getgid();
250 _errno = errno;
251 Debug1("getgid() -> "F_gid, result);
252 errno = _errno;
253 return result;
256 gid_t Getegid(void) {
257 gid_t result;
258 int _errno;
259 Debug("getegid()");
260 result = getegid();
261 _errno = errno;
262 Debug1("getegid() -> "F_gid, result);
263 errno = _errno;
264 return result;
267 int Setgid(gid_t gid) {
268 int result, _errno;
269 Debug1("setgid("F_gid")", gid);
270 result = setgid(gid);
271 _errno = errno;
272 Debug1("setgid() -> %d", result);
273 errno = _errno;
274 return result;
277 int Initgroups(const char *user, gid_t group) {
278 int result, _errno;
279 Debug2("initgroups(\"%s\", "F_gid")", user, group);
280 result = initgroups(user, group);
281 _errno = errno;
282 Debug1("initgroups() -> %d", result);
283 errno = _errno;
284 return result;
287 int Getgroups(int size, gid_t list[]) {
288 int result, _errno;
289 Debug2("getgroups(%d, "F_gid",...)", size, list[0]);
290 result = getgroups(size, list);
291 _errno = errno;
292 Debug1("getgroups() -> %d", result);
293 errno = _errno;
294 return result;
297 #if HAVE_SETGROUPS
298 int Setgroups(size_t size, const gid_t *list) {
299 int result, _errno;
300 switch (size) {
301 case 0: Debug1("setgroups("F_Zu", [])", size); break;;
302 case 1: Debug2("setgroups("F_Zu", ["F_gid"])", size, list[0]); break;;
303 case 2: Debug3("setgroups("F_Zu", ["F_gid","F_gid"])", size, list[0], list[1]); break;;
304 default: Debug3("setgroups("F_Zu", ["F_gid","F_gid",...])", size, list[0], list[1]); break;;
306 result = setgroups(size, list);
307 _errno = errno;
308 Debug1("setgroups() -> %d", result);
309 errno = _errno;
310 return result;
312 #endif
314 #if HAVE_GETGROUPLIST
315 int Getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) {
316 int n = *ngroups, result;
317 Debug4("getgrouplist(\"%s\", "F_gid", %p, [%d])", user, group, groups, n);
318 result = getgrouplist(user, group, groups, ngroups);
319 switch (Min(n,*ngroups)) {
320 case 0: Debug2("getgrouplist(,, [], [%d]) -> %d", *ngroups, result); break;
321 case 1: Debug3("getgrouplist(,, ["F_gid"], [%d]) -> %d", groups[0], *ngroups, result); break;
322 case 2: Debug4("getgrouplist(,, ["F_gid","F_gid"], [%d]) -> %d", groups[0], groups[1], *ngroups, result); break;
323 default: Debug4("getgrouplist(,, ["F_gid","F_gid",...], [%d]) -> %d", groups[0], groups[1], *ngroups, result); break;
325 return result;
327 #endif
329 int Chdir(const char *path) {
330 int result, _errno;
331 Debug1("chdir(\"%s\")", path);
332 result = chdir(path);
333 _errno = errno;
334 Debug1("chdir() -> %d", result);
335 errno = _errno;
336 return result;
339 int Chroot(const char *path) {
340 int result, _errno;
341 Debug1("chroot(\"%s\")", path);
342 result = chroot(path);
343 _errno = errno;
344 Debug1("chroot() -> %d", result);
345 errno = _errno;
346 return result;
349 int Gettimeofday(struct timeval *tv, struct timezone *tz) {
350 int result, _errno;
351 #if WITH_MSGLEVEL <= E_DEBUG
352 if (tz) {
353 Debug3("gettimeofday(%p, {%d,%d})",
354 tv, tz->tz_minuteswest, tz->tz_dsttime);
355 } else {
356 Debug1("gettimeofday(%p, NULL)", tv);
358 #endif /* WITH_MSGLEVEL <= E_DEBUG */
359 result = gettimeofday(tv, tz);
360 #if WITH_MSGLEVEL <= E_DEBUG
361 _errno = errno;
362 if (tz) {
363 Debug5("gettimeofday({%ld,%ld}, {%d,%d}) -> %d",
364 tv->tv_sec, tv->tv_usec, tz->tz_minuteswest, tz->tz_dsttime,
365 result);
366 } else {
367 Debug3("gettimeofday({%ld,%ld},) -> %d",
368 tv->tv_sec, tv->tv_usec, result);
370 errno = _errno;
371 #endif /* WITH_MSGLEVEL <= E_DEBUG */
372 return result;
375 int Mknod(const char *pathname, mode_t mode, dev_t dev) {
376 int result, _errno;
377 Debug3("mknod(\"%s\", 0%o, "F_dev")", pathname, mode, dev);
378 result = mknod(pathname, mode, dev);
379 _errno = errno;
380 Debug1("mknod() -> %d", result);
381 errno = _errno;
382 return result;
385 int Mkfifo(const char *pathname, mode_t mode) {
386 int result, _errno;
387 Debug2("mkfifo(\"%s\", 0%o)", pathname, mode);
388 result = mkfifo(pathname, mode);
389 _errno = errno;
390 Debug1("mkfifo() -> %d", result);
391 errno = _errno;
392 return result;
395 static void prtstat(const char *func, struct stat *buf, int result) {
396 char txt[256], *t = txt;
398 t += sprintf(t, "%s(, {"F_dev","F_st_ino","F_mode","F_st_nlink","F_uid","F_gid,
399 func, buf->st_dev, buf->st_ino,
400 buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
401 #if HAVE_ST_RDEV
402 t += sprintf(t, ","F_dev, buf->st_rdev);
403 #endif
404 t += sprintf(t, ","F_st_size, buf->st_size);
405 #if HAVE_ST_BLKSIZE
406 t += sprintf(t, ","F_st_blksize, buf->st_blksize);
407 #endif
408 #if HAVE_ST_BLOCKS
409 t += sprintf(t, ","F_st_blocks, buf->st_blocks);
410 #endif
411 sprintf(t, ",...}) -> %d", result);
412 Debug(txt);
415 #if defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64)
416 static void prtstat64(const char *func, struct stat64 *buf, int result) {
417 char txt[256], *t = txt;
419 if (result < 0) {
420 sprintf(t, "%s(, {}) -> %d", func, result);
421 } else {
422 t += sprintf(t, "%s(, {"F_dev","F_st64_ino","F_mode","F_st_nlink","F_uid","F_gid,
423 func, buf->st_dev, buf->st_ino,
424 buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
425 #if HAVE_ST_RDEV
426 t += sprintf(t, ","F_dev, buf->st_rdev);
427 #endif
428 t += sprintf(t, ","F_st64_size, buf->st_size);
429 #if HAVE_ST_BLKSIZE
430 t += sprintf(t, ","F_st_blksize, buf->st_blksize);
431 #endif
432 #if HAVE_ST_BLOCKS
433 t += sprintf(t, ","F_st64_blocks, buf->st_blocks);
434 #endif
435 sprintf(t, ",...}) -> %d", result);
437 Debug(txt);
439 #endif /* defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64) */
441 int Stat(const char *file_name, struct stat *buf) {
442 int result, _errno;
443 Debug2("stat(%s, %p)", file_name, buf);
444 result = stat(file_name, buf);
445 _errno = errno;
446 prtstat("stat", buf, result);
447 errno = _errno;
448 return result;
451 #if HAVE_STAT64
452 int Stat64(const char *file_name, struct stat64 *buf) {
453 int result, _errno;
454 Debug2("stat64(%s, %p)", file_name, buf);
455 result = stat64(file_name, buf);
456 _errno = errno;
457 prtstat64("stat64", buf, result);
458 errno = _errno;
459 return result;
461 #endif /* HAVE_STAT64 */
463 int Fstat(int filedes, struct stat *buf) {
464 int result, _errno;
465 Debug2("fstat(%d, %p)", filedes, buf);
466 result = fstat(filedes, buf);
467 _errno = errno;
468 prtstat("fstat", buf, result);
469 errno = _errno;
470 return result;
473 #if HAVE_FSTAT64
474 int Fstat64(int filedes, struct stat64 *buf) {
475 int result, _errno;
476 Debug2("fstat64(%d, %p)", filedes, buf);
477 result = fstat64(filedes, buf);
478 _errno = errno;
479 prtstat64("fstat64", buf, result);
480 errno = _errno;
481 return result;
483 #endif /* HAVE_FSTAT64 */
485 int Lstat(const char *file_name, struct stat *buf) {
486 int result, _errno;
487 Debug2("lstat(%s, %p)", file_name, buf);
488 result = lstat(file_name, buf);
489 _errno = errno;
490 prtstat("lstat", buf, result);
491 errno = _errno;
492 return result;
495 #if HAVE_LSTAT64
496 int Lstat64(const char *file_name, struct stat64 *buf) {
497 int result, _errno;
498 Debug2("lstat64(%s, %p)", file_name, buf);
499 result = lstat64(file_name, buf);
500 _errno = errno;
501 prtstat64("lstat64", buf, result);
502 errno = _errno;
503 return result;
505 #endif /* HAVE_LSTAT64 */
507 int Dup(int oldfd) {
508 int newfd, _errno;
509 Debug1("dup(%d)", oldfd);
510 newfd = dup(oldfd);
511 _errno = errno;
512 Info2("dup(%d) -> %d", oldfd, newfd);
513 errno = _errno;
514 return newfd;
517 int Dup2(int oldfd, int newfd) {
518 int result, _errno;
519 Debug2("dup2(%d, %d)", oldfd, newfd);
520 result = dup2(oldfd, newfd);
521 _errno = errno;
522 Info3("dup2(%d, %d) -> %d", oldfd, newfd, result);
523 errno = _errno;
524 return result;
527 int Pipe(int filedes[2]) {
528 int result, _errno;
529 Debug1("pipe(%p)", filedes);
530 result = pipe(filedes);
531 _errno = errno;
532 Info3("pipe({%d,%d}) -> %d", filedes[0], filedes[1], result);
533 errno = _errno;
534 return result;
537 #endif /* WITH_SYCLS */
539 ssize_t Read(int fd, void *buf, size_t count) {
540 ssize_t result;
541 int _errno;
542 if (!diag_in_handler) diag_flush();
543 #if WITH_SYCLS
544 Debug3("read(%d, %p, "F_Zu")", fd, buf, count);
545 #endif /* WITH_SYCLS */
546 result = read(fd, buf, count);
547 _errno = errno;
548 if (!diag_in_handler) diag_flush();
549 #if WITH_SYCLS
550 Debug1("read -> "F_Zd, result);
551 #endif /* WITH_SYCLS */
552 errno = _errno;
553 return result;
556 ssize_t Write(int fd, const void *buf, size_t count) {
557 ssize_t result;
558 int _errno;
559 if (!diag_in_handler) diag_flush();
560 #if WITH_SYCLS
561 Debug3("write(%d, %p, "F_Zu")", fd, buf, count);
562 #endif /* WITH_SYCLS */
563 result = write(fd, buf, count);
564 _errno = errno;
565 if (!diag_in_handler) diag_flush();
566 #if WITH_SYCLS
567 Debug1("write -> "F_Zd, result);
568 #endif /* WITH_SYCLS */
569 errno = _errno;
570 return result;
573 int Fcntl(int fd, int cmd) {
574 int result, _errno;
575 if (!diag_in_handler) diag_flush();
576 #if WITH_SYCLS
577 Debug2("fcntl(%d, %d)", fd, cmd);
578 #endif /* WITH_SYCLS */
579 result = fcntl(fd, cmd);
580 if (!diag_in_handler) diag_flush();
581 #if WITH_SYCLS
582 _errno = errno;
583 Debug1("fcntl() -> %d", result);
584 errno = _errno;
585 #endif /* WITH_SYCLS */
586 return result;
589 int Fcntl_l(int fd, int cmd, long arg) {
590 int result, _errno;
591 if (!diag_in_handler) diag_flush();
592 #if WITH_SYCLS
593 Debug3("fcntl(%d, %d, %ld)", fd, cmd, arg);
594 #endif /* WITH_SYCLS */
595 result = fcntl(fd, cmd, arg);
596 _errno = errno;
597 if (!diag_in_handler) diag_flush();
598 #if WITH_SYCLS
599 Debug1("fcntl() -> %d", result);
600 #endif /* WITH_SYCLS */
601 errno = _errno;
602 return result;
605 int Fcntl_lock(int fd, int cmd, struct flock *l) {
606 int result, _errno;
607 if (!diag_in_handler) diag_flush();
608 #if WITH_SYCLS
609 Debug7("fcntl(%d, %d, {type=%hd,whence=%hd,start="F_off",len="F_off",pid="F_pid"})",
610 fd, cmd, l->l_type, l->l_whence, l->l_start, l->l_len, l->l_pid);
611 #endif /* WITH_SYCLS */
612 result = fcntl(fd, cmd, l);
613 _errno = errno;
614 if (!diag_in_handler) diag_flush();
615 #if WITH_SYCLS
616 Debug1("fcntl() -> %d", result);
617 #endif /* WITH_SYCLS */
618 errno = _errno;
619 return result;
622 #if WITH_SYCLS
624 int Ftruncate(int fd, off_t length) {
625 int retval, _errno;
626 Debug2("ftruncate(%d, "F_off")", fd, length);
627 retval = ftruncate(fd, length);
628 _errno = errno;
629 Debug1("ftruncate() -> %d", retval);
630 errno = _errno;
631 return retval;
634 #if HAVE_FTRUNCATE64
635 int Ftruncate64(int fd, off64_t length) {
636 int retval, _errno;
637 Debug2("ftruncate64(%d, "F_off64")", fd, length);
638 retval = ftruncate64(fd, length);
639 _errno = errno;
640 Debug1("ftruncate64() -> %d", retval);
641 errno = _errno;
642 return retval;
644 #endif /* HAVE_FTRUNCATE64 */
646 #endif /* WITH_SYCLS */
648 #if HAVE_FLOCK
649 int Flock(int fd, int operation) {
650 int retval, _errno;
651 if (!diag_in_handler) diag_flush();
652 #if WITH_SYCLS
653 Debug2("flock(%d, %d)", fd, operation);
654 #endif /* WITH_SYCLS */
655 retval = flock(fd, operation);
656 _errno = errno;
657 if (!diag_in_handler) diag_flush();
658 #if WITH_SYCLS
659 Debug1("flock() -> %d", retval);
660 #endif /* WITH_SYCLS */
661 errno = _errno;
662 return retval;
664 #endif /* HAVE_FLOCK */
666 int Ioctl(int d, int request, void *argp) {
667 int retval, _errno;
668 if (!diag_in_handler) diag_flush();
669 #if WITH_SYCLS
670 if (argp > (void *)0x10000) { /* fuzzy...*/
671 Debug4("ioctl(%d, 0x%x, %p{%lu})", d, request, argp, *(unsigned long *)argp);
672 } else {
673 Debug3("ioctl(%d, 0x%x, 0x%p)", d, request, argp);
675 #endif /* WITH_SYCLS */
676 retval = ioctl(d, request, argp);
677 _errno = errno;
678 if (!diag_in_handler) diag_flush();
679 #if WITH_SYCLS
680 Debug1("ioctl() -> %d", retval);
681 #endif /* WITH_SYCLS */
682 errno = _errno;
683 return retval;
686 int Ioctl_int(int d, int request, int arg) {
687 int retval, _errno;
688 if (!diag_in_handler) diag_flush();
689 #if WITH_SYCLS
690 Debug3("ioctl(%d, 0x%x, %d)", d, request, arg);
691 #endif /* WITH_SYCLS */
692 retval = ioctl(d, request, arg);
693 _errno = errno;
694 if (!diag_in_handler) diag_flush();
695 #if WITH_SYCLS
696 Debug1("ioctl() -> %d", retval);
697 #endif /* WITH_SYCLS */
698 errno = _errno;
699 return retval;
702 #if WITH_SYCLS
704 int Close(int fd) {
705 int retval, _errno;
706 Info1("close(%d)", fd);
707 retval = close(fd);
708 _errno = errno;
709 Debug1("close() -> %d", retval);
710 errno = _errno;
711 return retval;
714 int Fchown(int fd, uid_t owner, gid_t group) {
715 int retval, _errno;
716 Debug3("fchown(%d, "F_uid", "F_gid")", fd, owner, group);
717 retval = fchown(fd, owner, group);
718 _errno = errno;
719 Debug1("fchown() -> %d", retval);
720 errno = _errno;
721 return retval;
724 int Fchmod(int fd, mode_t mode) {
725 int retval, _errno;
726 Debug2("fchmod(%d, 0%o)", fd, mode);
727 retval = fchmod(fd, mode);
728 _errno = errno;
729 Debug1("fchmod() -> %d", retval);
730 errno = _errno;
731 return retval;
734 int Unlink(const char *pathname) {
735 int retval, _errno;
736 Debug1("unlink(\"%s\")", pathname);
737 retval = unlink(pathname);
738 _errno = errno;
739 Debug1("unlink() -> %d", retval);
740 errno = _errno;
741 return retval;
744 int Symlink(const char *oldpath, const char *newpath) {
745 int retval, _errno;
746 Debug2("symlink(\"%s\", \"%s\")", oldpath, newpath);
747 retval = symlink(oldpath, newpath);
748 _errno = errno;
749 Debug1("symlink() -> %d", retval);
750 errno = _errno;
751 return retval;
754 int Readlink(const char *path, char *buf, size_t bufsiz) {
755 int retval, _errno;
756 Debug3("readlink(\"%s\", %p, "F_Zu")", path, buf, bufsiz);
757 retval = readlink(path, buf, bufsiz);
758 _errno = errno;
759 Debug1("readlink() -> %d", retval);
760 errno = _errno;
761 return retval;
764 int Chown(const char *path, uid_t owner, gid_t group) {
765 int retval, _errno;
766 Debug3("chown(\"%s\", "F_uid", "F_gid")", path, owner, group);
767 retval = chown(path, owner, group);
768 _errno = errno;
769 Debug1("chown() -> %d", retval);
770 errno = _errno;
771 return retval;
774 int Chmod(const char *path, mode_t mode) {
775 int retval, _errno;
776 Debug2("chmod(\"%s\", 0%o)", path, mode);
777 retval = chmod(path, mode);
778 _errno = errno;
779 Debug1("chmod() -> %d", retval);
780 errno = _errno;
781 return retval;
784 #endif /* WITH_SYCLS */
786 #if HAVE_POLL
787 /* we only show the first struct pollfd; hope this is enough for most cases. */
788 int Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
789 int _errno, result;
790 if (!diag_in_handler) diag_flush();
791 #if WITH_SYCLS
792 if (nfds == 4) {
793 Debug10("poll({%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}, %u, %d)",
794 ufds[0].fd, ufds[0].events, ufds[1].fd, ufds[1].events,
795 ufds[2].fd, ufds[2].events, ufds[3].fd, ufds[3].events,
796 nfds, timeout);
797 } else {
798 Debug4("poll({%d,0x%02hx,}, , %u, %d)", ufds[0].fd, ufds[0].events, nfds, timeout);
800 #endif /* WITH_SYCLS */
801 result = poll(ufds, nfds, timeout);
802 _errno = errno;
803 if (!diag_in_handler) diag_flush();
804 #if WITH_SYCLS
805 if (nfds == 4) {
806 Debug5("poll(, {,,0x%02hx}{,,0x%02hx}{,,0x%02hx}{,,0x%02hx}) -> %d",
807 ufds[0].revents, ufds[1].revents, ufds[2].revents, ufds[3].revents, result);
808 } else {
809 Debug2("poll(, {,,0x%02hx}) -> %d", ufds[0].revents, result);
811 #endif /* WITH_SYCLS */
812 errno = _errno;
813 return result;
815 #endif /* HAVE_POLL */
817 /* we only show the first word of the fd_set's; hope this is enough for most
818 cases. */
819 int Select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
820 struct timeval *timeout) {
821 int result, _errno;
822 if (!diag_in_handler) diag_flush();
823 #if WITH_SYCLS
824 #if HAVE_FDS_BITS
825 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu."F_tv_usec")",
826 n, readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
827 exceptfds?exceptfds->fds_bits[0]:0,
828 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
829 timeout?timeout->tv_usec:0);
830 #else
831 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu.%06u)",
832 n, readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
833 exceptfds?exceptfds->__fds_bits[0]:0,
834 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
835 timeout?timeout->tv_usec:0);
836 #endif
837 #endif /* WITH_SYCLS */
838 result = select(n, readfds, writefds, exceptfds, timeout);
839 _errno = errno;
840 if (!diag_in_handler) diag_flush();
841 #if WITH_SYCLS
842 #if HAVE_FDS_BITS
843 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu."F_tv_usec"), %d",
844 readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
845 exceptfds?exceptfds->fds_bits[0]:0,
846 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
847 timeout?timeout->tv_usec:0, result);
848 #else
849 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu.%06u), %d",
850 readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
851 exceptfds?exceptfds->__fds_bits[0]:0,
852 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
853 timeout?timeout->tv_usec:0, result);
854 #endif
855 #endif /* WITH_SYCLS */
856 errno = _errno;
858 return result;
861 #if HAVE_PSELECT
862 /* we only show the first word of the fd_set's; hope this is enough for most
863 cases. */
864 int Pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
865 const struct timespec *timeout, const sigset_t *sigmask) {
866 int result, _errno;
867 if (!diag_in_handler) diag_flush();
868 #if WITH_SYCLS
869 #if HAVE_FDS_BITS
870 Debug8("pselect(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu."F_tv_nsec", "F_sigset")",
871 n, readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
872 exceptfds?exceptfds->fds_bits[0]:0,
873 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
874 timeout?timeout->tv_nsec:0, *(T_sigset *)sigmask);
875 #else
876 Debug8("pselect(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu.%06u)",
877 n, readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
878 exceptfds?exceptfds->__fds_bits[0]:0,
879 timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
880 timeout?timeout->tv_nsec:0);
881 #endif
882 #endif /* WITH_SYCLS */
883 result = pselect(n, readfds, writefds, exceptfds, timeout, sigmask);
884 _errno = errno;
885 if (!diag_in_handler) diag_flush();
886 #if WITH_SYCLS
887 #if HAVE_FDS_BITS
888 Debug5("pselect -> (, 0x%lx, 0x%lx, 0x%lx), "F_sigset", %d",
889 readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
890 exceptfds?exceptfds->fds_bits[0]:0, *(T_sigset *)sigmask,
891 result);
892 #else
893 Debug6("pselect -> (, 0x%lx, 0x%lx, 0x%lx), %d",
894 readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
895 exceptfds?exceptfds->__fds_bits[0]:0,
896 result);
897 #endif
898 #endif /* WITH_SYCLS */
899 errno = _errno;
901 return result;
903 #endif /* HAVE_PSELECT */
905 #if WITH_SYCLS
907 pid_t Fork(void) {
908 pid_t pid;
909 int _errno;
910 Debug("fork()");
911 pid = fork();
912 _errno = errno;
913 Debug1("fork() -> %d", pid); /* attention: called twice! */
914 errno = _errno;
915 return pid;
918 #endif /* WITH_SYCLS */
920 pid_t Waitpid(pid_t pid, int *status, int options) {
921 int _errno;
922 pid_t retval;
923 if (!diag_in_handler) diag_flush();
924 #if WITH_SYCLS
925 Debug3("waitpid("F_pid", %p, %d)", pid, status, options);
926 #endif /* WITH_SYCLS */
927 retval = waitpid(pid, status, options);
928 _errno = errno;
929 if (!diag_in_handler) diag_flush();
930 #if WITH_SYCLS
931 Debug2("waitpid(, {%d}, ) -> "F_pid, *status, retval);
932 #endif /* WITH_SYCLS */
933 errno = _errno;
934 return retval;
937 #if WITH_SYCLS
939 sighandler_t Signal(int signum, sighandler_t handler) {
940 int _errno;
941 sighandler_t retval;
942 Debug2("signal(%d, %p)", signum, handler);
943 retval = signal(signum, handler);
944 _errno = errno;
945 Debug1("signal() -> %p", retval);
946 errno = _errno;
947 return retval;
950 #if HAVE_SIGACTION
951 int Sigaction(int signum, const struct sigaction *act,
952 struct sigaction *oldact) {
953 int retval;
954 Debug3("sigaction(%d, %p, %p)", signum, act, oldact);
955 retval = sigaction(signum, act, oldact);
956 Debug1("sigaction() -> %d", retval);
957 return retval;
959 #endif /* HAVE_SIGACTION */
961 int Sigprocmask(int how, const sigset_t *set, sigset_t *oset) {
962 int retval;
963 if (set)
964 Debug3("sigprocmask(%d, "F_sigset", %p)", how, *(T_sigset *)set, oset);
965 else
966 Debug2("sigprocmask(%d, NULL, %p)", how, oset);
967 retval = sigprocmask(how, set, oset);
968 if (oset)
969 Debug2("sigprocmask() -> {,, "F_sigset"} %d", *(T_sigset *)oset, retval);
970 else
971 Debug1("sigprocmask() -> %d", retval);
972 return retval;
975 unsigned int Alarm(unsigned int seconds) {
976 unsigned int retval;
977 Debug1("alarm(%u)", seconds);
978 retval = alarm(seconds);
979 Debug1("alarm() -> %u", retval);
980 return retval;
983 int Kill(pid_t pid, int sig) {
984 int retval, _errno;
985 Debug2("kill("F_pid", %d)", pid, sig);
986 retval = kill(pid, sig);
987 _errno = errno;
988 Debug1("kill() -> %d", retval);
989 errno = _errno;
990 return retval;
993 int Link(const char *oldpath, const char *newpath) {
994 int retval, _errno;
995 Debug2("link(\"%s\", \"%s\")", oldpath, newpath);
996 retval = link(oldpath, newpath);
997 _errno = errno;
998 Debug1("link() -> %d", retval);
999 errno = _errno;
1000 return retval;
1003 int Execvp(const char *file, char *const argv[]) {
1004 int result, _errno;
1005 if (argv[1] == NULL)
1006 Debug2("execvp(\"%s\", \"%s\")", file, argv[0]);
1007 else if (argv[2] == NULL)
1008 Debug3("execvp(\"%s\", \"%s\" \"%s\")", file, argv[0], argv[1]);
1009 else if (argv[3] == NULL)
1010 Debug4("execvp(\"%s\", \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2]);
1011 else if (argv[4] == NULL)
1012 Debug5("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3]);
1013 else if (argv[5] == NULL)
1014 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
1015 else
1016 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" ...)", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
1018 result = execvp(file, argv);
1019 _errno = errno;
1020 Debug1("execvp() -> %d", result);
1021 errno = _errno;
1022 return result;
1025 #endif /* WITH_SYCLS */
1027 int System(const char *string) {
1028 int result, _errno;
1029 #if WITH_SYCLS
1030 Debug1("system(\"%s\")", string);
1031 #endif /* WITH_SYCLS */
1032 diag_immediate_exit = 1;
1033 result = system(string);
1034 diag_immediate_exit = 0;
1035 #if WITH_SYCLS
1036 _errno = errno;
1037 Debug1("system() -> %d", result);
1038 errno = _errno;
1039 #endif /* WITH_SYCLS */
1040 return result;
1043 #if WITH_SYCLS
1045 int Socketpair(int d, int type, int protocol, int sv[2]) {
1046 int result, _errno;
1047 Debug4("socketpair(%d, %d, %d, %p)", d, type, protocol, sv);
1048 result = socketpair(d, type, protocol, sv);
1049 _errno = errno;
1050 Info6("socketpair(%d, %d, %d, {%d,%d}) -> %d", d, type, protocol, sv[0], sv[1], result);
1051 errno = _errno;
1052 return result;
1055 #if _WITH_SOCKET
1056 int Socket(int domain, int type, int protocol) {
1057 int result, _errno;
1058 Debug3("socket(%d, %d, %d)", domain, type, protocol);
1059 result = socket(domain, type, protocol);
1060 _errno = errno;
1061 Info4("socket(%d, %d, %d) -> %d", domain, type, protocol, result);
1062 errno = _errno;
1063 return result;
1065 #endif /* _WITH_SOCKET */
1067 #if _WITH_SOCKET
1068 int Bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) {
1069 int result, _errno;
1070 char infobuff[256];
1072 sockaddr_info(my_addr, addrlen, infobuff, sizeof(infobuff));
1073 Debug3("bind(%d, %s, "F_socklen")", sockfd, infobuff, addrlen);
1074 result = bind(sockfd, my_addr, addrlen);
1075 _errno = errno;
1076 Debug1("bind() -> %d", result);
1077 errno = _errno;
1078 return result;
1080 #endif /* _WITH_SOCKET */
1082 #endif /* WITH_SYCLS */
1084 #if _WITH_SOCKET
1085 int Connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) {
1086 int result, _errno;
1087 char infobuff[256];
1089 if (!diag_in_handler) diag_flush();
1090 #if WITH_SYCLS
1091 /*sockaddr_info(serv_addr, infobuff, sizeof(infobuff));
1092 Debug3("connect(%d, %s, "F_Zd")", sockfd, infobuff, addrlen);*/
1093 #if 0
1094 Debug18("connect(%d,{0x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x}, "F_Zd")",
1095 sockfd,
1096 ((unsigned char *)serv_addr)[0], ((unsigned char *)serv_addr)[1],
1097 ((unsigned char *)serv_addr)[2], ((unsigned char *)serv_addr)[3],
1098 ((unsigned char *)serv_addr)[4], ((unsigned char *)serv_addr)[5],
1099 ((unsigned char *)serv_addr)[6], ((unsigned char *)serv_addr)[7],
1100 ((unsigned char *)serv_addr)[8], ((unsigned char *)serv_addr)[9],
1101 ((unsigned char *)serv_addr)[10], ((unsigned char *)serv_addr)[11],
1102 ((unsigned char *)serv_addr)[12], ((unsigned char *)serv_addr)[13],
1103 ((unsigned char *)serv_addr)[14], ((unsigned char *)serv_addr)[15],
1104 addrlen);
1105 #else
1106 Debug4("connect(%d, {%d,%s}, "F_socklen")",
1107 sockfd, serv_addr->sa_family,
1108 sockaddr_info(serv_addr, addrlen, infobuff, sizeof(infobuff)),
1109 addrlen);
1110 #endif
1111 #endif /* WITH_SYCLS */
1112 result = connect(sockfd, serv_addr, addrlen);
1113 _errno = errno;
1114 if (!diag_in_handler) diag_flush();
1115 #if WITH_SYCLS
1116 Debug1("connect() -> %d", result);
1117 #endif /* WITH_SYCLS */
1118 errno = _errno;
1119 return result;
1121 #endif /* _WITH_SOCKET */
1123 #if WITH_SYCLS
1125 #if _WITH_SOCKET
1126 int Listen(int s, int backlog) {
1127 int result, _errno;
1128 Debug2("listen(%d, %d)", s, backlog);
1129 result = listen(s, backlog);
1130 _errno = errno;
1131 Debug1("listen() -> %d", result);
1132 errno = _errno;
1133 return result;
1135 #endif /* _WITH_SOCKET */
1137 #endif /* WITH_SYCLS */
1139 #if _WITH_SOCKET
1140 /* don't forget to handle EINTR when using Accept() ! */
1141 int Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
1142 int result, _errno;
1143 fd_set accept_s;
1144 if (!diag_in_handler) diag_flush();
1145 FD_ZERO(&accept_s);
1146 FD_SET(s, &accept_s);
1147 if (diag_select(s+1, &accept_s, NULL, NULL, NULL) < 0) {
1148 return -1;
1150 #if WITH_SYCLS
1151 Debug3("accept(%d, %p, %p)", s, addr, addrlen);
1152 #endif /* WITH_SYCLS */
1153 result = accept(s, addr, addrlen);
1154 _errno = errno;
1155 if (!diag_in_handler) diag_flush();
1156 #if WITH_SYCLS
1157 if (result >= 0) {
1158 char infobuff[256];
1159 sockaddr_info(addr, *addrlen, infobuff, sizeof(infobuff));
1160 Info5("accept(%d, {%d, %s}, "F_socklen") -> %d", s,
1161 addr->sa_family,
1162 sockaddr_info(addr, *addrlen, infobuff, sizeof(infobuff)),
1163 *addrlen, result);
1164 } else {
1165 Debug1("accept(,,) -> %d", result);
1167 #endif /* WITH_SYCLS */
1168 errno = _errno;
1169 return result;
1171 #endif /* _WITH_SOCKET */
1173 #if WITH_SYCLS
1175 #if _WITH_SOCKET
1176 int Getsockname(int s, struct sockaddr *name, socklen_t *namelen) {
1177 int result, _errno;
1178 char infobuff[256];
1180 Debug4("getsockname(%d, %p, %p{"F_socklen"})", s, name, namelen, *namelen);
1181 result = getsockname(s, name, namelen);
1182 _errno = errno;
1183 /*Debug2("getsockname(,, {"F_socklen"}) -> %d",
1184 *namelen, result);*/
1185 Debug3("getsockname(, {%s}, {"F_socklen"}) -> %d",
1186 sockaddr_info(name, *namelen, infobuff, sizeof(infobuff)),
1187 *namelen, result);
1188 errno = _errno;
1189 return result;
1191 #endif /* _WITH_SOCKET */
1193 #if _WITH_SOCKET
1194 int Getpeername(int s, struct sockaddr *name, socklen_t *namelen) {
1195 int result, _errno;
1196 char infobuff[256];
1198 Debug4("getpeername(%d, %p, %p{"F_socklen"})", s, name, namelen, *namelen);
1199 result = getpeername(s, name, namelen);
1200 _errno = errno;
1201 sockaddr_info(name, *namelen, infobuff, sizeof(infobuff));
1202 Debug3("getpeername(, {%s}, {"F_socklen"}) -> %d",
1203 infobuff, *namelen, result);
1204 errno = _errno;
1205 return result;
1207 #endif /* _WITH_SOCKET */
1209 #if _WITH_SOCKET
1210 int Getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) {
1211 int result, _errno;
1212 Debug5("getsockopt(%d, %d, %d, %p, {"F_socklen"})",
1213 s, level, optname, optval, *optlen);
1214 result = getsockopt(s, level, optname, optval, optlen);
1215 _errno = errno;
1216 Debug3("getsockopt() -> (,,, 0x%08x, %d), %d",
1217 *(int *)optval, *optlen, result);
1218 errno = _errno;
1219 return result;
1221 #endif /* _WITH_SOCKET */
1223 #if _WITH_SOCKET
1224 int Setsockopt(int s, int level, int optname, const void *optval, int optlen) {
1225 int result, _errno;
1226 if (optlen <= sizeof(int)) {
1227 Debug5("setsockopt(%d, %d, %d, {0x%x}, %d)",
1228 s, level, optname, *(unsigned int *)optval, optlen);
1229 } else {
1230 Debug6("setsockopt(%d, %d, %d, {0x%08x,%08x}, %d)",
1231 s, level, optname,
1232 ((unsigned int *)optval)[0], ((unsigned int *)optval)[1],
1233 optlen);
1235 result = setsockopt(s, level, optname, optval, optlen);
1236 _errno = errno;
1237 Debug1("setsockopt() -> %d", result);
1238 errno = _errno;
1239 return result;
1241 #endif /* _WITH_SOCKET */
1243 #endif /* WITH_SYCLS */
1245 #if _WITH_SOCKET
1246 int Recv(int s, void *buf, size_t len, int flags) {
1247 int retval, _errno;
1248 if (!diag_in_handler) diag_flush();
1249 #if WITH_SYCLS
1250 Debug4("recv(%d, %p, "F_Zu", %d)", s, buf, len, flags);
1251 #endif /* WITH_SYCLS */
1252 retval = recv(s, buf, len, flags);
1253 _errno = errno;
1254 if (!diag_in_handler) diag_flush();
1255 #if WITH_SYCLS
1256 Debug1("recv() -> %d", retval);
1257 #endif /* WITH_SYCLS */
1258 errno = _errno;
1259 return retval;
1261 #endif /* _WITH_SOCKET */
1263 #if _WITH_SOCKET
1264 int Recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from,
1265 socklen_t *fromlen) {
1266 int retval, _errno;
1267 char infobuff[256];
1268 if (!diag_in_handler) diag_flush();
1269 #if WITH_SYCLS
1270 Debug6("recvfrom(%d, %p, "F_Zu", %d, %p, "F_socklen")",
1271 s, buf, len, flags, from, *fromlen);
1272 #endif /* WITH_SYCLS */
1273 retval = recvfrom(s, buf, len, flags, from, fromlen);
1274 _errno = errno;
1275 if (!diag_in_handler) diag_flush();
1276 #if WITH_SYCLS
1277 if (from) {
1278 Debug4("recvfrom(,,,, {%d,%s}, "F_socklen") -> %d",
1279 from->sa_family,
1280 sockaddr_info(from, *fromlen, infobuff, sizeof(infobuff)),
1281 *fromlen, retval);
1282 } else {
1283 Debug1("recvfrom(,,,, NULL, NULL) -> %d", retval);
1285 #endif /* WITH_SYCLS */
1286 errno = _errno;
1287 return retval;
1289 #endif /* _WITH_SOCKET */
1291 #if _WITH_SOCKET
1292 int Recvmsg(int s, struct msghdr *msgh, int flags) {
1293 int retval, _errno;
1294 if (!diag_in_handler) diag_flush();
1295 #if WITH_SYCLS
1296 char infobuff[256];
1297 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROL) && defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN) && defined(HAVE_STRUCT_MSGHDR_MSGFLAGS)
1298 Debug10("recvmsg(%d, %p{%p,%u,%p,"F_Zu",%p,"F_Zu",%d}, %d)", s, msgh,
1299 msgh->msg_name, msgh->msg_namelen, msgh->msg_iov, msgh->msg_iovlen,
1300 msgh->msg_control, msgh->msg_controllen, msgh->msg_flags, flags);
1301 #else
1302 Debug7("recvmsg(%d, %p{%p,%u,%p,%u}, %d)", s, msgh,
1303 msgh->msg_name, msgh->msg_namelen, msgh->msg_iov, msgh->msg_iovlen,
1304 flags);
1305 #endif
1306 #endif /* WITH_SYCLS */
1307 retval = recvmsg(s, msgh, flags);
1308 _errno = errno;
1309 if (!diag_in_handler) diag_flush();
1310 #if WITH_SYCLS
1311 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN)
1312 Debug5("recvmsg(, {%s,%u,,"F_Zu",,"F_Zu",}, ) -> %d",
1313 msgh->msg_name?sockaddr_info(msgh->msg_name, msgh->msg_namelen, infobuff, sizeof(infobuff)):"NULL",
1314 msgh->msg_namelen, msgh->msg_iovlen, msgh->msg_controllen,
1315 retval);
1316 #else
1317 Debug4("recvmsg(, {%s,%u,,%u,,}, ) -> %d",
1318 msgh->msg_name?sockaddr_info(msgh->msg_name, msgh->msg_namelen, infobuff, sizeof(infobuff)):"NULL",
1319 msgh->msg_namelen, msgh->msg_iovlen,
1320 retval);
1321 #endif
1322 #endif /* WITH_SYCLS */
1323 errno = _errno;
1324 return retval;
1326 #endif /* _WITH_SOCKET */
1328 #if _WITH_SOCKET
1329 int Send(int s, const void *mesg, size_t len, int flags) {
1330 int retval, _errno;
1331 if (!diag_in_handler) diag_flush();
1332 #if WITH_SYCLS
1333 Debug5("send(%d, %p[%08x...], "F_Zu", %d)",
1334 s, mesg, ntohl(*(unsigned long *)mesg), len, flags);
1335 #endif /* WITH_SYCLS */
1336 retval = send(s, mesg, len, flags);
1337 _errno = errno;
1338 if (!diag_in_handler) diag_flush();
1339 #if WITH_SYCLS
1340 Debug1("send() -> %d", retval);
1341 #endif /* WITH_SYCLS */
1342 errno = _errno;
1343 return retval;
1345 #endif /* _WITH_SOCKET */
1347 #if _WITH_SOCKET
1348 int Sendto(int s, const void *mesg, size_t len, int flags,
1349 const struct sockaddr *to, socklen_t tolen) {
1350 int retval, _errno;
1351 char infobuff[256];
1353 if (!diag_in_handler) diag_flush();
1354 #if WITH_SYCLS
1355 sockaddr_info(to, tolen, infobuff, sizeof(infobuff));
1356 Debug7("sendto(%d, %p[%08x...], "F_Zu", %d, {%s}, %d)",
1357 s, mesg, htonl(*(unsigned long *)mesg), len, flags, infobuff, tolen);
1358 #endif /* WITH_SYCLS */
1359 retval = sendto(s, mesg, len, flags, to, tolen);
1360 _errno = errno;
1361 if (!diag_in_handler) diag_flush();
1362 #if WITH_SYCLS
1363 Debug1("sendto() -> %d", retval);
1364 #endif /* WITH_SYCLS */
1365 errno = _errno;
1366 return retval;
1368 #endif /* _WITH_SOCKET */
1370 #if WITH_SYCLS
1372 #if _WITH_SOCKET
1373 int Shutdown(int fd, int how) {
1374 int retval, _errno;
1375 Info2("shutdown(%d, %d)", fd, how);
1376 retval = shutdown(fd, how);
1377 _errno = errno;
1378 Debug1("shutdown() -> %d", retval);
1379 errno = _errno;
1380 return retval;
1382 #endif /* _WITH_SOCKET */
1384 unsigned int Sleep(unsigned int seconds) {
1385 unsigned int retval;
1386 Debug1("sleep(%u)", seconds);
1387 retval = sleep(seconds);
1388 Debug1("sleep() -> %u", retval);
1389 return retval;
1392 #if HAVE_NANOSLEEP
1393 unsigned int Nanosleep(const struct timespec *req, struct timespec *rem) {
1394 int retval, _errno;
1395 Debug3("nanosleep({"F_time",%ld},%p)", req->tv_sec, req->tv_nsec, rem);
1396 retval = nanosleep(req, rem);
1397 _errno = errno;
1398 if (rem) {
1399 Debug3("nanosleep(,{"F_time",%ld}) -> %d",
1400 rem->tv_sec, rem->tv_nsec, retval);
1401 } else {
1402 Debug1("nanosleep() -> %d", retval);
1404 errno = _errno;
1405 return retval;
1407 #endif /* HAVE_NANOSLEEP */
1409 int Pause(void) {
1410 int retval, _errno;
1411 Debug("pause()");
1412 retval = pause();
1413 _errno = errno;
1414 Debug1("pause() -> %d", retval);
1415 errno = _errno;
1416 return retval;
1419 #if ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME
1420 struct hostent *Gethostbyname(const char *name) {
1421 struct hostent *hent;
1422 Debug1("gethostbyname(\"%s\")", name);
1423 hent = gethostbyname(name);
1424 if (hent == NULL) {
1425 Debug("gethostbyname() -> NULL");
1426 } else {
1427 Debug4("gethostbyname() -> %d.%d.%d.%d",
1428 ((unsigned char *)hent->h_addr_list[0])[0],
1429 ((unsigned char *)hent->h_addr_list[0])[1],
1430 ((unsigned char *)hent->h_addr_list[0])[2],
1431 ((unsigned char *)hent->h_addr_list[0])[3]);
1433 return hent;
1435 #endif /* ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME */
1437 #if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
1438 int Getaddrinfo(const char *node, const char *service,
1439 const struct addrinfo *hints, struct addrinfo **res) {
1440 int result;
1441 Debug15("getaddrinfo(%s%s%s, %s%s%s, {%d,%d,%d,%d,"F_socklen",%p,%p,%p}, %p)",
1442 node?"\"":"", node?node:"NULL", node?"\"":"",
1443 service?"\"":"", service?service:"NULL", service?"\"":"",
1444 hints->ai_flags, hints->ai_family, hints->ai_socktype,
1445 hints->ai_protocol, hints->ai_addrlen, hints->ai_addr,
1446 hints->ai_canonname, hints->ai_next, res);
1447 result = getaddrinfo(node, service, hints, res);
1448 if (result == 0) {
1449 char sockbuff[256];
1450 sockaddr_info((*res)->ai_addr, hints->ai_addrlen, sockbuff, sizeof(sockbuff));
1451 Debug2("getaddrinfo(,,,{{%s, %s}) -> 0",
1452 sockbuff,
1453 (*res)->ai_canonname?(*res)->ai_canonname:"");
1454 } else {
1455 Debug2("getaddrinfo(,,,{%p}) -> %d", *res, result);
1457 return result;
1459 #endif /* (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO */
1461 #if (WITH_IP4 || WITH_IP6) && HAVE_PROTOTYPE_LIB_getipnodebyname
1462 struct hostent *Getipnodebyname(const char *name, int af, int flags,
1463 int *error_num) {
1464 struct hostent *result;
1465 Debug4("getipnodebyname(\"%s\", %d, %d, %p)", name, af, flags, error_num);
1466 result = getipnodebyname(name, af, flags, error_num);
1467 if (result == NULL) {
1468 Debug1("getipnodebyname(,,, {%d}) -> NULL", *error_num);
1469 } else {
1470 Debug4("getipnodebyname() -> {\"%s\", %p, %d, %d, ???}",
1471 result->h_name, result->h_aliases, result->h_addrtype,
1472 result->h_length);
1474 return result;
1476 #endif /* (WITH_IP4 || WITH_IP6) && HAVE_PROTOTYPE_LIB_getipnodebyname */
1478 void *Malloc(size_t size) {
1479 void *result;
1480 Debug1("malloc("F_Zd")", size);
1481 result = malloc(size);
1482 Debug1("malloc() -> %p", result);
1483 if (result == NULL) {
1484 Error1("malloc("F_Zd"): out of memory", size);
1485 return NULL;
1487 return result;
1490 void *Calloc(size_t nmemb, size_t size) {
1491 void *result;
1492 Debug2("calloc("F_Zd", "F_Zd")", nmemb, size);
1493 result = calloc(nmemb, size);
1494 Debug1("calloc() -> %p", result);
1495 if (result == NULL) {
1496 Error2("calloc("F_Zd", "F_Zd"): out of memory", nmemb, size);
1497 return NULL;
1499 return result;
1502 void *Realloc(void *ptr, size_t size) {
1503 void *result;
1504 Debug2("realloc(%p, "F_Zd")", ptr, size);
1505 result = realloc(ptr, size);
1506 Debug1("realloc() -> %p", result);
1507 if (result == NULL) {
1508 Error2("realloc(%p, "F_Zd"): out of memory", ptr, size);
1509 return NULL;
1511 return result;
1514 #if _WITH_TERMIOS
1515 int Tcgetattr(int fd, struct termios *termios_p) {
1516 int i, result, _errno;
1517 char chars[5*NCCS], *cp = chars;
1519 Debug2("tcgetattr(%d, %p)", fd, termios_p);
1520 result = tcgetattr(fd, termios_p);
1521 _errno = errno;
1523 for (i = 0; i < NCCS-1; ++i) {
1524 cp += sprintf(cp, "%02x,", termios_p->c_cc[i]);
1526 sprintf(cp, "%02x", termios_p->c_cc[i]);
1527 #if HAVE_STRUCT_TERMIOS_C_ISPEED && HAVE_STRUCT_TERMIOS_C_OSPEED
1528 Debug8("tcgetattr(, {%08x,%08x,%08x,%08x, "F_speed","F_speed", %s}) -> %d",
1529 termios_p->c_iflag, termios_p->c_oflag,
1530 termios_p->c_cflag, termios_p->c_lflag,
1531 termios_p->c_ispeed, termios_p->c_ospeed,
1532 chars, result);
1533 #else
1534 Debug6("tcgetattr(, {%08x,%08x,%08x,%08x,%s}) -> %d",
1535 termios_p->c_iflag, termios_p->c_oflag,
1536 termios_p->c_cflag, termios_p->c_lflag,
1537 chars, result);
1538 #endif
1539 errno = _errno;
1540 return result;
1542 #endif /* _WITH_TERMIOS */
1544 #if _WITH_TERMIOS
1545 int Tcsetattr(int fd, int optional_actions, struct termios *termios_p) {
1546 int i, result, _errno;
1547 char chars[5*NCCS], *cp = chars;
1549 for (i = 0; i < NCCS-1; ++i) {
1550 cp += sprintf(cp, "%02x,", termios_p->c_cc[i]);
1552 sprintf(cp, "%02x", termios_p->c_cc[i]);
1553 #if HAVE_STRUCT_TERMIOS_C_ISPEED && HAVE_STRUCT_TERMIOS_C_OSPEED
1554 Debug9("tcsetattr(%d, %d, {%08x,%08x,%08x,%08x, "F_speed","F_speed", %s})",
1555 fd, optional_actions,
1556 termios_p->c_iflag, termios_p->c_oflag,
1557 termios_p->c_cflag, termios_p->c_lflag,
1558 termios_p->c_ispeed, termios_p->c_ospeed,
1559 chars);
1560 #else
1561 Debug7("tcsetattr(%d, %d, {%08x,%08x,%08x,%08x,%s})", fd, optional_actions,
1562 termios_p->c_iflag, termios_p->c_oflag,
1563 termios_p->c_cflag, termios_p->c_lflag, chars);
1564 #endif
1565 result = tcsetattr(fd, optional_actions, termios_p);
1566 _errno = errno;
1567 Debug1("tcsetattr() -> %d", result);
1568 errno = _errno;
1569 return result;
1571 #endif /* _WITH_TERMIOS */
1573 char *Ttyname(int fd) {
1574 char *result;
1575 int _errno;
1576 Debug1("ttyname(%d)", fd);
1577 result = ttyname(fd);
1578 _errno = errno;
1579 if (result)
1580 Debug1("ttyname() -> %s", result);
1581 else
1582 Debug("ttyname() -> NULL");
1583 errno = _errno;
1584 return result;
1587 int Isatty(int fd) {
1588 int result, _errno;
1589 Debug1("isatty(%d)", fd);
1590 result = isatty(fd);
1591 _errno = errno;
1592 Debug1("isatty() -> %d", result);
1593 errno = _errno;
1594 return result;
1597 #if HAVE_OPENPTY
1598 int Openpty(int *ptyfd, int *ttyfd, char *ptyname, struct termios *termp,
1599 struct winsize *winp) {
1600 int result, _errno;
1601 Debug5("openpty(%p, %p, %p, %p, %p)", ptyfd, ttyfd, ptyname, termp, winp);
1602 result = openpty(ptyfd, ttyfd, ptyname, termp, winp);
1603 _errno = errno;
1604 Info4("openpty({%d}, {%d}, {\"%s\"},,) -> %d", *ptyfd, *ttyfd, ptyname,
1605 result);
1606 errno = _errno;
1607 return result;
1609 #endif /* HAVE_OPENPTY */
1611 #if HAVE_GRANTPT
1612 int Grantpt(int fd) {
1613 int result, _errno;
1614 Debug1("grantpt(%d)", fd);
1615 result = grantpt(fd);
1616 _errno = errno;
1617 Debug1("grantpt() -> %d", result);
1618 errno = _errno;
1619 return result;
1621 #endif /* HAVE_GRANTPT */
1623 #if HAVE_UNLOCKPT
1624 int Unlockpt(int fd) {
1625 int result, _errno;
1626 Debug1("unlockpt(%d)", fd);
1627 result = unlockpt(fd);
1628 _errno = errno;
1629 Debug1("unlockpt() -> %d", result);
1630 errno = _errno;
1631 return result;
1633 #endif /* HAVE_UNLOCKPT */
1635 #if HAVE_PROTOTYPE_LIB_ptsname /* AIX, not Linux */
1636 char *Ptsname(int fd) {
1637 char *result;
1638 int _errno;
1639 Debug1("ptsname(%d)", fd);
1640 result = ptsname(fd);
1641 _errno = errno;
1642 if (result)
1643 Debug1("ptsname() -> %s", result);
1644 else
1645 Debug("ptsname() -> NULL");
1646 errno = _errno;
1647 return result;
1649 #endif /* HAVE_PROTOTYPE_LIB_ptsname */
1651 int Uname(struct utsname *buf) {
1652 int result, _errno;
1653 Debug1("uname(%p)", buf);
1654 result = uname(buf);
1655 _errno = errno;
1656 #if UNAME_DOMAINNAME
1657 Debug6("uname({%s, %s, %s, %s, %s, %s})",
1658 buf->sysname, buf->nodename, buf->release,
1659 buf->version, buf->machine, buf->domainname);
1660 #else
1661 Debug5("uname({%s, %s, %s, %s, %s})",
1662 buf->sysname, buf->nodename, buf->release,
1663 buf->version, buf->machine);
1664 #endif
1665 errno = _errno;
1666 return result;
1669 int Gethostname(char *name, size_t len) {
1670 int result, _errno;
1671 Debug2("gethostname(%p, "F_Zu")", name, len);
1672 result = gethostname(name, len);
1673 _errno = errno;
1674 Debug2("gethostname(\"%s\", ) -> %d", name, result);
1675 errno = _errno;
1676 return result;
1679 /* due to Linux docu, it does not set errno */
1680 int Atexit(void (*func)(void)) {
1681 int result;
1682 Debug1("atexit(%p)", func);
1683 result = atexit(func);
1684 Debug1("atexit() -> %d", result);
1685 return result;
1688 #endif /* WITH_SYCLS */
1690 void Exit(int status) {
1691 if (!diag_in_handler) diag_flush();
1692 #if WITH_SYCLS
1693 Debug1("exit(%d)", status);
1694 #endif /* WITH_SYCLS */
1695 exit(status);
1698 #if WITH_SYCLS
1700 void Abort(void) {
1701 Debug("abort()");
1702 abort();
1705 int Mkstemp(char *template) {
1706 int result, _errno;
1707 Debug1("mkstemp(\"%s\")", template);
1708 result = mkstemp(template);
1709 _errno = errno;
1710 Info2("mkstemp({%s}) -> %d", template, result);
1711 errno = _errno;
1712 return result;
1715 int Setenv(const char *name, const char *value, int overwrite) {
1716 int result, _errno;
1717 Debug3("setenv(\"%s\", \"%s\", %d)", name, value, overwrite);
1718 result = setenv(name, value, overwrite);
1719 _errno = errno;
1720 Debug1("setenv() -> %d", result);
1721 errno = _errno;
1722 return result;
1725 #if HAVE_UNSETENV
1726 /* on Linux it returns int but on FreeBSD void.
1727 we do not expect many errors, so we take void which works on all systems. */
1728 void Unsetenv(const char *name) {
1729 int _errno;
1730 Debug1("unsetenv(\"%s\")", name);
1731 unsetenv(name);
1732 _errno = errno;
1733 Debug("unsetenv() ->");
1734 errno = _errno;
1735 return;
1737 #endif
1739 #if WITH_READLINE
1741 char *Readline(const char *prompt) {
1742 char *result;
1744 if (prompt) {
1745 Debug1("readline(\"%s\")", prompt);
1746 } else {
1747 Debug("readline(NULL)");
1749 result = readline(prompt);
1750 if (result) {
1751 Debug("readline() -> \"...\"");
1752 } else {
1753 Debug("readline() -> NULL");
1755 return result;
1758 void Using_history(void) {
1759 Debug("using_history()");
1760 using_history();
1761 Debug("using_history() ->");
1764 int Read_history(const char *filename) {
1765 int result;
1767 if (filename) {
1768 Debug1("read_history(\"%s\")", filename);
1769 } else {
1770 Debug("read_history(NULL)");
1772 result = read_history(filename);
1773 if (result) {
1774 Debug1("read_history() -> %d", result);
1775 } else {
1776 Debug("read_history() -> 0");
1778 return result;
1781 int Write_history(const char *filename) {
1782 int result;
1784 if (filename) {
1785 Debug1("write_history(\"%s\")", filename);
1786 } else {
1787 Debug("write_history(NULL)");
1789 result = write_history(filename);
1790 if (result) {
1791 Debug1("write_history() -> %d", result);
1792 } else {
1793 Debug("write_history() -> 0");
1795 return result;
1798 int Append_history(int nelements, const char *filename) {
1799 int result;
1801 if (filename) {
1802 Debug2("append_history(%d, \"%s\")", nelements, filename);
1803 } else {
1804 Debug1("append_history(%d, NULL)", nelements);
1806 result = append_history(nelements, filename);
1807 if (result) {
1808 Debug1("append_history() -> %d", result);
1809 } else {
1810 Debug("append_history() -> 0");
1812 return result;
1815 int Where_history(void) {
1816 int result;
1818 Debug("where_history()");
1819 result = where_history();
1820 Debug1("where_history() -> %d", result);
1821 return result;
1824 void Add_history(const char *string) {
1825 Debug1("add_history(\"%s\")", string);
1826 add_history(string);
1827 Debug("add_history() ->");
1830 #endif /* WITH_READLINE */
1832 #endif /* WITH_SYCLS */