libmpcdec: src/mpc_reader.c Source File

Main Page | Class List | Directories | File List | Class Members | File Members | Related Pages

# mpc_reader.c

Go to the documentation of this file.

    00001 /*
    00002   Copyright (c) 2005, The Musepack Development Team
    00003   All rights reserved.
    00004
    00005   Redistribution and use in source and binary forms, with or without
    00006   modification, are permitted provided that the following conditions are
    00007   met:
    00008
    00009   * Redistributions of source code must retain the above copyright
    00010   notice, this list of conditions and the following disclaimer.
    00011
    00012   * Redistributions in binary form must reproduce the above
    00013   copyright notice, this list of conditions and the following
    00014   disclaimer in the documentation and/or other materials provided
    00015   with the distribution.
    00016
    00017   * Neither the name of the The Musepack Development Team nor the
    00018   names of its contributors may be used to endorse or promote
    00019   products derived from this software without specific prior
    00020   written permission.
    00021
    00022   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00023   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00024   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00025   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    00026   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00027   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00028   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    00029   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    00030   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00031   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00032   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00033 */
    00034
    00037
    00038 #include <mpcdec/mpcdec.h>
    00039
    00041 static mpc_int32_t
    00042 read_impl(void *data, void *ptr, mpc_int32_t size)
    00043 {
    00044     mpc_reader_file *d = (mpc_reader_file *) data;
    00045
    00046     return fread(ptr, 1, size, d->file);
    00047 }
    00048
    00049 static mpc_bool_t
    00050 seek_impl(void *data, mpc_int32_t offset)
    00051 {
    00052     mpc_reader_file *d = (mpc_reader_file *) data;
    00053
    00054     return d->is_seekable ? !fseek(d->file, offset, SEEK_SET) : FALSE;
    00055 }
    00056
    00057 static mpc_int32_t
    00058 tell_impl(void *data)
    00059 {
    00060     mpc_reader_file *d = (mpc_reader_file *) data;
    00061
    00062     return ftell(d->file);
    00063 }
    00064
    00065 static mpc_int32_t
    00066 get_size_impl(void *data)
    00067 {
    00068     mpc_reader_file *d = (mpc_reader_file *) data;
    00069
    00070     return d->file_size;
    00071 }
    00072
    00073 static mpc_bool_t
    00074 canseek_impl(void *data)
    00075 {
    00076     mpc_reader_file *d = (mpc_reader_file *) data;
    00077
    00078     return d->is_seekable;
    00079 }
    00080
    00081 void
    00082 mpc_reader_setup_file_reader(mpc_reader_file *p_reader, FILE *input)
    00083 {
    00084     p_reader->reader.seek = seek_impl;
    00085     p_reader->reader.read = read_impl;
    00086     p_reader->reader.tell = tell_impl;
    00087     p_reader->reader.get_size = get_size_impl;
    00088     p_reader->reader.canseek = canseek_impl;
    00089     p_reader->reader.data = p_reader; // point back to ourselves
    00090
    00091     p_reader->file = input;
    00092     p_reader->is_seekable = TRUE;
    00093     fseek(input, 0, SEEK_END);
    00094     p_reader->file_size = ftell(input);
    00095     fseek(input, 0, SEEK_SET);
    00096 }