Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jul 2000 19:08:51 -0400
From:      "Thomas M. Sommers" <tms2@mail.ptd.net>
To:        Dag-Erling Smorgrav <des@flood.ping.uio.no>, Mike Pritchard <mpp@mppsystems.com>, Alfred Perlstein <bright@wintelcom.net>, arch@FreeBSD.ORG
Subject:   Re: kernel printf %i?
Message-ID:  <396CFA83.BCB82874@mail.ptd.net>
References:  <5lzonpbc53.fsf@assaris.sics.se> <57067.963303670@axl.ops.uunet.co.za> <20000711013227.P25571@fw.wintelcom.net> <20000711041415.A16480@mppsystems.com> <xzpsntfg623.fsf@flood.ping.uio.no> <396CEA70.2C7A69B3@mail.ptd.net>

next in thread | previous in thread | raw e-mail | index | archive | help
"Thomas M. Sommers" wrote:
> 
> Dag-Erling Smorgrav wrote:
> >
> > Speaking of printf(), there are two things I'd like to see added:
> >
> >  - in libc, a *dprintf() family similar to *fprintf() except that they
> >    write to a file descriptor instead of a FILE *.
> 
> How about something like this:
> 

<bad code snipped>

Or better yet, this:

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int dprintf(int fd, const char *format, ...)
{
    char    *buf;
    int     err = -1;
    int     len;
    va_list args;

    va_start(args, format);
    len = vasprintf(&buf, format, args);
    va_end(args);

    if ( len != -1 ) {
        err = write(fd, buf, len);
        free(buf);
    }
    else {
        errno = ENOMEM;
    }

    return err;
}

Thanks to Steve Kargl <sgk@troutmask.apl.washington.edu> for pointing
out my error.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?396CFA83.BCB82874>