xref: /reactos/sdk/lib/3rdparty/libmpg123/lfs_alias.c (revision c2c66aff)
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. */
65 struct mpg123_handle_struct;
66 typedef struct mpg123_handle_struct mpg123_handle;
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);
104 int attribute_align_arg ALIAS_NAME(mpg123_open)(mpg123_handle *mh, const char *path)
105 {
106 	return NATIVE_NAME(mpg123_open)(mh, path);
107 }
108 
109 int NATIVE_NAME(mpg123_open_fd)(mpg123_handle *mh, int fd);
110 int attribute_align_arg ALIAS_NAME(mpg123_open_fd)(mpg123_handle *mh, int fd)
111 {
112 	return NATIVE_NAME(mpg123_open_fd)(mh, fd);
113 }
114 
115 int NATIVE_NAME(mpg123_open_handle)(mpg123_handle *mh, void *iohandle);
116 int attribute_align_arg ALIAS_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);
122 int attribute_align_arg ALIAS_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);
128 int attribute_align_arg ALIAS_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 
133 lfs_alias_t NATIVE_NAME(mpg123_framepos)(mpg123_handle *mh);
134 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_framepos)(mpg123_handle *mh)
135 {
136 	return NATIVE_NAME(mpg123_framepos)(mh);
137 }
138 
139 lfs_alias_t NATIVE_NAME(mpg123_tell)(mpg123_handle *mh);
140 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tell)(mpg123_handle *mh)
141 {
142 	return NATIVE_NAME(mpg123_tell)(mh);
143 }
144 
145 lfs_alias_t NATIVE_NAME(mpg123_tellframe)(mpg123_handle *mh);
146 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tellframe)(mpg123_handle *mh)
147 {
148 	return NATIVE_NAME(mpg123_tellframe)(mh);
149 }
150 
151 lfs_alias_t NATIVE_NAME(mpg123_tell_stream)(mpg123_handle *mh);
152 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tell_stream)(mpg123_handle *mh)
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);
158 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_seek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence)
159 {
160 	return NATIVE_NAME(mpg123_seek)(mh, sampleoff, whence);
161 }
162 
163 lfs_alias_t NATIVE_NAME(mpg123_feedseek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence, lfs_alias_t *input_offset);
164 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_feedseek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence, lfs_alias_t *input_offset)
165 {
166 	return NATIVE_NAME(mpg123_feedseek)(mh, sampleoff, whence, input_offset);
167 }
168 
169 lfs_alias_t NATIVE_NAME(mpg123_seek_frame)(mpg123_handle *mh, lfs_alias_t frameoff, int whence);
170 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_seek_frame)(mpg123_handle *mh, lfs_alias_t frameoff, int whence)
171 {
172 	return NATIVE_NAME(mpg123_seek_frame)(mh, frameoff, whence);
173 }
174 
175 lfs_alias_t NATIVE_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec);
176 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec)
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);
182 int attribute_align_arg ALIAS_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);
188 int attribute_align_arg ALIAS_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 
199 lfs_alias_t NATIVE_NAME(mpg123_framelength)(mpg123_handle *mh);
200 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_framelength)(mpg123_handle *mh)
201 {
202 	return NATIVE_NAME(mpg123_framelength)(mh);
203 }
204 
205 lfs_alias_t NATIVE_NAME(mpg123_length)(mpg123_handle *mh);
206 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_length)(mpg123_handle *mh)
207 {
208 	return NATIVE_NAME(mpg123_length)(mh);
209 }
210 
211 int NATIVE_NAME(mpg123_set_filesize)(mpg123_handle *mh, lfs_alias_t size);
212 int attribute_align_arg ALIAS_NAME(mpg123_set_filesize)(mpg123_handle *mh, lfs_alias_t size)
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));
218 int attribute_align_arg ALIAS_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 
229