libopenmpt 0.8.0-pre.5+r20620
cross-platform C++ and C library to decode tracked music files
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#ifndef _MSC_VER
16#include <errno.h>
17#endif
18#ifdef _MSC_VER
19#include <io.h>
20#endif
21#include <limits.h>
22#include <stdint.h>
23#include <stdio.h>
24#include <string.h>
25#ifndef _MSC_VER
26#include <unistd.h>
27#endif
28
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* This stuff has to be in a header file because of possibly different MSVC CRTs which cause problems for fd crossing CRT boundaries. */
38
39static size_t openmpt_stream_fd_read_func( void * stream, void * dst, size_t bytes ) {
40 int fd = 0;
41 #if defined(_MSC_VER)
42 size_t retval = 0;
43 int to_read = 0;
44 int ret_read = 0;
45 #else
46 ssize_t retval = 0;
47 #endif
48 fd = (int)(uintptr_t)stream;
49 if ( fd < 0 ) {
50 return 0;
51 }
52 #if defined(_MSC_VER)
53 retval = 0;
54 while ( bytes > 0 ) {
55 to_read = 0;
56 if ( bytes < (size_t)INT_MAX ) {
57 to_read = (int)bytes;
58 } else {
59 to_read = INT_MAX;
60 }
61 ret_read = _read( fd, dst, to_read );
62 if ( ret_read <= 0 ) {
63 return retval;
64 }
65 bytes -= ret_read;
66 retval += ret_read;
67 }
68 #else
69 do {
70 retval = read( fd, dst, bytes );
71 } while ( ( retval == -1 ) && ( errno == EINTR ) );
72 #endif
73 if ( retval <= 0 ) {
74 return 0;
75 }
76 return retval;
77}
78
92 memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
94 return retval;
95}
96
97#ifdef __cplusplus
98}
99#endif
100
105#endif /* LIBOPENMPT_STREAM_CALLBACKS_FD_H */
static size_t openmpt_stream_fd_read_func(void *stream, void *dst, size_t bytes)
Definition: libopenmpt_stream_callbacks_fd.h:39
static openmpt_stream_callbacks openmpt_stream_get_fd_callbacks(void)
Provide openmpt_stream_callbacks for standard POSIX file descriptors.
Definition: libopenmpt_stream_callbacks_fd.h:90
Stream callbacks.
Definition: libopenmpt.h:300
openmpt_stream_read_func read
Read callback.
Definition: libopenmpt.h:306