libopenmpt  0.2.5787-autotools
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 #ifdef _MSC_VER
16 #include <io.h>
17 #endif
18 #include <limits.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <string.h>
22 #ifndef _MSC_VER
23 #include <unistd.h>
24 #endif
25 #ifdef _MSC_VER
26 #include <wchar.h> /* off_t */
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /* This stuff has to be in a header file because of possibly different MSVC CRTs which cause problems for FILE * crossing CRT boundaries. */
34 
35 static size_t openmpt_stream_file_read_func( void * stream, void * dst, size_t bytes ) {
36  FILE * f = 0;
37  size_t retval = 0;
38  f = (FILE*)stream;
39  if ( !f ) {
40  return 0;
41  }
42  retval = fread( dst, 1, bytes, f );
43  if ( retval <= 0 ) {
44  return 0;
45  }
46  return retval;
47 }
48 
49 static int openmpt_stream_file_seek_func( void * stream, int64_t offset, int whence ) {
50  FILE * f = 0;
51  int fwhence = 0;
52  f = (FILE*)stream;
53  if ( !f ) {
54  return -1;
55  }
56  switch ( whence ) {
57 #if defined(SEEK_SET)
59  fwhence = SEEK_SET;
60  break;
61 #endif
62 #if defined(SEEK_CUR)
64  fwhence = SEEK_CUR;
65  break;
66 #endif
67 #if defined(SEEK_END)
69  fwhence = SEEK_END;
70  break;
71 #endif
72  default:
73  return -1;
74  break;
75  }
76  #if defined(_MSC_VER)
77  return _fseeki64( f, offset, fwhence ) ? -1 : 0;
78  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
79  return fseeko( f, offset, fwhence ) ? -1 : 0;
80  #else
81  return fseek( f, offset, fwhence ) ? -1 : 0;
82  #endif
83 }
84 
85 static int64_t openmpt_stream_file_tell_func( void * stream ) {
86  FILE * f = 0;
87  int64_t retval = 0;
88  f = (FILE*)stream;
89  if ( !f ) {
90  return -1;
91  }
92  #if defined(_MSC_VER)
93  retval = _ftelli64( f );
94  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
95  retval = ftello( f );
96  #else
97  retval = ftell( f );
98  #endif
99  if ( retval < 0 ) {
100  return -1;
101  }
102  return retval;
103 }
104 
107  memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
111  return retval;
112 }
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_H */
119 
static int openmpt_stream_file_seek_func(void *stream, int64_t offset, int whence)
Definition: libopenmpt_stream_callbacks_file.h:49
#define OPENMPT_STREAM_SEEK_CUR
Definition: libopenmpt.h:138
static openmpt_stream_callbacks openmpt_stream_get_file_callbacks(void)
Definition: libopenmpt_stream_callbacks_file.h:105
#define OPENMPT_STREAM_SEEK_SET
Definition: libopenmpt.h:137
static size_t openmpt_stream_file_read_func(void *stream, void *dst, size_t bytes)
Definition: libopenmpt_stream_callbacks_file.h:35
openmpt_stream_tell_func tell
Tell callback.
Definition: libopenmpt.h:197
#define OPENMPT_STREAM_SEEK_END
Definition: libopenmpt.h:139
Stream callbacks.
Definition: libopenmpt.h:177
static int64_t openmpt_stream_file_tell_func(void *stream)
Definition: libopenmpt_stream_callbacks_file.h:85
openmpt_stream_read_func read
Read callback.
Definition: libopenmpt.h:183
openmpt_stream_seek_func seek
Seek callback.
Definition: libopenmpt.h:190