forked from mmitch/gbsplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugout_stdout.c
49 lines (40 loc) · 923 Bytes
/
plugout_stdout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* gbsplay is a Gameboy sound player
*
* 2004 (C) by Christian Garbs <mitch@cgarbs.de>
* Licensed under GNU GPL.
*
* STDOUT file writer output plugin
*/
#include "common.h"
#include <unistd.h>
#include "plugout.h"
int fd;
static long regparm stdout_open(/*@unused@*/ enum plugout_endian endian,
/*@unused@*/ long rate)
{
/*
* clone and close STDOUT_FILENO
* to make sure nobody else can write to stdout
*/
fd = dup(STDOUT_FILENO);
if (fd == -1) return -1;
(void)close(STDOUT_FILENO);
return 0;
}
static ssize_t regparm stdout_write(const void *buf, size_t count)
{
return write(fd, buf, count);
}
static void regparm stdout_close()
{
(void)close(fd);
}
const struct output_plugin plugout_stdout = {
.name = "stdout",
.description = "STDOUT file writer",
.open = stdout_open,
.write = stdout_write,
.close = stdout_close,
.flags = PLUGOUT_USES_STDOUT,
};