libopenmpt 0.7.11+release
cross-platform C++ and C library to decode tracked music files
libopenmpt_stream_callbacks_file.h
Go to the documentation of this file.
1/*
2 * libopenmpt_stream_callbacks_file.h
3 * ----------------------------------
4 * Purpose: libopenmpt public c interface
5 * Notes : (currently none)
6 * Authors: OpenMPT Devs
7 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
8 */
9
10#ifndef LIBOPENMPT_STREAM_CALLBACKS_FILE_H
11#define LIBOPENMPT_STREAM_CALLBACKS_FILE_H
12
13#include "libopenmpt.h"
14
15#include <stdint.h>
16#include <stdio.h>
17#include <string.h>
18
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* This stuff has to be in a header file because of possibly different MSVC CRTs which cause problems for FILE * crossing CRT boundaries. */
28
29static size_t openmpt_stream_file_read_func( void * stream, void * dst, size_t bytes ) {
30 FILE * f = 0;
31 size_t retval = 0;
32 f = (FILE*)stream;
33 if ( !f ) {
34 return 0;
35 }
36 retval = fread( dst, 1, bytes, f );
37 if ( retval <= 0 ) {
38 return 0;
39 }
40 return retval;
41}
42
43static int openmpt_stream_file_seek_func( void * stream, int64_t offset, int whence ) {
44 FILE * f = 0;
45 int fwhence = 0;
46 f = (FILE*)stream;
47 if ( !f ) {
48 return -1;
49 }
50 switch ( whence ) {
52 fwhence = SEEK_SET;
53 break;
55 fwhence = SEEK_CUR;
56 break;
58 fwhence = SEEK_END;
59 break;
60 default:
61 return -1;
62 break;
63 }
64 if ( (long)offset != offset ) {
65 return -1;
66 }
67 return fseek( f, (long)offset, fwhence ) ? -1 : 0;
68}
69
70static int64_t openmpt_stream_file_tell_func( void * stream ) {
71 FILE * f = 0;
72 long result = 0;
73 int64_t retval = 0;
74 f = (FILE*)stream;
75 if ( !f ) {
76 return -1;
77 }
78 result = ftell( f );
79 if ( (int64_t)result != result ) {
80 return -1;
81 }
82 retval = (int64_t)result;
83 if ( retval < 0 ) {
84 return -1;
85 }
86 return retval;
87}
88
111 memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
115 return retval;
116}
117
134 memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
138 return retval;
139}
140
141#ifdef __cplusplus
142}
143#endif
144
149#endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_H */
static openmpt_stream_callbacks openmpt_stream_get_file_callbacks2(void)
Provide openmpt_stream_callbacks for standard C FILE objects.
Definition: libopenmpt_stream_callbacks_file.h:132
#define OPENMPT_STREAM_SEEK_SET
Definition: libopenmpt.h:253
#define OPENMPT_STREAM_SEEK_CUR
Definition: libopenmpt.h:255
static int openmpt_stream_file_seek_func(void *stream, int64_t offset, int whence)
Definition: libopenmpt_stream_callbacks_file.h:43
static size_t openmpt_stream_file_read_func(void *stream, void *dst, size_t bytes)
Definition: libopenmpt_stream_callbacks_file.h:29
#define OPENMPT_STREAM_SEEK_END
Definition: libopenmpt.h:257
static openmpt_stream_callbacks openmpt_stream_get_file_callbacks(void)
Provide openmpt_stream_callbacks for standard C FILE objects.
Definition: libopenmpt_stream_callbacks_file.h:109
static int64_t openmpt_stream_file_tell_func(void *stream)
Definition: libopenmpt_stream_callbacks_file.h:70
#define LIBOPENMPT_DEPRECATED
Definition: libopenmpt_config.h:315
#define LIBOPENMPT_C_INLINE
Definition: libopenmpt_config.h:339
Stream callbacks.
Definition: libopenmpt.h:300
openmpt_stream_read_func read
Read callback.
Definition: libopenmpt.h:306
openmpt_stream_seek_func seek
Seek callback.
Definition: libopenmpt.h:313
openmpt_stream_tell_func tell
Tell callback.
Definition: libopenmpt.h:320