"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/mgetaline.c" (28 Dec 2021, 1867 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mgetaline.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.11.12_vs_1.12.0.

    1 /*
    2 mgetaline.c -- getaline with timeout, split from the NNTP server
    3 
    4 Written by Arnt Gulbrandsen <agulbra@troll.no> and copyright 1995
    5 Troll Tech AS, Postboks 6133 Etterstad, 0602 Oslo, Norway, fax +47
    6 22646949.
    7 Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>
    8 and Randolf Skerka <Randolf.Skerka@gmx.de>.
    9 Copyright of the modifications 1997.
   10 Modified by Kent Robotti <robotti@erols.com>. Copyright of the
   11 modifications 1998.
   12 Modified by Markus Enzenberger <enz@cip.physik.uni-muenchen.de>.
   13 Copyright of the modifications 1998.
   14 Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>
   15 and Kazushi (Jam) Marukawa <jam@pobox.com>.
   16 Copyright of the modifications 1998, 1999.
   17 Modified by Ralf Wildenhues <ralf.wildenhues@gmx.de>
   18 Copyright of the modifications 2002.
   19 Modified by Richard van der Hoff <richard@rvanderhoff.org.uk>
   20 Copyright of the modifications 2002.
   21 Modified by Matthias Andree <matthias.andree@gmx.de>
   22 Copyright of the modifications 2000 - 2010.
   23 
   24 See file COPYING for restrictions on the use of this software.
   25 */
   26 
   27 #include "leafnode.h"
   28 #include "mysigact.h"
   29 
   30 #include <sys/types.h>
   31 #include <signal.h>
   32 #include <stdlib.h>
   33 #include <unistd.h>
   34 #include <setjmp.h>
   35 #include <stdio.h>
   36 
   37 static unsigned int timeout_secs;
   38 
   39 sigjmp_buf timeout;
   40 
   41 void timer(int sig)
   42 {
   43     siglongjmp(timeout, 1);
   44     exit(sig);          /* not reached */
   45 }
   46 
   47 /*
   48  * call getaline with config specified timeout
   49  */
   50 /*@dependent@*/ char *
   51 mgetaline(FILE * f)
   52 {
   53     char *l;
   54 
   55     if (sigsetjmp(timeout,1)) {
   56     if (debug)
   57         syslog(LOG_DEBUG, "< (ERROR: timeout - no response in %u s)", timeout_secs);
   58     return NULL;
   59     }
   60     mysigact(SIGALRM, SA_RESETHAND, timer, 0);
   61     (void)alarm(timeout_secs);
   62     l = getaline(f);
   63     (void)alarm(0U);
   64     mysigact(SIGALRM, 0, SIG_DFL, 0);
   65     return l;
   66 }
   67 
   68 void
   69 mgetaline_settimeout(unsigned int t) {
   70     timeout_secs = t;
   71 }