libopenmpt
0.2.4115
cross-platform C++ and C library to decode tracked music files
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
libopenmpt_stream_callbacks_fd.h
Go to the documentation of this file.
1
/*
2
* libopenmpt_stream_callbacks_fd.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_FD_H
11
#define LIBOPENMPT_STREAM_CALLBACKS_FD_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_fd_read_func
(
void
* stream,
void
* dst,
size_t
bytes ) {
36
int
fd = 0;
37
#if defined(_MSC_VER)
38
size_t
retval = 0;
39
int
to_read = 0;
40
int
ret_read = 0;
41
#else
42
ssize_t retval = 0;
43
#endif
44
fd = (int)(uintptr_t)stream;
45
if
( fd < 0 ) {
46
return
0;
47
}
48
#if defined(_MSC_VER)
49
retval = 0;
50
while
( bytes > 0 ) {
51
to_read = 0;
52
if
( bytes < (
size_t
)INT_MAX ) {
53
to_read = (int)bytes;
54
}
else
{
55
to_read = INT_MAX;
56
}
57
ret_read = _read( fd, dst, to_read );
58
if
( ret_read <= 0 ) {
59
return
retval;
60
}
61
bytes -= ret_read;
62
retval += ret_read;
63
}
64
#else
65
retval = read( fd, dst, bytes );
66
#endif
67
if
( retval <= 0 ) {
68
return
0;
69
}
70
return
retval;
71
}
72
73
static
openmpt_stream_callbacks
openmpt_stream_get_fd_callbacks
(
void
) {
74
openmpt_stream_callbacks
retval;
75
memset( &retval, 0,
sizeof
(
openmpt_stream_callbacks
) );
76
retval.
read
=
openmpt_stream_fd_read_func
;
77
return
retval;
78
}
79
80
#ifdef __cplusplus
81
}
82
#endif
83
84
#endif
/* LIBOPENMPT_STREAM_CALLBACKS_FD_H */
85
libopenmpt
libopenmpt_stream_callbacks_fd.h
Generated on Sun Jun 15 2014 18:44:30 for libopenmpt by
1.8.1.2