1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Added igloo_stdio_new_file()

This commit is contained in:
Philipp Schafft 2019-06-27 11:55:34 +00:00
parent 812a2ccaaf
commit f5bc4e77c4
3 changed files with 118 additions and 0 deletions

View File

@ -22,6 +22,7 @@ pkginclude_HEADERS = \
include/igloo/typedef.h \
include/igloo/interface.h \
include/igloo/io.h \
include/igloo/stdio.h \
include/igloo/buffer.h \
include/igloo/list.h \
include/igloo/reportxml.h
@ -31,6 +32,7 @@ libigloo_la_SOURCES = \
src/interface.c \
src/ro.c \
src/io.c \
src/stdio.c \
src/buffer.c \
src/list.c \
src/reportxml.c

40
include/igloo/stdio.h Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2019 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _LIBIGLOO__STDIO_H_
#define _LIBIGLOO__STDIO_H_
/**
* @file
* Put a good description of this file here
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Put stuff here */
#include "io.h"
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated);
#ifdef __cplusplus
}
#endif
#endif /* ! _LIBIGLOO__STDIO_H_ */

76
src/stdio.c Normal file
View File

@ -0,0 +1,76 @@
/* Icecast
*
* This program is distributed under the GNU General Public License, version 2.
* A copy of this license is included with this source.
*
* Copyright 2019, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <igloo/io.h>
static int __free(igloo_INTERFACE_BASIC_ARGS)
{
fclose(*backend_userdata);
*backend_userdata = NULL;
return 0;
}
static ssize_t __read(igloo_INTERFACE_BASIC_ARGS, void *buffer, size_t len)
{
return fread(buffer, 1, len, *backend_userdata);
}
static ssize_t __write(igloo_INTERFACE_BASIC_ARGS, const void *buffer, size_t len)
{
return fwrite(buffer, 1, len, *backend_userdata);
}
static int __flush(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags)
{
return fflush(*backend_userdata) == 0 ? 0 : -1;
}
static int __sync(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags)
{
return 0;
}
static libigloo_io_blockingmode_t __get_blockingmode(igloo_INTERFACE_BASIC_ARGS)
{
return igloo_IO_BLOCKINGMODE_FULL;
}
static int __get_fd_for_systemcall(igloo_INTERFACE_BASIC_ARGS)
{
return fileno(*backend_userdata);
}
static const igloo_io_ifdesc_t igloo_stdio_ifdesc = {
.__base = {.free = __free},
.read = __read,
.write = __write,
.flush = __flush,
.sync = __sync,
.get_blockingmode = __get_blockingmode,
.get_fd_for_systemcall = __get_fd_for_systemcall
};
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated)
{
FILE *file = fopen(filename, mode);
igloo_io_t *io;
if (!file)
return NULL;
io = igloo_io_new(&igloo_stdio_ifdesc, igloo_RO_NULL, file, name, associated);
if (!io) {
fclose(file);
return io;
}
return io;
}