libopenmpt  0.2.7386-autotools
cross-platform C++ and C library to decode tracked music files
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <limits.h>
16 #include <stdint.h>
17 #include <stdio.h>
18 #include <string.h>
19 #ifdef _MSC_VER
20 #include <wchar.h> /* off_t */
21 #endif
22 
23 #ifdef __cplusplus
24 extern "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 
29 static 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 
43 static 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 ) {
51 #if defined(SEEK_SET)
53  fwhence = SEEK_SET;
54  break;
55 #endif
56 #if defined(SEEK_CUR)
58  fwhence = SEEK_CUR;
59  break;
60 #endif
61 #if defined(SEEK_END)
63  fwhence = SEEK_END;
64  break;
65 #endif
66  default:
67  return -1;
68  break;
69  }
70  #if defined(_MSC_VER)
71  return _fseeki64( f, offset, fwhence ) ? -1 : 0;
72  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
73  return fseeko( f, offset, fwhence ) ? -1 : 0;
74  #else
75  return fseek( f, offset, fwhence ) ? -1 : 0;
76  #endif
77 }
78 
79 static int64_t openmpt_stream_file_tell_func( void * stream ) {
80  FILE * f = 0;
81  int64_t retval = 0;
82  f = (FILE*)stream;
83  if ( !f ) {
84  return -1;
85  }
86  #if defined(_MSC_VER)
87  retval = _ftelli64( f );
88  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
89  retval = ftello( f );
90  #else
91  retval = ftell( f );
92  #endif
93  if ( retval < 0 ) {
94  return -1;
95  }
96  return retval;
97 }
98 
101  memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
105  return retval;
106 }
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_H */
113 
static int openmpt_stream_file_seek_func(void *stream, int64_t offset, int whence)
Definition: libopenmpt_stream_callbacks_file.h:43
#define OPENMPT_STREAM_SEEK_CUR
Definition: libopenmpt.h:206
static openmpt_stream_callbacks openmpt_stream_get_file_callbacks(void)
Definition: libopenmpt_stream_callbacks_file.h:99
#define OPENMPT_STREAM_SEEK_SET
Definition: libopenmpt.h:205
static size_t openmpt_stream_file_read_func(void *stream, void *dst, size_t bytes)
Definition: libopenmpt_stream_callbacks_file.h:29
openmpt_stream_tell_func tell
Tell callback.
Definition: libopenmpt.h:265
#define OPENMPT_STREAM_SEEK_END
Definition: libopenmpt.h:207
Stream callbacks.
Definition: libopenmpt.h:245
static int64_t openmpt_stream_file_tell_func(void *stream)
Definition: libopenmpt_stream_callbacks_file.h:79
openmpt_stream_read_func read
Read callback.
Definition: libopenmpt.h:251
openmpt_stream_seek_func seek
Seek callback.
Definition: libopenmpt.h:258