OSSP CVS Repository

ossp - ossp-pkg/lmtp2nntp/trace.c
Not logged in
[Honeypot]  [Browse]  [Directory]  [Home]  [Login
[Reports]  [Search]  [Ticket]  [Timeline
  [Raw

ossp-pkg/lmtp2nntp/trace.c
/*
**  Copyright (c) 2001 The OSSP Project <http://www.ossp.org/>
**  Copyright (c) 2001 Cable & Wireless Deutschland <http://www.cw.com/de/>
**
**  This file is part of OSSP lmtp2nntp, an LMTP speaking local
**  mailer which forwards mails as Usenet news articles via NNTP.
**  It can be found at http://www.ossp.org/pkg/lmtp2nntp/.
**
**  This program is free software; you can redistribute it and/or
**  modify it under the terms of the GNU General Public  License
**  as published by the Free Software Foundation; either version
**  2.0 of the License, or (at your option) any later version.
**
**  This program 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
**  General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with this file; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
**  USA, or contact the OSSP project <ossp@ossp.org>.
**
**  trace.c: I/O tracing support
*/

#include <errno.h>
#include <limits.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_DMALLOC_H) && defined(DMALLOC)
#include "dmalloc.h"
#endif

#include "trace.h"

#ifndef _POSIX_PATH_MAX
#if defined(PATH_MAX)
#define _POSIX_PATH_MAX PATH_MAX
#elif defined(MAX_PATH)
#define _POSIX_PATH_MAX MAX_PATH
#else
#error "unable to determime maximum path limit"
#endif
#endif

/*
 * tracing
 */

ssize_t trace_read(int d, void *buf, size_t nbytes)
{
    ssize_t rc;
    int tf;
    static char tfn[_POSIX_PATH_MAX] = "/tmp/trace";

    if ((d == -1) && (buf != NULL) && (nbytes == 0)) {
        strncpy(tfn, buf, _POSIX_PATH_MAX-1);
    }
    rc = read(d, buf, nbytes);
    if ((tf = open(tfn, O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
        write(tf, buf, rc);
        close(tf);
    }
    return rc;
}

ssize_t trace_write(int d, const void *buf, size_t nbytes)
{
    ssize_t rc;
    int tf;
    static char tfn[_POSIX_PATH_MAX] = "/tmp/trace";

    if ((d == -1) && (buf != NULL) && (nbytes == 0)) {
        strncpy(tfn, buf, _POSIX_PATH_MAX-1);
    }

    rc = write(d, buf, nbytes);
    if ((tf = open(tfn, O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
        write(tf, buf, rc);
        close(tf);
    }
    return rc;
}


CVSTrac 2.0.1