File: reader_file.c

package info (click to toggle)
mpc123 0.2.4-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 276 kB
  • sloc: ansic: 773; makefile: 35
file content (74 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (6)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 *  mpc123 - Musepack Console audio player
 *  Copyright (C) 2005-2008 Fernando Vezzosi <fv at linuxvar.it>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software Foundation,
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <unistd.h>
#include <fcntl.h>

#include "mpc123.h"

/* read wrapper */
static mpc_int32_t mpc123_file_read(mpc_reader *t, void *ptr, mpc_int32_t size){
  reader_data *data=(reader_data*) t->data;
  return read(data->fd, ptr, size);
}

/* seek wrapper */
static mpc_bool_t mpc123_file_seek(mpc_reader *t, mpc_int32_t offset){
  reader_data *data=(reader_data*) t->data;
  lseek(data->fd, offset, SEEK_SET);
  return MPC_TRUE;
}

static mpc_int32_t mpc123_file_tell(mpc_reader *t){
  reader_data *data=(reader_data*) t->data;
  return lseek(data->fd, 0, SEEK_CUR);
}

/* get filesize */
static mpc_int32_t mpc123_file_get_size(mpc_reader *t){
  reader_data *data=(reader_data*) t->data;
  off_t old_offset=lseek(data->fd, 0, SEEK_CUR);	/* save old pos */
  mpc_int32_t toret=lseek(data->fd, 0, SEEK_END);

  /* restore old situation */
  lseek(data->fd, old_offset, SEEK_SET);

  return toret;
}

/* on an empty disk, you can seek() forever */
static mpc_bool_t mpc123_file_canseek(mpc_reader *t){
  return MPC_TRUE;
}

/*
 * this provides raw data to the decoder library
 * handles plain files
 */
mpc_reader mpc123_file_reader={
  .read = mpc123_file_read,
  .seek = mpc123_file_seek,
  .tell = mpc123_file_tell,
  .get_size = mpc123_file_get_size,
  .canseek = mpc123_file_canseek,
  .data = NULL		/* reader_data * data */
};

/* vim:ft=c:tw=78:ts=2:et:cin:
 */