Blame gettext-tools/libgettextpo/file-ostream.oo.c

Packit Bot 06c835
/* Output stream referring to an stdio FILE.
Packit Bot 06c835
   Copyright (C) 2006, 2015 Free Software Foundation, Inc.
Packit Bot 06c835
   Written by Bruno Haible <bruno@clisp.org>, 2006.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software: you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3 of the License, or
Packit Bot 06c835
   (at your option) any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
#include <config.h>
Packit Bot 06c835
Packit Bot 06c835
/* Specification.  */
Packit Bot 06c835
#include "file-ostream.h"
Packit Bot 06c835
Packit Bot 06c835
#include <stdlib.h>
Packit Bot 06c835
Packit Bot 06c835
#include "xalloc.h"
Packit Bot 06c835
Packit Bot 06c835
struct file_ostream : struct ostream
Packit Bot 06c835
{
Packit Bot 06c835
fields:
Packit Bot 06c835
  FILE *fp;
Packit Bot 06c835
};
Packit Bot 06c835
Packit Bot 06c835
/* Implementation of ostream_t methods.  */
Packit Bot 06c835
Packit Bot 06c835
static void
Packit Bot 06c835
file_ostream::write_mem (file_ostream_t stream, const void *data, size_t len)
Packit Bot 06c835
{
Packit Bot 06c835
  if (len > 0)
Packit Bot 06c835
    fwrite (data, 1, len, stream->fp);
Packit Bot 06c835
}
Packit Bot 06c835
Packit Bot 06c835
static void
Packit Bot 06c835
file_ostream::flush (file_ostream_t stream)
Packit Bot 06c835
{
Packit Bot 06c835
  /* This ostream has no internal buffer.  No need to fflush (stream->fp),
Packit Bot 06c835
     since it's external to this ostream.  */
Packit Bot 06c835
}
Packit Bot 06c835
Packit Bot 06c835
static void
Packit Bot 06c835
file_ostream::free (file_ostream_t stream)
Packit Bot 06c835
{
Packit Bot 06c835
  free (stream);
Packit Bot 06c835
}
Packit Bot 06c835
Packit Bot 06c835
/* Constructor.  */
Packit Bot 06c835
Packit Bot 06c835
file_ostream_t
Packit Bot 06c835
file_ostream_create (FILE *fp)
Packit Bot 06c835
{
Packit Bot 06c835
  file_ostream_t stream = XMALLOC (struct file_ostream_representation);
Packit Bot 06c835
Packit Bot 06c835
  stream->base.vtable = &file_ostream_vtable;
Packit Bot 06c835
  stream->fp = fp;
Packit Bot 06c835
Packit Bot 06c835
  return stream;
Packit Bot 06c835
}