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@; 1.19 date 2007.01.01.18.23.53; author rse; state Exp; branches; next 1.18; commitid 9DhdiirNzQPBIP0s; 1.18 date 2006.06.08.17.54.54; author rse; state Exp; branches; next 1.17; commitid x8N3mLVdQgkbdeAr; 1.17 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.16; 1.16 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.15; 1.15 date 2003.01.01.15.49.12; author rse; state Exp; branches; next 1.14; 1.14 date 2002.01.27.11.03.41; author rse; state Exp; branches; next 1.13; 1.13 date 2001.03.24.14.51.05; author rse; state Exp; branches; next 1.12; 1.12 date 99.12.30.21.59.01; author rse; state Exp; branches; next 1.11; 1.11 date 99.11.09.08.11.32; author rse; state Exp; branches; next 1.10; 1.10 date 99.11.01.10.27.21; author rse; state Exp; branches; next 1.9; 1.9 date 99.10.31.11.46.13; author rse; state Exp; branches 1.9.2.1; next 1.8; 1.8 date 99.10.26.13.03.16; author rse; state Exp; branches; next 1.7; 1.7 date 99.09.17.08.01.56; author rse; state Exp; branches; next 1.6; 1.6 date 99.08.28.14.11.41; author rse; state Exp; branches; next 1.5; 1.5 date 99.08.28.13.59.03; author rse; state Exp; branches; next 1.4; 1.4 date 99.08.19.15.08.53; author rse; state Exp; branches; next 1.3; 1.3 date 99.08.17.08.08.36; author rse; state Exp; branches; next 1.2; 1.2 date 99.07.19.06.45.01; author rse; state Exp; branches; next 1.1; 1.1 date 99.07.16.11.15.09; author rse; state Exp; branches; next ; 1.9.2.1 date 99.11.01.10.25.02; author rse; state Exp; branches; next ; desc @@ 1.19 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 . ** ** test_common.c: Pth common test program stuff */ /* ``It doesn't need to be tested, because it works.'' -- Richard Holloway */ #include #include #include #include #include "pth.h" #include "test_common.h" /* * implementation of a convinient greedy tread-safe line reading function to * avoid slow byte-wise reading from filedescriptors - which is important for * high-performance situations. */ #define READLINE_MAXLEN 1024 static pth_key_t readline_key; static pth_once_t readline_once_ctrl = PTH_ONCE_INIT; typedef struct { int rl_cnt; char *rl_bufptr; char rl_buf[READLINE_MAXLEN]; } readline_buf; static void readline_buf_destroy(void *vp) { free(vp); return; } static void readline_init(void *vp) { pth_key_create(&readline_key, readline_buf_destroy); return; } ssize_t pth_readline(int fd, void *buf, size_t buflen) { return pth_readline_ev(fd, buf, buflen, NULL); } ssize_t pth_readline_ev(int fd, void *buf, size_t buflen, pth_event_t ev_extra) { size_t n; ssize_t rc; char c = '\0', *cp; readline_buf *rl; pth_once(&readline_once_ctrl, readline_init, NULL); if ((rl = (readline_buf *)pth_key_getdata(readline_key)) == NULL) { rl = (readline_buf *)malloc(sizeof(readline_buf)); rl->rl_cnt = 0; rl->rl_bufptr = NULL; pth_key_setdata(readline_key, rl); } cp = (char *)buf; for (n = 1; n < buflen; n++) { /* fetch one character (but read more) */ rc = 1; if (rl->rl_cnt <= 0) { if ((rl->rl_cnt = pth_read_ev(fd, rl->rl_buf, READLINE_MAXLEN, ev_extra)) < 0) rc = -1; else if (rl->rl_cnt == 0) rc = 0; else rl->rl_bufptr = rl->rl_buf; } if (rc == 1) { rl->rl_cnt--; c = *rl->rl_bufptr++; } /* act on fetched character */ if (rc == 1) { if (c == '\r') { n--; continue; } *cp++ = c; if (c == '\n') break; } else if (rc == 0) { if (n == 1) return 0; else break; } else return -1; } *cp = NUL; return n; } @ 1.18 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.17 log @Adjusted all copyright messages for new year 2005. @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.16 log @Adjusted all copyright messages for new year 2004. @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.15 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.14 log @bump copyright year @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.13 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.12 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.11 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.10 log @*** empty log message *** @ text @d25 1 a25 1 /* ``It doesn't need to be tested, d111 1 a111 1 } d117 1 a117 1 } @ 1.9 log @*** empty log message *** @ text @d2 1 a2 2 ** test_common.c -- Pth common test program stuff ** d22 2 @ 1.9.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** test_common.c: Pth common test program stuff @ 1.8 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.7 log @*** empty log message *** @ text @d73 1 a73 1 char c, *cp; @ 1.6 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.5 log @*** empty log message *** @ text @a63 14 static ssize_t readline_read(readline_buf *rl, int fd, char *ptr, pth_event_t ev_extra) { if (rl->rl_cnt <= 0) { if ((rl->rl_cnt = pth_read_ev(fd, rl->rl_buf, READLINE_MAXLEN, ev_extra)) < 0) return -1; else if (rl->rl_cnt == 0) return 0; rl->rl_bufptr = rl->rl_buf; } rl->rl_cnt--; *ptr = *rl->rl_bufptr++; return 1; } d85 18 a102 1 if ((rc = readline_read(rl, fd, &c, ev_extra)) == 1) { @ 1.4 log @*** empty log message *** @ text @d67 5 a71 8 for (;;) { if ((rl->rl_cnt = pth_read_ev(fd, rl->rl_buf, READLINE_MAXLEN, ev_extra)) < 0) return -1; else if (rl->rl_cnt == 0) return 0; rl->rl_bufptr = rl->rl_buf; break; } @ 1.3 log @*** empty log message *** @ text @d24 3 a26 1 @ 1.2 log @*** empty log message *** @ text @d86 2 a87 1 int n, rc; d93 1 a93 1 rl = malloc(sizeof(readline_buf)); @ 1.1 log @*** empty log message *** @ text @d32 2 @