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.9 PTH_1_0b7:1.9 PTH_1_0b6:1.9 PTH_1_0b5:1.9 PTH_1_0b4:1.7 PTH_1_0b3:1.5 PTH_1_0b2:1.5 PTH_1_0b1:1.4 PTH_0_9_21:1.1 PTH_0_9_20:1.1 PTH_0_9_19:1.1 PTH_0_9_18:1.1 PTH_0_9_17:1.1 PTH_0_9_16:1.1; locks; strict; comment @ * @; 1.27 date 2007.01.01.18.23.53; author rse; state Exp; branches; next 1.26; commitid 9DhdiirNzQPBIP0s; 1.26 date 2006.06.08.17.54.53; author rse; state Exp; branches; next 1.25; commitid x8N3mLVdQgkbdeAr; 1.25 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.24; 1.24 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.23; 1.23 date 2003.01.01.15.49.12; author rse; state Exp; branches; next 1.22; 1.22 date 2002.10.24.09.07.51; author rse; state Exp; branches; next 1.21; 1.21 date 2002.01.27.13.15.28; author rse; state Exp; branches; next 1.20; 1.20 date 2002.01.27.11.03.41; author rse; state Exp; branches; next 1.19; 1.19 date 2001.03.24.14.51.05; author rse; state Exp; branches; next 1.18; 1.18 date 99.12.30.21.59.01; author rse; state Exp; branches; next 1.17; 1.17 date 99.11.09.08.11.32; author rse; state Exp; branches; next 1.16; 1.16 date 99.11.01.10.27.20; author rse; state Exp; branches; next 1.15; 1.15 date 99.10.31.11.46.13; author rse; state Exp; branches 1.15.2.1; next 1.14; 1.14 date 99.09.17.08.01.56; author rse; state Exp; branches; next 1.13; 1.13 date 99.09.01.08.51.24; author rse; state Exp; branches; next 1.12; 1.12 date 99.08.19.15.08.53; author rse; state Exp; branches; next 1.11; 1.11 date 99.08.13.13.35.59; author rse; state Exp; branches; next 1.10; 1.10 date 99.07.19.08.09.58; author rse; state Exp; branches; next 1.9; 1.9 date 99.07.11.11.55.21; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.09.08.06.41; author rse; state Exp; branches; next 1.7; 1.7 date 99.07.08.10.34.01; author rse; state Exp; branches; next 1.6; 1.6 date 99.07.08.10.19.11; author rse; state Exp; branches; next 1.5; 1.5 date 99.07.04.12.05.36; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.28.10.22.10; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.27.15.38.04; author rse; state Exp; branches; next 1.2; 1.2 date 99.06.27.12.58.40; author rse; state Exp; branches; next 1.1; 1.1 date 99.06.04.21.26.10; author rse; state Exp; branches; next ; 1.15.2.1 date 99.11.01.10.25.01; author rse; state Exp; branches; next ; desc @@ 1.27 log @Adjusted all copyright messages for new year 2007. @ text @/* ** GNU Pth - The GNU Portable Threads ** Copyright (c) 1999-2007 Ralf S. Engelschall ** ** This file is part of GNU Pth, a non-preemptive thread scheduling ** library which can be found at http://www.gnu.org/software/pth/. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License as published by the Free Software Foundation; either ** version 2.1 of the License, or (at your option) any later version. ** ** This library is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public ** License along with this library; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** USA, or contact Ralf S. Engelschall . ** ** pth_util.c: Pth utility functions */ /* ``Premature optimization is the root of all evil.'' -- D.E.Knuth */ #include "pth_p.h" /* calculate numerical mimimum */ #if cpp #define pth_util_min(a,b) \ ((a) > (b) ? (b) : (a)) #endif /* delete a pending signal */ static void pth_util_sigdelete_sighandler(int _sig) { /* nop */ return; } intern int pth_util_sigdelete(int sig) { sigset_t ss, oss; struct sigaction sa, osa; /* check status of signal */ sigpending(&ss); if (!sigismember(&ss, sig)) return FALSE; /* block signal and remember old mask */ sigemptyset(&ss); sigaddset(&ss, sig); pth_sc(sigprocmask)(SIG_BLOCK, &ss, &oss); /* set signal action to our dummy handler */ sa.sa_handler = pth_util_sigdelete_sighandler; sigfillset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(sig, &sa, &osa) != 0) { pth_sc(sigprocmask)(SIG_SETMASK, &oss, NULL); return FALSE; } /* now let signal be delivered */ sigfillset(&ss); sigdelset(&ss, sig); sigsuspend(&ss); /* restore signal mask and handler */ sigaction(sig, &osa, NULL); pth_sc(sigprocmask)(SIG_SETMASK, &oss, NULL); return TRUE; } /* copy a string like strncpy() but always null-terminate */ intern char *pth_util_cpystrn(char *dst, const char *src, size_t dst_size) { register char *d, *end; if (dst_size == 0) return dst; d = dst; end = dst + dst_size - 1; for (; d < end; ++d, ++src) { if ((*d = *src) == '\0') return d; } *d = '\0'; return d; } /* check whether a file-descriptor is valid */ intern int pth_util_fd_valid(int fd) { if (fd < 0 || fd >= FD_SETSIZE) return FALSE; if (fcntl(fd, F_GETFL) == -1 && errno == EBADF) return FALSE; return TRUE; } /* merge input fd set into output fds */ intern void pth_util_fds_merge(int nfd, fd_set *ifds1, fd_set *ofds1, fd_set *ifds2, fd_set *ofds2, fd_set *ifds3, fd_set *ofds3) { register int s; for (s = 0; s < nfd; s++) { if (ifds1 != NULL) if (FD_ISSET(s, ifds1)) FD_SET(s, ofds1); if (ifds2 != NULL) if (FD_ISSET(s, ifds2)) FD_SET(s, ofds2); if (ifds3 != NULL) if (FD_ISSET(s, ifds3)) FD_SET(s, ofds3); } return; } /* test whether fds in the input fd sets occurred in the output fds */ intern int pth_util_fds_test(int nfd, fd_set *ifds1, fd_set *ofds1, fd_set *ifds2, fd_set *ofds2, fd_set *ifds3, fd_set *ofds3) { register int s; for (s = 0; s < nfd; s++) { if (ifds1 != NULL) if (FD_ISSET(s, ifds1) && FD_ISSET(s, ofds1)) return TRUE; if (ifds2 != NULL) if (FD_ISSET(s, ifds2) && FD_ISSET(s, ofds2)) return TRUE; if (ifds3 != NULL) if (FD_ISSET(s, ifds3) && FD_ISSET(s, ofds3)) return TRUE; } return FALSE; } /* * clear fds in input fd sets if not occurred in output fd sets and return * number of remaining input fds. This number uses BSD select(2) semantics: a * fd in two set counts twice! */ intern int pth_util_fds_select(int nfd, fd_set *ifds1, fd_set *ofds1, fd_set *ifds2, fd_set *ofds2, fd_set *ifds3, fd_set *ofds3) { register int s; register int n; n = 0; for (s = 0; s < nfd; s++) { if (ifds1 != NULL && FD_ISSET(s, ifds1)) { if (!FD_ISSET(s, ofds1)) FD_CLR(s, ifds1); else n++; } if (ifds2 != NULL && FD_ISSET(s, ifds2)) { if (!FD_ISSET(s, ofds2)) FD_CLR(s, ifds2); else n++; } if (ifds3 != NULL && FD_ISSET(s, ifds3)) { if (!FD_ISSET(s, ofds3)) FD_CLR(s, ifds3); else n++; } } return n; } @ 1.26 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.25 log @Adjusted all copyright messages for new year 2005. @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.24 log @Adjusted all copyright messages for new year 2004. @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.23 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.22 log @Added POSIX-compliant sanity checks for bad filedescriptors to mostly all filedescriptor-based I/O functions in pth_high.c @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.21 log @Internally make sure an invalid file-descriptor (integer not between 0 and (FD_SETSIZE-1) does not lead to any segfaults or other undefined behaviour. Instead an error is returned and errno is set to EBADF, similar to what the OS functions do. Especially pth_poll() now return with this error (instead of skipping the fd) if an fd in the "struct pollfd" is invalid. Hint by: Archie Cobbs @ text @d95 8 a102 7 #if cpp #if !defined(FD_SETSIZE) #define FD_SETSIZE 1024 #endif #define pth_util_fd_valid(fd) \ ((fd) >= 0 && (fd) <= (FD_SETSIZE-1)) #endif @ 1.20 log @bump copyright year @ text @d94 9 @ 1.19 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.18 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.17 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.16 log @*** empty log message *** @ text @d25 1 a25 1 /* ``Premature optimization is d56 1 a56 1 d95 1 a95 1 intern void pth_util_fds_merge(int nfd, d117 3 a119 3 intern int pth_util_fds_test(int nfd, fd_set *ifds1, fd_set *ofds1, fd_set *ifds2, fd_set *ofds2, d138 1 a138 1 /* d143 3 a145 3 intern int pth_util_fds_select(int nfd, fd_set *ifds1, fd_set *ofds1, fd_set *ifds2, fd_set *ofds2, @ 1.15 log @*** empty log message *** @ text @d2 1 a2 2 ** pth_util.c -- Pth utility functions ** d22 2 @ 1.15.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** pth_util.c: Pth utility functions @ 1.14 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.13 log @*** empty log message *** @ text @d10 1 a10 1 ** modify it under the terms of the GNU Library General Public d17 1 a17 1 ** Library General Public License for more details. d19 1 a19 1 ** You should have received a copy of the GNU Library General Public @ 1.12 log @*** empty log message *** @ text @d47 5 d54 1 a54 6 sigprocmask(SIG_BLOCK, &ss, &oss); sigpending(&ss); if (!sigismember(&ss, sig)) { sigprocmask(SIG_SETMASK, &oss, NULL); return FALSE; } d57 1 a57 1 memset((void *)&sa, 0, sizeof(struct sigaction)); d59 1 a59 1 sa.sa_handler = pth_util_sigdelete_sighandler; d61 1 a61 1 sigprocmask(SIG_SETMASK, &oss, NULL); d72 1 a72 1 sigprocmask(SIG_SETMASK, &oss, NULL); @ 1.11 log @*** empty log message *** @ text @d24 3 a26 1 @ 1.10 log @*** empty log message *** @ text @d99 1 a99 1 for (s = 0; s <= nfd-1; s++) { d121 1 a121 1 for (s = 0; s <= nfd-1; s++) { d149 1 a149 1 for (s = 0; s <= nfd-1; s++) { @ 1.9 log @*** empty log message *** @ text @d27 6 @ 1.8 log @*** empty log message *** @ text @d144 18 a161 12 if (ifds1 != NULL && FD_ISSET(s, ifds1) && !FD_ISSET(s, ofds1)) FD_CLR(s, ifds1); else n++; if (ifds2 != NULL && FD_ISSET(s, ifds2) && !FD_ISSET(s, ofds2)) FD_CLR(s, ifds2); else n++; if (ifds3 != NULL && FD_ISSET(s, ifds3) && !FD_ISSET(s, ofds3)) FD_CLR(s, ifds3); else n++; @ 1.7 log @*** empty log message *** @ text @d85 75 @ 1.6 log @*** empty log message *** @ text @d2 1 a2 1 ** pth_util.c -- PTH utility functions @ 1.5 log @*** empty log message *** @ text @d6 2 a7 2 ** This file is part of PTH, a non-preemptive thread scheduling library ** which can be found at http://www.gnu.org/software/pth/. @ 1.4 log @*** empty log message *** @ text @d7 1 a7 1 ** which can be found at http://www.engelschall.com/sw/pth/. @ 1.3 log @*** empty log message *** @ text @d28 1 a28 1 static void pth_util_sigdelete_sighandler(int sig) d68 1 d81 1 a81 1 *d = '\0'; /* always null terminate */ @ 1.2 log @*** empty log message *** @ text @d70 1 a70 1 char *d, *end; @ 1.1 log @*** empty log message *** @ text @d68 16 @