~ubuntu-branches/ubuntu/raring/mpc123/raring

« back to all changes in this revision

Viewing changes to reader_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniele Sempione
  • Date: 2006-01-06 11:39:37 UTC
  • Revision ID: james.westby@ubuntu.com-20060106113937-yq03rdkr11rywj6v
Tags: upstream-0.1.9
ImportĀ upstreamĀ versionĀ 0.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  mpc123 - Musepack Console audio player
 
3
 *  Copyright (C) 2005 Fernando Vezzosi <fvezzosi at masobit.net>
 
4
 *
 
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.
 
9
 *
 
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
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software Foundation,
 
17
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <unistd.h>
 
21
#include <fcntl.h>
 
22
 
 
23
#include "mpc123.h"
 
24
 
 
25
#include <mpcdec/config_types.h>
 
26
#include <mpcdec/mpcdec.h>
 
27
 
 
28
/* read wrapper */
 
29
static mpc_int32_t mpc123_file_read(void *t, void *ptr, mpc_int32_t size){
 
30
  reader_data *data=(reader_data*) t;
 
31
  return read(data->fd, ptr, size);
 
32
}
 
33
 
 
34
/* seek wrapper */
 
35
static mpc_bool_t mpc123_file_seek(void *t, mpc_int32_t offset){
 
36
  reader_data *data=(reader_data*) t;
 
37
  lseek(data->fd, offset, SEEK_SET);
 
38
  return TRUE;
 
39
}
 
40
 
 
41
static mpc_int32_t mpc123_file_tell(void *t){
 
42
  reader_data *data=(reader_data*) t;
 
43
  return lseek(data->fd, 0, SEEK_CUR);
 
44
}
 
45
 
 
46
/* get filesize */
 
47
static mpc_int32_t mpc123_file_get_size(void *t){
 
48
  reader_data *data=(reader_data*) t;
 
49
  off_t old_offset=lseek(data->fd, 0, SEEK_CUR);        /* save old pos */
 
50
  mpc_int32_t toret=lseek(data->fd, 0, SEEK_END);
 
51
 
 
52
  /* restore old situation */
 
53
  lseek(data->fd, old_offset, SEEK_SET);
 
54
 
 
55
  return toret;
 
56
}
 
57
 
 
58
/* on an empty disk, you can seek() forever */
 
59
static mpc_bool_t mpc123_file_canseek(void *t){
 
60
  return TRUE;
 
61
}
 
62
 
 
63
/*
 
64
 * this provides raw data to the decoder library
 
65
 * handles plain files
 
66
 */
 
67
mpc_reader mpc123_file_reader={
 
68
  .read=mpc123_file_read,
 
69
  .seek=mpc123_file_seek,
 
70
  .tell=mpc123_file_tell,
 
71
  .get_size=mpc123_file_get_size,
 
72
  .canseek=mpc123_file_canseek,
 
73
  .data=NULL            /* reader_data * data */
 
74
};