Blame gst/printf/printf.c

Packit f546b1
/* GLIB - Library of useful routines for C programming
Packit f546b1
 * Copyright (C) 2003 Matthias Clasen
Packit f546b1
 *
Packit f546b1
 * This library is free software; you can redistribute it and/or
Packit f546b1
 * modify it under the terms of the GNU Lesser General Public
Packit f546b1
 * License as published by the Free Software Foundation; either
Packit f546b1
 * version 2 of the License, or (at your option) any later version.
Packit f546b1
 *
Packit f546b1
 * This library is distributed in the hope that it will be useful,
Packit f546b1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit f546b1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit f546b1
 * Lesser General Public License for more details.
Packit f546b1
 *
Packit f546b1
 * You should have received a copy of the GNU Lesser General Public
Packit f546b1
 * License along with this library; if not, write to the
Packit f546b1
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit f546b1
 * Boston, MA 02111-1307, USA.
Packit f546b1
 */
Packit f546b1
Packit f546b1
/*
Packit f546b1
 * Modified by the GLib Team and others 2003.  See the AUTHORS
Packit f546b1
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit f546b1
 * files for a list of changes.  These files are distributed with
Packit f546b1
 * GLib at ftp://ftp.gtk.org/pub/gtk/.
Packit f546b1
 */
Packit f546b1
Packit f546b1
#ifdef HAVE_CONFIG_H
Packit f546b1
# include <config.h>
Packit f546b1
#endif
Packit f546b1
#include <string.h>
Packit f546b1
#include <stdlib.h>
Packit f546b1
#include <stdio.h>
Packit f546b1
#include "gst-printf.h"
Packit f546b1
#include "vasnprintf.h"
Packit f546b1
#include "printf.h"
Packit f546b1
Packit f546b1
#if 0
Packit f546b1
int
Packit f546b1
__gst_printf (char const *format, ...)
Packit f546b1
{
Packit f546b1
  va_list args;
Packit f546b1
  int retval;
Packit f546b1
Packit f546b1
  va_start (args, format);
Packit f546b1
  retval = __gst_vprintf (format, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return retval;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_fprintf (FILE * file, char const *format, ...)
Packit f546b1
{
Packit f546b1
  va_list args;
Packit f546b1
  int retval;
Packit f546b1
Packit f546b1
  va_start (args, format);
Packit f546b1
  retval = __gst_vfprintf (file, format, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return retval;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_sprintf (char *string, char const *format, ...)
Packit f546b1
{
Packit f546b1
  va_list args;
Packit f546b1
  int retval;
Packit f546b1
Packit f546b1
  va_start (args, format);
Packit f546b1
  retval = __gst_vsprintf (string, format, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return retval;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_snprintf (char *string, size_t n, char const *format, ...)
Packit f546b1
{
Packit f546b1
  va_list args;
Packit f546b1
  int retval;
Packit f546b1
Packit f546b1
  va_start (args, format);
Packit f546b1
  retval = __gst_vsnprintf (string, n, format, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return retval;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_vprintf (char const *format, va_list args)
Packit f546b1
{
Packit f546b1
  return __gst_vfprintf (stdout, format, args);
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_vfprintf (FILE * file, char const *format, va_list args)
Packit f546b1
{
Packit f546b1
  char *result;
Packit f546b1
  size_t length;
Packit f546b1
Packit f546b1
  result = vasnprintf (NULL, &length, format, args);
Packit f546b1
  if (result == NULL)
Packit f546b1
    return -1;
Packit f546b1
Packit f546b1
  fwrite (result, 1, length, file);
Packit f546b1
  free (result);
Packit f546b1
Packit f546b1
  return length;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_vsprintf (char *string, char const *format, va_list args)
Packit f546b1
{
Packit f546b1
  char *result;
Packit f546b1
  size_t length;
Packit f546b1
Packit f546b1
  result = vasnprintf (NULL, &length, format, args);
Packit f546b1
  if (result == NULL)
Packit f546b1
    return -1;
Packit f546b1
Packit f546b1
  memcpy (string, result, length + 1);
Packit f546b1
  free (result);
Packit f546b1
Packit f546b1
  return length;
Packit f546b1
}
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_vsnprintf (char *string, size_t n, char const *format, va_list args)
Packit f546b1
{
Packit f546b1
  char *result;
Packit f546b1
  size_t length;
Packit f546b1
Packit f546b1
  result = vasnprintf (NULL, &length, format, args);
Packit f546b1
  if (result == NULL)
Packit f546b1
    return -1;
Packit f546b1
Packit f546b1
  if (n > 0) {
Packit f546b1
    memcpy (string, result, MIN (length + 1, n));
Packit f546b1
    string[n - 1] = 0;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  free (result);
Packit f546b1
Packit f546b1
  return length;
Packit f546b1
}
Packit f546b1
#endif
Packit f546b1
Packit f546b1
int
Packit f546b1
__gst_vasprintf (char **result, char const *format, va_list args)
Packit f546b1
{
Packit f546b1
  size_t length;
Packit f546b1
Packit f546b1
  *result = vasnprintf (NULL, &length, format, args);
Packit f546b1
  if (*result == NULL)
Packit f546b1
    return -1;
Packit f546b1
Packit f546b1
  return length;
Packit f546b1
}