Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3960 Serge 1
/*
2
	lfs_alias: Aliases to the small/native API functions with the size of long int as suffix.
3
 
4
	copyright 2010 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, which is the only choice on that platform anyway. It should be no-op, but prompts the platform-agnostic header of mpg123 to define API calls with the corresponding suffix.
9
	This file provides the names for this case. It's cruft, but glibc does it, too -- so people rely on it.
10
	Oh, and it also caters for the lunatics that define _FILE_OFFSET_BITS=32 on 32 bit platforms.
11
 
12
	There is also the strange case that the mpg123 build itself is configured for unnecessary _FILE_OFFSET_BITS == LFS_ALIAS_BITS =^ sizeof(long). In that case, the "native" function will have the suffix and the alias shall be provided without the suffix.
13
 
14
	So, two basic cases:
15
	1. mpg123_bla_32 alias for mpg123_bla
16
	2. mpg123_bla    alias for mpg123_bla_32
17
	Confusing, I know. It sucks.
18
*/
19
 
20
#include "config.h"
21
 
22
/* Hack for Solaris: Some system headers included from compat.h might force _FILE_OFFSET_BITS. Need to follow that here. */
23
#include "compat.h"
24
 
25
#ifndef LFS_ALIAS_BITS
26
#error "I need the count of alias bits here."
27
#endif
28
 
29
#define MACROCAT_REALLY(a, b) a ## b
30
#define MACROCAT(a, b) MACROCAT_REALLY(a, b)
31
 
32
/* This is wicked switchery: Decide which way the aliases are facing. */
33
 
34
#if _FILE_OFFSET_BITS+0 == LFS_ALIAS_BITS
35
 
36
/* The native functions are actually _with_ suffix, so let the mpg123 header use large file hackery to define the correct interfaces. */
37
#include "mpg123.h"
38
/* Don't forget to undef the function symbols before usage... */
39
 
40
/* The native functions have suffix, the aliases not. */
41
#define NATIVE_SUFFIX MACROCAT(_, _FILE_OFFSET_BITS)
42
#define NATIVE_NAME(func) MACROCAT(func, NATIVE_SUFFIX)
43
#define ALIAS_NAME(func) func
44
 
45
#else
46
 
47
/* Native functions are without suffix... */
48
#define MPG123_NO_LARGENAME
49
#include "mpg123.h"
50
 
51
/* The alias functions have suffix, the native ones not. */
52
#define ALIAS_SUFFIX MACROCAT(_, LFS_ALIAS_BITS)
53
#define ALIAS_NAME(func) MACROCAT(func, ALIAS_SUFFIX)
54
#define NATIVE_NAME(func) func
55
 
56
#endif
57
 
58
/* Now get the rest of the infrastructure on speed, namely attribute_align_arg, to stay safe. */
59
#include "mpg123lib_intern.h"
60
 
61
/*
62
	Extract the list of functions we need wrappers for, pregenerating the wrappers for simple cases (inline script for nedit):
63
perl -ne '
64
if(/^\s*EXPORT\s+(\S+)\s+(mpg123_\S+)\((.*)\);\s*$/)
65
{
66
	my $type = $1;
67
	my $name = $2;
68
	my $args = $3;
69
	next unless ($type =~ /off_t/ or $args =~ /off_t/ or ($name =~ /open/ and $name ne mpg123_open_feed));
70
	$type =~ s/off_t/long/g;
71
	my @nargs = ();
72
	$args =~ s/off_t/long/g;
73
	foreach my $a (split(/,/, $args))
74
	{
75
		$a =~ s/^.*\s\**([a-z_]+)$/$1/;
76
		push(@nargs, $a);
77
	}
78
	my $nargs = join(", ", @nargs);
79
	$nargs = "Human: figure me out." if($nargs =~ /\(/);
80
	print <
81
 
82
##ifdef $name
83
##undef $name
84
##endif
85
$type attribute_align_arg ALIAS_NAME($name)($args)
86
{
87
	return NATIVE_NAME($name)($nargs);
88
}
89
EOT
90
 
91
}' < mpg123.h.in
92
*/
93
 
94
#ifdef mpg123_open
95
#undef mpg123_open
96
#endif
97
int attribute_align_arg ALIAS_NAME(mpg123_open)(mpg123_handle *mh, const char *path)
98
{
99
	return NATIVE_NAME(mpg123_open)(mh, path);
100
}
101
 
102
#ifdef mpg123_open_fd
103
#undef mpg123_open_fd
104
#endif
105
int attribute_align_arg ALIAS_NAME(mpg123_open_fd)(mpg123_handle *mh, int fd)
106
{
107
	return NATIVE_NAME(mpg123_open_fd)(mh, fd);
108
}
109
 
110
#ifdef mpg123_open_handle
111
#undef mpg123_open_handle
112
#endif
113
int attribute_align_arg ALIAS_NAME(mpg123_open_handle)(mpg123_handle *mh, void *iohandle)
114
{
115
	return NATIVE_NAME(mpg123_open_handle)(mh, iohandle);
116
}
117
 
118
#ifdef mpg123_decode_frame
119
#undef mpg123_decode_frame
120
#endif
121
int attribute_align_arg ALIAS_NAME(mpg123_decode_frame)(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
122
{
123
	return NATIVE_NAME(mpg123_decode_frame)(mh, num, audio, bytes);
124
}
125
 
126
#ifdef mpg123_framebyframe_decode
127
#undef mpg123_framebyframe_decode
128
#endif
129
int attribute_align_arg ALIAS_NAME(mpg123_framebyframe_decode)(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
130
{
131
	return NATIVE_NAME(mpg123_framebyframe_decode)(mh, num, audio, bytes);
132
}
133
 
134
#ifdef mpg123_framepos
135
#undef mpg123_framepos
136
#endif
137
long attribute_align_arg ALIAS_NAME(mpg123_framepos)(mpg123_handle *mh)
138
{
139
	return NATIVE_NAME(mpg123_framepos)(mh);
140
}
141
 
142
#ifdef mpg123_tell
143
#undef mpg123_tell
144
#endif
145
long attribute_align_arg ALIAS_NAME(mpg123_tell)(mpg123_handle *mh)
146
{
147
	return NATIVE_NAME(mpg123_tell)(mh);
148
}
149
 
150
#ifdef mpg123_tellframe
151
#undef mpg123_tellframe
152
#endif
153
long attribute_align_arg ALIAS_NAME(mpg123_tellframe)(mpg123_handle *mh)
154
{
155
	return NATIVE_NAME(mpg123_tellframe)(mh);
156
}
157
 
158
#ifdef mpg123_tell_stream
159
#undef mpg123_tell_stream
160
#endif
161
long attribute_align_arg ALIAS_NAME(mpg123_tell_stream)(mpg123_handle *mh)
162
{
163
	return NATIVE_NAME(mpg123_tell_stream)(mh);
164
}
165
 
166
#ifdef mpg123_seek
167
#undef mpg123_seek
168
#endif
169
long attribute_align_arg ALIAS_NAME(mpg123_seek)(mpg123_handle *mh, long sampleoff, int whence)
170
{
171
	return NATIVE_NAME(mpg123_seek)(mh, sampleoff, whence);
172
}
173
 
174
#ifdef mpg123_feedseek
175
#undef mpg123_feedseek
176
#endif
177
long attribute_align_arg ALIAS_NAME(mpg123_feedseek)(mpg123_handle *mh, long sampleoff, int whence, long *input_offset)
178
{
179
	return NATIVE_NAME(mpg123_feedseek)(mh, sampleoff, whence, input_offset);
180
}
181
 
182
#ifdef mpg123_seek_frame
183
#undef mpg123_seek_frame
184
#endif
185
long attribute_align_arg ALIAS_NAME(mpg123_seek_frame)(mpg123_handle *mh, long frameoff, int whence)
186
{
187
	return NATIVE_NAME(mpg123_seek_frame)(mh, frameoff, whence);
188
}
189
 
190
#ifdef mpg123_timeframe
191
#undef mpg123_timeframe
192
#endif
193
long attribute_align_arg ALIAS_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec)
194
{
195
	return NATIVE_NAME(mpg123_timeframe)(mh, sec);
196
}
197
 
198
#ifdef mpg123_index
199
#undef mpg123_index
200
#endif
201
int attribute_align_arg ALIAS_NAME(mpg123_index)(mpg123_handle *mh, long **offsets, long *step, size_t *fill)
202
{
203
	return NATIVE_NAME(mpg123_index)(mh, offsets, step, fill);
204
}
205
 
206
#ifdef mpg123_set_index
207
#undef mpg123_set_index
208
#endif
209
int attribute_align_arg ALIAS_NAME(mpg123_set_index)(mpg123_handle *mh, long *offsets, long step, size_t fill)
210
{
211
	return NATIVE_NAME(mpg123_set_index)(mh, offsets, step, fill);
212
}
213
 
214
#ifdef mpg123_position
215
#undef mpg123_position
216
#endif
217
int attribute_align_arg ALIAS_NAME(mpg123_position)( mpg123_handle *mh, long frame_offset, long buffered_bytes, long *current_frame, long *frames_left, double *current_seconds, double *seconds_left)
218
{
219
	return NATIVE_NAME(mpg123_position)(mh, frame_offset, buffered_bytes, current_frame, frames_left, current_seconds, seconds_left);
220
}
221
 
222
#ifdef mpg123_length
223
#undef mpg123_length
224
#endif
225
long attribute_align_arg ALIAS_NAME(mpg123_length)(mpg123_handle *mh)
226
{
227
	return NATIVE_NAME(mpg123_length)(mh);
228
}
229
 
230
#ifdef mpg123_set_filesize
231
#undef mpg123_set_filesize
232
#endif
233
int attribute_align_arg ALIAS_NAME(mpg123_set_filesize)(mpg123_handle *mh, long size)
234
{
235
	return NATIVE_NAME(mpg123_set_filesize)(mh, size);
236
}
237
 
238
#ifdef mpg123_replace_reader
239
#undef mpg123_replace_reader
240
#endif
241
int attribute_align_arg ALIAS_NAME(mpg123_replace_reader)(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), long (*r_lseek)(int, long, int))
242
{
243
	return NATIVE_NAME(mpg123_replace_reader)(mh, r_read, r_lseek);
244
}
245
 
246
#ifdef mpg123_replace_reader_handle
247
#undef mpg123_replace_reader_handle
248
#endif
249
int attribute_align_arg ALIAS_NAME(mpg123_replace_reader_handle)(mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), long (*r_lseek)(void *, long, int), void (*cleanup)(void*))
250
{
251
	return NATIVE_NAME(mpg123_replace_reader_handle)(mh, r_read, r_lseek, cleanup);
252
}