"Fossies" - the Fresh Open Source Software Archive

Member "plptools-1.0.15/lib/log.cc" (31 Oct 2019, 1448 Bytes) of package /linux/privat/plptools-1.0.15.tar.gz:


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 "log.cc" see the Fossies "Dox" file reference documentation.

    1 /*-*-c++-*-
    2  * $Id$
    3  *
    4  * This file is part of plptools.
    5  *
    6  *  Copyright (C) 1999  Philip Proudman <philip.proudman@btinternet.com>
    7  *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
    8  *
    9  *  This program is free software; you can redistribute it and/or modify
   10  *  it under the terms of the GNU General Public License as published by
   11  *  the Free Software Foundation; either version 2 of the License, or
   12  *  (at your option) any later version.
   13  *
   14  *  This program is distributed in the hope that it will be useful,
   15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  *  GNU General Public License for more details.
   18  *
   19  *  You should have received a copy of the GNU General Public License
   20  *  along with this program; if not, write to the Free Software
   21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22  *
   23  */
   24 #include "log.h"
   25 
   26 #include <unistd.h>
   27 
   28 logbuf::logbuf(int loglevel, int fd) {
   29     ptr = buf;
   30     len = 0;
   31     _on = true;
   32     _level = loglevel;
   33     _fd = fd;
   34 }
   35 
   36 int logbuf::overflow(int c) {
   37     if (c == '\n') {
   38     *ptr++ = '\n';
   39     *ptr = '\0';
   40     if (_on)
   41         syslog(_level, "%s", buf);
   42     else if (_fd != -1)
   43         write(_fd, buf, len + 1);
   44     ptr = buf;
   45     len = 0;
   46     return 0;
   47     }
   48     if ((len + 2) >= sizeof(buf))
   49     return EOF;
   50     *ptr++ = c;
   51     len++;
   52     return 0;
   53 }
   54 
   55 /*
   56  * Local variables:
   57  * c-basic-offset: 4
   58  * End:
   59  */