libopenmpt  0.2.3532
cross-platform C and C++ library to decode tracked music files
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups 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 #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  f = (FILE*)stream;
52  if ( !f ) {
53  return -1;
54  }
55  #if defined(_MSC_VER)
56  return _fseeki64( f, offset, whence ) ? -1 : 0;
57  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
58  return fseeko( f, offset, whence ) ? -1 : 0;
59  #else
60  return fseek( f, offset, whence ) ? -1 : 0;
61  #endif
62 }
63 
64 static int64_t openmpt_stream_file_tell_func( void * stream ) {
65  FILE * f = 0;
66  int64_t retval = 0;
67  f = (FILE*)stream;
68  if ( !f ) {
69  return -1;
70  }
71  #if defined(_MSC_VER)
72  retval = _ftelli64( f );
73  #elif defined(_POSIX_SOURCE) && (_POSIX_SOURCE == 1)
74  retval = ftello( f );
75  #else
76  retval = ftell( f );
77  #endif
78  if ( retval < 0 ) {
79  return -1;
80  }
81  return retval;
82 }
83 
86  memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
90  return retval;
91 }
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_H */
98