Back to index

tetex-bin  3.0
Defines | Functions
my-vsnprintf.h File Reference
#include "xdvi-config.h"
#include "xdvi.h"
#include <unistd.h>
#include "util.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define VSNPRINTF(buf, len, format, args)   my_vsnprintf(buf, len, format, args)

Functions

int my_vsnprintf (char *, int, const char *, va_list)

Define Documentation

#define VSNPRINTF (   buf,
  len,
  format,
  args 
)    my_vsnprintf(buf, len, format, args)

Definition at line 41 of file my-vsnprintf.h.


Function Documentation

int my_vsnprintf ( char *  ,
int  ,
const char *  ,
va_list   
)

Definition at line 54 of file my-vsnprintf.c.

{
    int pipe_fd[2];
    FILE *fd;
    int size;
#ifdef DEBUG
    printf("=============my_vsnprintf called!\n");
#endif
    len--;    /* for the trailing '\0' */
    
    /* create a pipe for reading/writing */
    if (xpipe(pipe_fd) == -1) {
       perror("my_vsnprintf: pipe");
       xdvi_exit(EXIT_FAILURE);
    }
    if ((fd = try_fdopen(pipe_fd[1], "w")) == NULL) {
       perror("my_vsnprintf: fdopen");
       xdvi_exit(EXIT_FAILURE);
    }
    /* instead of setting fd to non-buffering, flush it explicitly: */
    /*  setvbuf(fd, NULL, _IONBF, BUFSIZ); */
    size = vfprintf(fd, format, argp);
    fflush(fd);

    /* wrote less characters than len -> adjust len for the subsequent read */
    if (size < len) {
       len = size;
    }
    read(pipe_fd[0], buf, len);
    buf[len] = '\0';     /* always null-terminate */

    fclose(fd);
    close(pipe_fd[0]);
    close(pipe_fd[1]);

    return size;
}

Here is the call graph for this function: