ReactOS  0.4.14-dev-599-g2d4d3f5
lfs_alias.c
Go to the documentation of this file.
1 /*
2  lfs_alias: Aliases to the small/native API functions with the size of long int as suffix.
3 
4  copyright 2010-2013 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis
7 
8  Use case: Client code on Linux/x86-64 that defines _FILE_OFFSET_BITS to 64,
9  which is the only choice on that platform anyway. It should be no-op, but
10  prompts the platform-agnostic header of mpg123 to define API calls with the
11  corresponding suffix. This file provides the names for this case. It's cruft,
12  but glibc does it, too -- so people rely on it.
13  Oh, and it also caters for the lunatics that define _FILE_OFFSET_BITS=32 on
14  32 bit platforms. In addition, it's needed for platforms that always have
15  off_t /= long, and clients still insisting on defining _FILE_OFFSET_BITS.
16 
17  Depending on use case, the aliases map to 32 (small) or 64 bit (large) offset
18  functions, to the ones from libmpg123 or the ones from lfs_wrap.
19 
20  So, two basic cases:
21  1. mpg123_bla_32 alias for mpg123_bla (native)
22  2. mpg123_bla alias for mpg123_bla_32 (wrapper)
23  Same for 64 bits. Confusing, I know. It sucks.
24 
25  Note that the mpg123 header is _not_ used here to avoid definition with whacky off_t.
26  The aliases are always about arguments of native alias_t type. This can be off_t, but
27  on Linux/x86, this is long int. The off_t declarations in mpg123.h confuse things,
28  so reproduce definitions for the wrapper functions in that case. The definitions are
29  pulled by an inline Perl script in any case ... no need to copy anything manually!
30  As a benefit, one can skip undefining possible largefile namings.
31 */
32 
33 #include "config.h"
34 
35 /* Hack for Solaris: Some system headers included from compat.h might force _FILE_OFFSET_BITS. Need to follow that here.
36  Also, want it around to have types defined. */
37 #include "compat.h"
38 
39 #ifndef LFS_ALIAS_BITS
40 #error "I need the count of alias bits here."
41 #endif
42 
43 #define MACROCAT_REALLY(a, b) a ## b
44 #define MACROCAT(a, b) MACROCAT_REALLY(a, b)
45 
46 /* This is wicked switchery: Decide which way the aliases are facing. */
47 
48 #if _FILE_OFFSET_BITS+0 == LFS_ALIAS_BITS
49 
50 /* The native functions have suffix, the aliases not. */
51 #define NATIVE_SUFFIX MACROCAT(_, _FILE_OFFSET_BITS)
52 #define NATIVE_NAME(func) MACROCAT(func, NATIVE_SUFFIX)
53 #define ALIAS_NAME(func) func
54 
55 #else
56 
57 /* The alias functions have suffix, the native ones not. */
58 #define ALIAS_SUFFIX MACROCAT(_, LFS_ALIAS_BITS)
59 #define ALIAS_NAME(func) MACROCAT(func, ALIAS_SUFFIX)
60 #define NATIVE_NAME(func) func
61 
62 #endif
63 
64 /* Copy of necessary definitions, actually just forward declarations. */
67 
68 
69 /* Get attribute_align_arg, to stay safe. */
70 #include "abi_align.h"
71 
72 /*
73  Extract the list of functions we need wrappers for, pregenerating the wrappers for simple cases (inline script for nedit):
74 perl -ne '
75 if(/^\s*MPG123_EXPORT\s+(\S+)\s+(mpg123_\S+)\((.*)\);\s*$/)
76 {
77  my $type = $1;
78  my $name = $2;
79  my $args = $3;
80  next unless ($type =~ /off_t/ or $args =~ /off_t/ or ($name =~ /open/ and $name ne mpg123_open_feed));
81  $type =~ s/off_t/lfs_alias_t/g;
82  my @nargs = ();
83  $args =~ s/off_t/lfs_alias_t/g;
84  foreach my $a (split(/,/, $args))
85  {
86  $a =~ s/^.*\s\**([a-z_]+)$/$1/;
87  push(@nargs, $a);
88  }
89  my $nargs = join(", ", @nargs);
90  $nargs = "Human: figure me out." if($nargs =~ /\(/);
91  print <<EOT
92 
93 $type NATIVE_NAME($name)($args);
94 $type attribute_align_arg ALIAS_NAME($name)($args)
95 {
96  return NATIVE_NAME($name)($nargs);
97 }
98 EOT
99 
100 }' < mpg123.h.in
101 */
102 
103 int NATIVE_NAME(mpg123_open)(mpg123_handle *mh, const char *path);
105 {
106  return NATIVE_NAME(mpg123_open)(mh, path);
107 }
108 
111 {
112  return NATIVE_NAME(mpg123_open_fd)(mh, fd);
113 }
114 
115 int NATIVE_NAME(mpg123_open_handle)(mpg123_handle *mh, void *iohandle);
117 {
118  return NATIVE_NAME(mpg123_open_handle)(mh, iohandle);
119 }
120 
121 int NATIVE_NAME(mpg123_decode_frame)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes);
123 {
124  return NATIVE_NAME(mpg123_decode_frame)(mh, num, audio, bytes);
125 }
126 
127 int NATIVE_NAME(mpg123_framebyframe_decode)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes);
129 {
130  return NATIVE_NAME(mpg123_framebyframe_decode)(mh, num, audio, bytes);
131 }
132 
135 {
136  return NATIVE_NAME(mpg123_framepos)(mh);
137 }
138 
141 {
142  return NATIVE_NAME(mpg123_tell)(mh);
143 }
144 
147 {
148  return NATIVE_NAME(mpg123_tellframe)(mh);
149 }
150 
153 {
154  return NATIVE_NAME(mpg123_tell_stream)(mh);
155 }
156 
157 lfs_alias_t NATIVE_NAME(mpg123_seek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence);
159 {
160  return NATIVE_NAME(mpg123_seek)(mh, sampleoff, whence);
161 }
162 
165 {
166  return NATIVE_NAME(mpg123_feedseek)(mh, sampleoff, whence, input_offset);
167 }
168 
171 {
172  return NATIVE_NAME(mpg123_seek_frame)(mh, frameoff, whence);
173 }
174 
177 {
178  return NATIVE_NAME(mpg123_timeframe)(mh, sec);
179 }
180 
181 int NATIVE_NAME(mpg123_index)(mpg123_handle *mh, lfs_alias_t **offsets, lfs_alias_t *step, size_t *fill);
183 {
184  return NATIVE_NAME(mpg123_index)(mh, offsets, step, fill);
185 }
186 
187 int NATIVE_NAME(mpg123_set_index)(mpg123_handle *mh, lfs_alias_t *offsets, lfs_alias_t step, size_t fill);
189 {
190  return NATIVE_NAME(mpg123_set_index)(mh, offsets, step, fill);
191 }
192 
193 int NATIVE_NAME(mpg123_position)( mpg123_handle *mh, lfs_alias_t frame_offset, lfs_alias_t buffered_bytes, lfs_alias_t *current_frame, lfs_alias_t *frames_left, double *current_seconds, double *seconds_left);
194 int attribute_align_arg ALIAS_NAME(mpg123_position)( mpg123_handle *mh, lfs_alias_t frame_offset, lfs_alias_t buffered_bytes, lfs_alias_t *current_frame, lfs_alias_t *frames_left, double *current_seconds, double *seconds_left)
195 {
196  return NATIVE_NAME(mpg123_position)(mh, frame_offset, buffered_bytes, current_frame, frames_left, current_seconds, seconds_left);
197 }
198 
201 {
202  return NATIVE_NAME(mpg123_framelength)(mh);
203 }
204 
207 {
208  return NATIVE_NAME(mpg123_length)(mh);
209 }
210 
213 {
214  return NATIVE_NAME(mpg123_set_filesize)(mh, size);
215 }
216 
217 int NATIVE_NAME(mpg123_replace_reader)(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), lfs_alias_t (*r_lseek)(int, lfs_alias_t, int));
219 {
220  return NATIVE_NAME(mpg123_replace_reader)(mh, r_read, r_lseek);
221 }
222 
223 int NATIVE_NAME(mpg123_replace_reader_handle)(mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), lfs_alias_t (*r_lseek)(void *, lfs_alias_t, int), void (*cleanup)(void*));
224 int attribute_align_arg ALIAS_NAME(mpg123_replace_reader_handle)(mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), lfs_alias_t (*r_lseek)(void *, lfs_alias_t, int), void (*cleanup)(void*))
225 {
226  return NATIVE_NAME(mpg123_replace_reader_handle)(mh, r_read, r_lseek, cleanup);
227 }
228 
lfs_alias_t NATIVE_NAME() mpg123_timeframe(mpg123_handle *mh, double sec)
Definition: lfs_alias.c:176
lfs_alias_t NATIVE_NAME() mpg123_seek(mpg123_handle *mh, lfs_alias_t sampleoff, int whence)
Definition: lfs_alias.c:158
#define lfs_alias_t
Definition: config.h:460
#define frame_offset
Definition: intsym.h:190
int NATIVE_NAME() mpg123_set_filesize(mpg123_handle *mh, lfs_alias_t size)
Definition: lfs_alias.c:212
GLsizei const GLchar ** path
Definition: glext.h:7234
lfs_alias_t NATIVE_NAME() mpg123_tell_stream(mpg123_handle *mh)
Definition: lfs_alias.c:152
lfs_alias_t NATIVE_NAME() mpg123_tell(mpg123_handle *mh)
Definition: lfs_alias.c:140
int NATIVE_NAME() mpg123_replace_reader_handle(mpg123_handle *mh, ssize_t(*r_read)(void *, void *, size_t), lfs_alias_t(*r_lseek)(void *, lfs_alias_t, int), void(*cleanup)(void *))
Definition: lfs_alias.c:224
static int fd
Definition: io.c:51
#define ssize_t
Definition: config.h:469
int NATIVE_NAME() mpg123_decode_frame(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes)
Definition: lfs_alias.c:122
off_t input_offset
Definition: frame.h:216
int NATIVE_NAME() mpg123_index(mpg123_handle *mh, lfs_alias_t **offsets, lfs_alias_t *step, size_t *fill)
Definition: lfs_alias.c:182
lfs_alias_t NATIVE_NAME() mpg123_framepos(mpg123_handle *mh)
Definition: lfs_alias.c:134
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
lfs_alias_t NATIVE_NAME() mpg123_feedseek(mpg123_handle *mh, lfs_alias_t sampleoff, int whence, lfs_alias_t *input_offset)
Definition: lfs_alias.c:164
__kernel_size_t size_t
Definition: linux.h:237
lfs_alias_t NATIVE_NAME() mpg123_tellframe(mpg123_handle *mh)
Definition: lfs_alias.c:146
GLsizeiptr size
Definition: glext.h:5919
int NATIVE_NAME() mpg123_framebyframe_decode(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes)
Definition: lfs_alias.c:128
int NATIVE_NAME() mpg123_set_index(mpg123_handle *mh, lfs_alias_t *offsets, lfs_alias_t step, size_t fill)
Definition: lfs_alias.c:188
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
lfs_alias_t NATIVE_NAME() mpg123_framelength(mpg123_handle *mh)
Definition: lfs_alias.c:200
GLuint GLuint num
Definition: glext.h:9618
int NATIVE_NAME() mpg123_open(mpg123_handle *mh, const char *path)
Definition: lfs_alias.c:104
int NATIVE_NAME() mpg123_open_handle(mpg123_handle *mh, void *iohandle)
Definition: lfs_alias.c:116
int NATIVE_NAME() mpg123_position(mpg123_handle *mh, lfs_alias_t frame_offset, lfs_alias_t buffered_bytes, lfs_alias_t *current_frame, lfs_alias_t *frames_left, double *current_seconds, double *seconds_left)
Definition: lfs_alias.c:194
lfs_alias_t NATIVE_NAME() mpg123_length(mpg123_handle *mh)
Definition: lfs_alias.c:206
#define ALIAS_NAME(func)
Definition: lfs_alias.c:53
char * cleanup(char *str)
Definition: wpickclick.c:99
int NATIVE_NAME() mpg123_open_fd(mpg123_handle *mh, int fd)
Definition: lfs_alias.c:110
#define attribute_align_arg
Definition: abi_align.h:30
lfs_alias_t NATIVE_NAME() mpg123_seek_frame(mpg123_handle *mh, lfs_alias_t frameoff, int whence)
Definition: lfs_alias.c:170
int NATIVE_NAME() mpg123_replace_reader(mpg123_handle *mh, ssize_t(*r_read)(int, void *, size_t), lfs_alias_t(*r_lseek)(int, lfs_alias_t, int))
Definition: lfs_alias.c:218
#define NATIVE_NAME(func)
Definition: lfs_alias.c:52
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31