2
* Copyright (C) 2002 Doug Bell <drbell@users.sourceforge.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include <sys/types.h>
39
fifo_t *fifo_new( const char *filename )
41
fifo_t *fifo = malloc( sizeof( struct fifo_s ) );
46
memset( fifo->buf, 0, sizeof( fifo->buf ) );
49
fifo->fd = open( filename, O_RDONLY | O_NONBLOCK );
51
/* Attempt to create it. */
52
if( mkfifo( filename, S_IREAD | S_IWRITE ) < 0 ) {
53
fprintf( stderr, "fifo: Cannot create %s: %s\n",
54
filename, strerror( errno ) );
58
fifo->fd = open( filename, O_RDONLY | O_NONBLOCK );
60
fprintf( stderr, "fifo: Cannot open %s: %s\n",
61
filename, strerror( errno ) );
67
/* Our fifo is open for reading. */
71
static char *fifo_next_line( fifo_t *fifo )
77
while( read( fifo->fd, &c, 1 ) > 0 ) {
78
if( c == '\n' ) return fifo->buf;
80
if( fifo->bufpos == 0 ) continue;
81
fifo->buf[ --fifo->bufpos ] = 0;
84
if( fifo->bufpos < sizeof( fifo->buf ) - 1 )
85
fifo->buf[ fifo->bufpos++ ] = c;
90
int fifo_get_next_command( fifo_t *fifo )
92
char *str = fifo_next_line( fifo );
99
if( !str[ i ] ) break;
100
if( isspace( str[ i ] ) ) {
102
memcpy( fifo->arg, str + i + 1, 255 - i );
107
cmd = tvtime_string_to_command( str );
109
memset( fifo->buf, 0, sizeof( fifo->buf ) );
115
return TVTIME_NOCOMMAND;
118
const char *fifo_get_arguments( fifo_t *fifo )
123
void fifo_delete( fifo_t *fifo )