libopenmpt  0.2.7386-autotools
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 #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 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* This stuff has to be in a header file because of possibly different MSVC CRTs which cause problems for fd crossing CRT boundaries. */
31 
32 static size_t openmpt_stream_fd_read_func( void * stream, void * dst, size_t bytes ) {
33  int fd = 0;
34  #if defined(_MSC_VER)
35  size_t retval = 0;
36  int to_read = 0;
37  int ret_read = 0;
38  #else
39  ssize_t retval = 0;
40  #endif
41  fd = (int)(uintptr_t)stream;
42  if ( fd < 0 ) {
43  return 0;
44  }
45  #if defined(_MSC_VER)
46  retval = 0;
47  while ( bytes > 0 ) {
48  to_read = 0;
49  if ( bytes < (size_t)INT_MAX ) {
50  to_read = (int)bytes;
51  } else {
52  to_read = INT_MAX;
53  }
54  ret_read = _read( fd, dst, to_read );
55  if ( ret_read <= 0 ) {
56  return retval;
57  }
58  bytes -= ret_read;
59  retval += ret_read;
60  }
61  #else
62  retval = read( fd, dst, bytes );
63  #endif
64  if ( retval <= 0 ) {
65  return 0;
66  }
67  return retval;
68 }
69 
72  memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
74  return retval;
75 }
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif /* LIBOPENMPT_STREAM_CALLBACKS_FD_H */
82 
static size_t openmpt_stream_fd_read_func(void *stream, void *dst, size_t bytes)
Definition: libopenmpt_stream_callbacks_fd.h:32
static openmpt_stream_callbacks openmpt_stream_get_fd_callbacks(void)
Definition: libopenmpt_stream_callbacks_fd.h:70
Stream callbacks.
Definition: libopenmpt.h:245
openmpt_stream_read_func read
Read callback.
Definition: libopenmpt.h:251