1
/* the Music Player Daemon (MPD)
2
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3
* This project's homepage is: http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* 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
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include "input_file.h"
29
input_file_open(struct input_stream *is, const char *filename)
34
if (filename[0] != '/')
37
fd = open(filename, O_RDONLY);
52
if (!S_ISREG(st.st_mode)) {
53
g_debug("Not a regular file: %s\n", filename);
59
is->size = st.st_size;
61
#ifdef POSIX_FADV_SEQUENTIAL
62
posix_fadvise(fd, (off_t)0, is->size, POSIX_FADV_SEQUENTIAL);
65
is->data = GINT_TO_POINTER(fd);
72
input_file_seek(struct input_stream *is, off_t offset, int whence)
74
int fd = GPOINTER_TO_INT(is->data);
76
offset = lseek(fd, offset, whence);
87
input_file_read(struct input_stream *is, void *ptr, size_t size)
89
int fd = GPOINTER_TO_INT(is->data);
92
nbytes = read(fd, ptr, size);
95
g_debug("input_file_read: error reading: %s\n",
100
is->offset += nbytes;
101
return (size_t)nbytes;
105
input_file_close(struct input_stream *is)
107
int fd = GPOINTER_TO_INT(is->data);
113
input_file_eof(struct input_stream *is)
115
return is->offset >= is->size;
119
input_file_buffer(G_GNUC_UNUSED struct input_stream *is)
124
const struct input_plugin input_plugin_file = {
125
.open = input_file_open,
126
.close = input_file_close,
127
.buffer = input_file_buffer,
128
.read = input_file_read,
129
.eof = input_file_eof,
130
.seek = input_file_seek,