libopenmpt: libopenmpt/libopenmpt_stream_callbacks_file_mingw.h Source File

libopenmpt 0.9.0-pre.12+r25301 cross-platform C++ and C library to decode tracked music files

Loading...
Searching...
No Matches
libopenmpt_stream_callbacks_file_mingw.h
Go to the documentation of this file.
1/*
2 * libopenmpt_stream_callbacks_file_mingw.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_MINGW_H
11#define LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW_H
12
13#include "libopenmpt.h"
14
15#include <stdint.h>
16#include <stdio.h>
17#include <string.h>
18
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27 static size_t openmpt_stream_file_mingw_read_func( void * stream, void * dst, size_t bytes ) {
28 FILE * f = 0;
29 size_t retval = 0;
30 f = (FILE*)stream;
31 if ( !f ) {
32 return 0;
33 }
34 retval = fread( dst, 1, bytes, f );
35 if ( retval <= 0 ) {
36 return 0;
37 }
38 return retval;
39}
40
41 static int openmpt_stream_file_mingw_seek_func( void * stream, int64_t offset, int whence ) {
42 FILE * f = 0;
43 int fwhence = 0;
44 f = (FILE*)stream;
45 if ( !f ) {
46 return -1;
47 }
48 switch ( whence ) {
49 case OPENMPT_STREAM_SEEK_SET:
50 fwhence = SEEK_SET;
51 break;
52 case OPENMPT_STREAM_SEEK_CUR:
53 fwhence = SEEK_CUR;
54 break;
55 case OPENMPT_STREAM_SEEK_END:
56 fwhence = SEEK_END;
57 break;
58 default:
59 return -1;
60 break;
61 }
62 if ( (_off64_t)offset != offset ) {
63 return -1;
64 }
65 return fseeko64( f, (_off64_t)offset, fwhence ) ? -1 : 0;
66}
67
68 static int64_t openmpt_stream_file_mingw_tell_func( void * stream ) {
69 FILE * f = 0;
70 _off64_t result = 0;
71 int64_t retval = 0;
72 f = (FILE*)stream;
73 if ( !f ) {
74 return -1;
75 }
76 result = ftello64( f );
77 if ( (int64_t)result != result ) {
78 return -1;
79 }
80 retval = (int64_t)result;
81 if ( retval < 0 ) {
82 return -1;
83 }
84 return retval;
85}
86
98 static openmpt_stream_callbacks openmpt_stream_get_file_mingw_callbacks(void) {
99 openmpt_stream_callbacks retval;
100 memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
101 retval.read = openmpt_stream_file_mingw_read_func;
102 retval.seek = openmpt_stream_file_mingw_seek_func;
103 retval.tell = openmpt_stream_file_mingw_tell_func;
104 return retval;
105}
106
107#ifdef __cplusplus
108}
109#endif
110
114
115#endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW_H */
OPENMPT_STREAM_SEEK_SET
#define OPENMPT_STREAM_SEEK_SET
Definition libopenmpt.h:253
openmpt_stream_file_mingw_seek_func
static int openmpt_stream_file_mingw_seek_func(void *stream, int64_t offset, int whence)
Definition libopenmpt_stream_callbacks_file_mingw.h:41
OPENMPT_STREAM_SEEK_CUR
#define OPENMPT_STREAM_SEEK_CUR
Definition libopenmpt.h:255
openmpt_stream_get_file_mingw_callbacks
static openmpt_stream_callbacks openmpt_stream_get_file_mingw_callbacks(void)
Provide openmpt_stream_callbacks for standard C FILE objects.
Definition libopenmpt_stream_callbacks_file_mingw.h:98
openmpt_stream_file_mingw_tell_func
static int64_t openmpt_stream_file_mingw_tell_func(void *stream)
Definition libopenmpt_stream_callbacks_file_mingw.h:68
OPENMPT_STREAM_SEEK_END
#define OPENMPT_STREAM_SEEK_END
Definition libopenmpt.h:257
openmpt_stream_file_mingw_read_func
static size_t openmpt_stream_file_mingw_read_func(void *stream, void *dst, size_t bytes)
Definition libopenmpt_stream_callbacks_file_mingw.h:27
libopenmpt.h
openmpt_stream_callbacks
Stream callbacks.
Definition libopenmpt.h:300
openmpt_stream_callbacks::read
openmpt_stream_read_func read
Read callback.
Definition libopenmpt.h:306
openmpt_stream_callbacks::seek
openmpt_stream_seek_func seek
Seek callback.
Definition libopenmpt.h:313
openmpt_stream_callbacks::tell
openmpt_stream_tell_func tell
Tell callback.
Definition libopenmpt.h:320