PageRenderTime 1150ms CodeModel.GetById 1122ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 0ms

/xbmc/cores/DllLoader/exports/wrapper.c

http://github.com/xbmc/xbmc
C | 494 lines | 397 code | 81 blank | 16 comment | 2 complexity | a000f23f341fd192d440c137616f7bf3 MD5 | raw file
  1/*
  2 *  Copyright (C) 2005-2018 Team Kodi
  3 *  This file is part of Kodi - https://kodi.tv
  4 *
  5 *  SPDX-License-Identifier: GPL-2.0-or-later
  6 *  See LICENSES/README.md for more information.
  7 */
  8
  9//
 10// To recreate wrapper.def:
 11//
 12// bash# (echo -n "-Wl"; grep __wrap wrapper.c | grep -v bash | sed "s/.*__wrap_//g" | sed "s/(.*//g" | awk '{printf(",-wrap,%s",$0);}') > wrapper.def
 13//
 14#include <sys/types.h>
 15#include <sys/stat.h>
 16#if !defined(TARGET_ANDROID)
 17#include <sys/statvfs.h>
 18#endif
 19#include <stdio.h>
 20#include <stdlib.h>
 21#include <unistd.h>
 22#include <stdarg.h>
 23#include <dirent.h>
 24#include <dlfcn.h>
 25
 26#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_ANDROID)
 27typedef off_t     __off_t;
 28typedef int64_t   off64_t;
 29typedef off64_t   __off64_t;
 30typedef fpos_t    fpos64_t;
 31#define stat64    stat
 32#endif
 33
 34#ifdef TARGET_POSIX
 35#define _stat stat
 36#endif
 37
 38struct mntent;
 39
 40void* dllmalloc(size_t );
 41void* dllcalloc( size_t , size_t );
 42void* dllrealloc(void*, size_t);
 43void dllfree(void*);
 44
 45int dll_open(const char* szFileName, int iMode);
 46int dll_write(int fd, const void* buffer, unsigned int uiSize);
 47int dll_read(int fd, void* buffer, unsigned int uiSize);
 48off_t dll_lseek(int fd, __off_t lPos, int iWhence);
 49__off64_t dll_lseeki64(int fd, __off64_t lPos, int iWhence);
 50int dll_close(int fd);
 51
 52FILE * dll_fopen (const char * filename, const char * mode);
 53FILE* dll_freopen(const char *path, const char *mode, FILE *stream);
 54FILE* dll_fdopen(int i, const char* file);
 55int dll_fclose (FILE * stream);
 56int dll_ferror (FILE * stream);
 57int dll_feof (FILE * stream);
 58int dll_fileno(FILE* stream);
 59void dll_clearerr(FILE* stream);
 60int dll_fread (void * buffer, size_t size, size_t count, FILE * stream);
 61size_t dll_fwrite ( const void * buffer, size_t size, size_t count, FILE * stream );
 62int dll_fflush (FILE * stream);
 63int dll_fputc (int character, FILE * stream);
 64int dll_fputs (const char * szLine , FILE* stream);
 65int dll_putc(int c, FILE *stream);
 66int dll_fseek ( FILE * stream , long offset , int origin );
 67int dll_fseek64(FILE *stream, off64_t offset, int origin);
 68long dll_ftell(FILE *stream);
 69off64_t dll_ftell64(FILE *stream);
 70void dll_rewind(FILE* stream);
 71int dll_fgetpos(FILE* stream, fpos_t* pos);
 72int dll_fgetpos64(FILE *stream, fpos64_t *pos);
 73int dll_fsetpos(FILE* stream, const fpos_t* pos);
 74int dll_fsetpos64(FILE* stream, const fpos64_t* pos);
 75DIR* dll_opendir(const char* name);
 76struct dirent* dll_readdir(DIR* dirp);
 77int dll_closedir(DIR* dirp);
 78void dll_rewinddir(DIR* dirp);
 79int dll_fprintf(FILE* stream , const char * format, ...);
 80int dllprintf(const char *format, ...);
 81int dll_vfprintf(FILE *stream, const char *format, va_list va);
 82int dll_fgetc (FILE* stream);
 83char * dll_fgets (char* pszString, int num , FILE * stream);
 84int dll_getc (FILE * stream);
 85int dll_ungetc (int c, FILE * stream);
 86int dll_ioctl(int d, unsigned long int request, va_list va);
 87int dll_stat(const char *path, struct _stat *buffer);
 88int dll_stat64(const char *path, struct stat64 *buffer);
 89void dll_flockfile(FILE *file);
 90int dll_ftrylockfile(FILE *file);
 91void dll_funlockfile(FILE *file);
 92int dll_fstat64(int fd, struct stat64 *buf);
 93int dll_fstat(int fd, struct _stat *buf);
 94FILE* dll_popen(const char *command, const char *mode);
 95void* dll_dlopen(const char *filename, int flag);
 96int dll_setvbuf(FILE *stream, char *buf, int type, size_t size);
 97struct mntent *dll_getmntent(FILE *fp);
 98
 99void *__wrap_dlopen(const char *filename, int flag)
100{
101  return dlopen(filename, flag);
102}
103
104FILE *__wrap_popen(const char *command, const char *mode)
105{
106  return dll_popen(command, mode);
107}
108
109void* __wrap_calloc( size_t num, size_t size )
110{
111  return dllcalloc(num, size);
112}
113
114void* __wrap_malloc(size_t size)
115{
116  return dllmalloc(size);
117}
118
119void* __wrap_realloc( void *memblock, size_t size )
120{
121  return dllrealloc(memblock, size);
122}
123
124void __wrap_free( void* pPtr )
125{
126  dllfree(pPtr);
127}
128
129int __wrap_open(const char *file, int oflag, ...)
130{
131  return dll_open(file, oflag);
132}
133
134int __wrap_open64(const char *file, int oflag, ...)
135{
136  return dll_open(file, oflag);
137}
138
139int __wrap_close(int fd)
140{
141   return dll_close(fd);
142}
143
144ssize_t __wrap_write(int fd, const void *buf, size_t count)
145{
146  return dll_write(fd, buf, count);
147}
148
149ssize_t __wrap_read(int fd, void *buf, size_t count)
150{
151  return dll_read(fd, buf, count);
152}
153
154__off_t __wrap_lseek(int filedes, __off_t offset, int whence)
155{
156  return dll_lseek(filedes, offset, whence);
157}
158
159__off64_t __wrap_lseek64(int filedes, __off64_t offset, int whence)
160{
161  __off64_t seekRes = dll_lseeki64(filedes, offset, whence);
162  return seekRes;
163}
164
165int __wrap_fclose(FILE *fp)
166{
167  return dll_fclose(fp);
168}
169
170int __wrap_ferror(FILE *stream)
171{
172  return dll_ferror(stream);
173}
174
175void __wrap_clearerr(FILE *stream)
176{
177  dll_clearerr(stream);
178}
179
180int __wrap_feof(FILE *stream)
181{
182  return dll_feof(stream);
183}
184
185int __wrap_fileno(FILE *stream)
186{
187  return dll_fileno(stream);
188}
189
190FILE *__wrap_fopen(const char *path, const char *mode)
191{
192  return dll_fopen(path, mode);
193}
194
195FILE *__wrap_fopen64(const char *path, const char *mode)
196{
197  return dll_fopen(path, mode);
198}
199
200FILE *__wrap_fdopen(int filedes, const char *mode)
201{
202  return dll_fdopen(filedes, mode);
203}
204
205FILE *__wrap_freopen(const char *path, const char *mode, FILE *stream)
206{
207  return dll_freopen(path, mode, stream);
208}
209
210size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
211{
212  return dll_fread(ptr, size, nmemb, stream);
213}
214
215size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
216{
217  return dll_fwrite(ptr, size, nmemb, stream);
218}
219
220int __wrap_fflush(FILE *stream)
221{
222  return dll_fflush(stream);
223}
224
225int __wrap_fputc(int c, FILE *stream)
226{
227  return dll_fputc(c, stream);
228}
229
230int __wrap_fputs(const char *s, FILE *stream)
231{
232  return dll_fputs(s, stream);
233}
234
235int __wrap__IO_putc(int c, FILE *stream)
236{
237  return dll_putc(c, stream);
238}
239
240int __wrap_fseek(FILE *stream, long offset, int whence)
241{
242  return dll_fseek(stream, offset, whence);
243}
244
245int __wrap_fseeko64(FILE *stream, off64_t offset, int whence)
246{
247  return dll_fseek64(stream, offset, whence);
248}
249
250long __wrap_ftell(FILE *stream)
251{
252  return dll_ftell(stream);
253}
254
255off64_t __wrap_ftello64(FILE *stream)
256{
257  return dll_ftell64(stream);
258}
259
260void __wrap_rewind(FILE *stream)
261{
262  dll_rewind(stream);
263}
264
265int __wrap_fgetpos(FILE *stream, fpos_t *pos)
266{
267  return dll_fgetpos(stream, pos);
268}
269
270int __wrap_fgetpos64(FILE *stream, fpos64_t *pos)
271{
272  return dll_fgetpos64(stream, pos);
273}
274
275int __wrap_fsetpos(FILE *stream, fpos_t *pos)
276{
277  return dll_fsetpos(stream, pos);
278}
279
280int __wrap_fsetpos64(FILE *stream, fpos64_t *pos)
281{
282  return dll_fsetpos64(stream, pos);
283}
284
285DIR * __wrap_opendir(const char *name)
286{
287  return dll_opendir(name);
288}
289
290struct dirent * __wrap_readdir(DIR* dirp)
291{
292  return dll_readdir(dirp);
293}
294
295struct dirent * __wrap_readdir64(DIR* dirp)
296{
297  return dll_readdir(dirp);
298}
299
300int __wrap_closedir(DIR* dirp)
301{
302  return dll_closedir(dirp);
303}
304
305void __wrap_rewinddir(DIR* dirp)
306{
307  dll_rewinddir(dirp);
308}
309
310int __wrap_fprintf(FILE *stream, const char *format, ...)
311{
312    int res;
313    va_list va;
314    va_start(va, format);
315    res = dll_vfprintf(stream, format, va);
316    va_end(va);
317    return res;
318}
319
320int __wrap_vfprintf(FILE *stream, const char *format, va_list ap)
321{
322  return dll_vfprintf(stream, format, ap);
323}
324
325int __wrap_printf(const char *format, ...)
326{
327    int res;
328    va_list va;
329    va_start(va, format);
330    res = dll_vfprintf(stdout, format, va);
331    va_end(va);
332    return res;
333}
334
335int __wrap_fgetc(FILE *stream)
336{
337  return dll_fgetc(stream);
338}
339
340char *__wrap_fgets(char *s, int size, FILE *stream)
341{
342  return dll_fgets(s, size, stream);
343}
344
345int __wrap__IO_getc(FILE *stream)
346{
347  return dll_getc(stream);
348}
349
350int __wrap__IO_getc_unlocked(FILE *stream)
351{
352  return dll_getc(stream);
353}
354
355int __wrap_getc_unlocked(FILE *stream)
356{
357  return dll_getc(stream);
358}
359
360int __wrap_ungetc(int c, FILE *stream)
361{
362  return dll_ungetc(c, stream);
363}
364
365int __wrap_getc(FILE *stream)
366{
367  return dll_getc(stream);
368}
369
370int __wrap_ioctl(int d, unsigned long int request, ...)
371{
372    int res;
373    va_list va;
374    va_start(va, request);
375    res = dll_ioctl(d, request, va);
376    va_end(va);
377    return res;
378}
379
380int __wrap__stat(const char *path, struct _stat *buffer)
381{
382  return dll_stat(path, buffer);
383}
384
385int __wrap_stat(const char *path, struct _stat *buffer)
386{
387  return dll_stat(path, buffer);
388}
389
390int __wrap___xstat(int __ver, const char *__filename, struct stat *__stat_buf)
391{
392  return dll_stat(__filename, __stat_buf);
393}
394
395int __wrap___xstat64(int __ver, const char *__filename, struct stat64 *__stat_buf)
396{
397  return dll_stat64(__filename, __stat_buf);
398}
399
400int __wrap___lxstat64(int __ver, const char *__filename, struct stat64 *__stat_buf)
401{
402  return dll_stat64(__filename, __stat_buf);
403}
404
405void __wrap_flockfile(FILE *file)
406{
407    dll_flockfile(file);
408}
409
410int __wrap_ftrylockfile(FILE *file)
411{
412    return dll_ftrylockfile(file);
413}
414
415void __wrap_funlockfile(FILE *file)
416{
417    dll_funlockfile(file);
418}
419
420int __wrap___fxstat64(int ver, int fd, struct stat64 *buf)
421{
422  return dll_fstat64(fd, buf);
423}
424
425int __wrap___fxstat(int ver, int fd, struct stat *buf)
426{
427  return dll_fstat(fd, buf);
428}
429
430int __wrap_fstat(int fd, struct _stat *buf)
431{
432  return dll_fstat(fd, buf);
433}
434
435int __wrap_setvbuf(FILE *stream, char *buf, int type, size_t size)
436{
437   return dll_setvbuf(stream, buf, type, size);
438}
439
440struct mntent *__wrap_getmntent(FILE *fp)
441{
442#ifdef TARGET_POSIX
443  return dll_getmntent(fp);
444#endif
445  return NULL;
446}
447
448// GCC 4.3 in Ubuntu 8.10 defines _FORTIFY_SOURCE=2 which means, that fread, read etc
449// are actually #defines which are inlined when compiled with -O. Those defines
450// actually call __*chk (for example, __fread_chk). We need to bypass this whole
451// thing to actually call our wrapped functions.
452#if _FORTIFY_SOURCE > 1
453
454size_t __wrap___fread_chk(void * ptr, size_t ptrlen, size_t size, size_t n, FILE * stream)
455{
456  return dll_fread(ptr, size, n, stream);
457}
458
459int __wrap___printf_chk(int flag, const char *format, ...)
460{
461  int res;
462  va_list va;
463  va_start(va, format);
464  res = dll_vfprintf(stdout, format, va);
465  va_end(va);
466  return res;
467}
468
469int __wrap___vfprintf_chk(FILE* stream, int flag, const char *format, va_list ap)
470{
471  return dll_vfprintf(stream, format, ap);
472}
473
474int __wrap___fprintf_chk(FILE * stream, int flag, const char *format, ...)
475{
476  int res;
477  va_list va;
478  va_start(va, format);
479  res = dll_vfprintf(stream, format, va);
480  va_end(va);
481  return res;
482}
483
484char *__wrap___fgets_chk(char *s, size_t size, int n, FILE *stream)
485{
486  return dll_fgets(s, n, stream);
487}
488
489size_t __wrap___read_chk(int fd, void *buf, size_t nbytes, size_t buflen)
490{
491  return dll_read(fd, buf, nbytes);
492}
493
494#endif