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

« back to all changes in this revision

Viewing changes to reader.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 <string.h>
 
21
#include <fcntl.h>
 
22
#include <errno.h>
 
23
#include <unistd.h>
 
24
 
 
25
#include "mpc123.h"
 
26
 
 
27
/*
 
28
 * select which mpc_reader to use, based on filename
 
29
 * currently it knows about:
 
30
 * - plain file
 
31
 */
 
32
int reader_choose_and_prepare(const char * fname, mpc_reader ** ret,
 
33
                              reader_data * data){
 
34
  /* default to plain file reader */
 
35
  debugf("choosing plain file reader for \"%s\"", fname);
 
36
  data->fd=open(fname, O_RDONLY);
 
37
  if(data->fd == -1){
 
38
    dief("Couldn't open file \"%s\": [%d] %s",
 
39
         fname, errno, (errno == 0 ? "Unknown reason" : strerror(errno) ));
 
40
  }
 
41
  *ret=&mpc123_file_reader;
 
42
  (*ret)->data=data;
 
43
  return 0;
 
44
}
 
45
 
 
46
/*
 
47
 * cleans up things needed for each reader 
 
48
 * knows about:
 
49
 * - plain files
 
50
 */
 
51
void do_cleanup_stream(mpc_reader * the_reader, reader_data * the_data){
 
52
  /*
 
53
   * plain file reader,
 
54
   * nothing special
 
55
   */
 
56
  if(the_reader == &mpc123_file_reader){
 
57
    close(the_data->fd);
 
58
    the_data->fd = -1;
 
59
  }
 
60
}