xref: /reactos/sdk/lib/3rdparty/libmpg123/lfs_alias.c (revision 7b1049c8)
1 /*
2 	lfs_alias: Aliases to the small/native API functions with the size of long int as suffix.
3 
4 	copyright 2010-2020 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_fixed)( mpg123_handle *mh, const char *path
104 ,	int channels, int encoding );
105 int attribute_align_arg ALIAS_NAME(mpg123_open_fixed)( mpg123_handle *mh, const char *path
106 ,	int channels, int encoding )
107 {
108 	return NATIVE_NAME(mpg123_open_fixed)(mh, path, channels, encoding);
109 }
110 
111 int NATIVE_NAME(mpg123_open)(mpg123_handle *mh, const char *path);
112 int attribute_align_arg ALIAS_NAME(mpg123_open)(mpg123_handle *mh, const char *path)
113 {
114 	return NATIVE_NAME(mpg123_open)(mh, path);
115 }
116 
117 int NATIVE_NAME(mpg123_open_fd)(mpg123_handle *mh, int fd);
118 int attribute_align_arg ALIAS_NAME(mpg123_open_fd)(mpg123_handle *mh, int fd)
119 {
120 	return NATIVE_NAME(mpg123_open_fd)(mh, fd);
121 }
122 
123 int NATIVE_NAME(mpg123_open_handle)(mpg123_handle *mh, void *iohandle);
124 int attribute_align_arg ALIAS_NAME(mpg123_open_handle)(mpg123_handle *mh, void *iohandle)
125 {
126 	return NATIVE_NAME(mpg123_open_handle)(mh, iohandle);
127 }
128 
129 int NATIVE_NAME(mpg123_decode_frame)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes);
130 int attribute_align_arg ALIAS_NAME(mpg123_decode_frame)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes)
131 {
132 	return NATIVE_NAME(mpg123_decode_frame)(mh, num, audio, bytes);
133 }
134 
135 int NATIVE_NAME(mpg123_framebyframe_decode)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes);
136 int attribute_align_arg ALIAS_NAME(mpg123_framebyframe_decode)(mpg123_handle *mh, lfs_alias_t *num, unsigned char **audio, size_t *bytes)
137 {
138 	return NATIVE_NAME(mpg123_framebyframe_decode)(mh, num, audio, bytes);
139 }
140 
141 lfs_alias_t NATIVE_NAME(mpg123_framepos)(mpg123_handle *mh);
142 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_framepos)(mpg123_handle *mh)
143 {
144 	return NATIVE_NAME(mpg123_framepos)(mh);
145 }
146 
147 lfs_alias_t NATIVE_NAME(mpg123_tell)(mpg123_handle *mh);
148 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tell)(mpg123_handle *mh)
149 {
150 	return NATIVE_NAME(mpg123_tell)(mh);
151 }
152 
153 lfs_alias_t NATIVE_NAME(mpg123_tellframe)(mpg123_handle *mh);
154 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tellframe)(mpg123_handle *mh)
155 {
156 	return NATIVE_NAME(mpg123_tellframe)(mh);
157 }
158 
159 lfs_alias_t NATIVE_NAME(mpg123_tell_stream)(mpg123_handle *mh);
160 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_tell_stream)(mpg123_handle *mh)
161 {
162 	return NATIVE_NAME(mpg123_tell_stream)(mh);
163 }
164 
165 lfs_alias_t NATIVE_NAME(mpg123_seek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence);
166 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_seek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence)
167 {
168 	return NATIVE_NAME(mpg123_seek)(mh, sampleoff, whence);
169 }
170 
171 lfs_alias_t NATIVE_NAME(mpg123_feedseek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence, lfs_alias_t *input_offset);
172 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_feedseek)(mpg123_handle *mh, lfs_alias_t sampleoff, int whence, lfs_alias_t *input_offset)
173 {
174 	return NATIVE_NAME(mpg123_feedseek)(mh, sampleoff, whence, input_offset);
175 }
176 
177 lfs_alias_t NATIVE_NAME(mpg123_seek_frame)(mpg123_handle *mh, lfs_alias_t frameoff, int whence);
178 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_seek_frame)(mpg123_handle *mh, lfs_alias_t frameoff, int whence)
179 {
180 	return NATIVE_NAME(mpg123_seek_frame)(mh, frameoff, whence);
181 }
182 
183 lfs_alias_t NATIVE_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec);
184 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec)
185 {
186 	return NATIVE_NAME(mpg123_timeframe)(mh, sec);
187 }
188 
189 int NATIVE_NAME(mpg123_index)(mpg123_handle *mh, lfs_alias_t **offsets, lfs_alias_t *step, size_t *fill);
190 int attribute_align_arg ALIAS_NAME(mpg123_index)(mpg123_handle *mh, lfs_alias_t **offsets, lfs_alias_t *step, size_t *fill)
191 {
192 	return NATIVE_NAME(mpg123_index)(mh, offsets, step, fill);
193 }
194 
195 int NATIVE_NAME(mpg123_set_index)(mpg123_handle *mh, lfs_alias_t *offsets, lfs_alias_t step, size_t fill);
196 int attribute_align_arg ALIAS_NAME(mpg123_set_index)(mpg123_handle *mh, lfs_alias_t *offsets, lfs_alias_t step, size_t fill)
197 {
198 	return NATIVE_NAME(mpg123_set_index)(mh, offsets, step, fill);
199 }
200 
201 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);
202 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)
203 {
204 	return NATIVE_NAME(mpg123_position)(mh, frame_offset, buffered_bytes, current_frame, frames_left, current_seconds, seconds_left);
205 }
206 
207 lfs_alias_t NATIVE_NAME(mpg123_framelength)(mpg123_handle *mh);
208 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_framelength)(mpg123_handle *mh)
209 {
210 	return NATIVE_NAME(mpg123_framelength)(mh);
211 }
212 
213 lfs_alias_t NATIVE_NAME(mpg123_length)(mpg123_handle *mh);
214 lfs_alias_t attribute_align_arg ALIAS_NAME(mpg123_length)(mpg123_handle *mh)
215 {
216 	return NATIVE_NAME(mpg123_length)(mh);
217 }
218 
219 int NATIVE_NAME(mpg123_set_filesize)(mpg123_handle *mh, lfs_alias_t size);
220 int attribute_align_arg ALIAS_NAME(mpg123_set_filesize)(mpg123_handle *mh, lfs_alias_t size)
221 {
222 	return NATIVE_NAME(mpg123_set_filesize)(mh, size);
223 }
224 
225 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));
226 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))
227 {
228 	return NATIVE_NAME(mpg123_replace_reader)(mh, r_read, r_lseek);
229 }
230 
231 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*));
232 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*))
233 {
234 	return NATIVE_NAME(mpg123_replace_reader_handle)(mh, r_read, r_lseek, cleanup);
235 }
236 
237