Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.61 KB | None | 0 0
  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id: file.h 28752 2010-12-06 22:26:31Z kugel $
  9.  *
  10.  * Copyright (C) 2002 by Björn Stenberg
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License
  14.  * as published by the Free Software Foundation; either version 2
  15.  * of the License, or (at your option) any later version.
  16.  *
  17.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  18.  * KIND, either express or implied.
  19.  *
  20.  ****************************************************************************/
  21.  
  22. #ifndef _FILE_H_
  23. #define _FILE_H_
  24.  
  25. #include <sys/types.h>
  26. #include "config.h"
  27. #include "gcc_extensions.h"
  28. #include <fcntl.h>
  29. #ifdef WIN32
  30. /* this has SEEK_SET et al */
  31. #include <stdio.h>
  32. #endif
  33.  
  34.  
  35. #undef MAX_PATH /* this avoids problems when building simulator */
  36. #define MAX_PATH 260
  37. #define MAX_OPEN_FILES 11
  38.  
  39. typedef int (*open_func)(const char* pathname, int flags, ...);
  40. typedef ssize_t (*read_func)(int fd, void *buf, size_t count);
  41. typedef int (*creat_func)(const char *pathname, mode_t mode);
  42. typedef ssize_t (*write_func)(int fd, const void *buf, size_t count);
  43. typedef void (*qsort_func)(void *base, size_t nmemb,  size_t size,
  44.                            int(*_compar)(const void *, const void *));
  45.  
  46. /*
  47.    The function declaration scheme is as follows.
  48.  
  49.    - For plugins and codecs, no file access functions are declared since
  50.      in this case they are accessed via the rb API.
  51.  
  52.    - For application build (target or sim), they are declared as macros
  53.      which expand to app_xxx. I.e. the functions that get declared after
  54.      the preprocessing are "app_open", "app_remove" etc. These functions
  55.      are implemented using the host functions "open", "remove" etc.
  56.  
  57.    - For non-app simulator builds, they are declared as macros
  58.      which expand to sim_xxx. I.e. the functions that get declared after
  59.      the preprocessing are "sim_open", "sim_remove" etc. These functions
  60.      are implemented using the host functions "open", "remove" etc.
  61.  
  62.    - For non-app target builds, they are declared as-is.
  63.  
  64. */
  65.  
  66. #if !defined(PLUGIN) && !defined(CODEC)
  67.  
  68. #if defined(APPLICATION)
  69. #   define FN_PREFIX       app_
  70. #elif defined(SIMULATOR)
  71. #   define FN_PREFIX       sim_
  72. #endif /* SIMULATOR */
  73.  
  74. /*
  75.    Define to what the function names should expand
  76.    (alphabetically ordered for easier matching with declarations below)
  77. */
  78. #ifdef FN_PREFIX
  79. #define close(x)       FN_PREFIX ## close(x)
  80. #define creat(x,m)     FN_PREFIX ## creat(x,m)
  81. #define fdprintf(fd, fmt, ...) FN_PREFIX ## fdprintf(fd, fmt, __VA_ARGS__)
  82. #define filesize(x)    FN_PREFIX ## filesize(x)
  83. #define fsync(x)       FN_PREFIX ## fsync(x)
  84. #define ftruncate(x,y) FN_PREFIX ## ftruncate(x,y)
  85. #define lseek(x,y,z)   FN_PREFIX ## lseek(x,y,z)
  86. #define open(x, ...)   FN_PREFIX ## open(x, __VA_ARGS__)
  87. #define read(x,y,z)    FN_PREFIX ## read(x,y,z)
  88. #define remove(x)      FN_PREFIX ## remove(x)
  89. #define rename(x,y)    FN_PREFIX ## rename(x,y)
  90. #define write(x,y,z)   FN_PREFIX ## write(x,y,z)
  91. #undef FN_PREFIX
  92. #endif /* FN_PREFIX */
  93.  
  94.  
  95. #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(__PCTOOL__)
  96. /* posix compatibility function */
  97. static inline int creat(const char *pathname, mode_t mode)
  98. {
  99.     (void)mode;
  100.     return file_creat(pathname);
  101. }
  102. #define creat(path, mode) file_creat(path)
  103. #define open(x, y, ...)   file_open(x,y)
  104. extern int release_files(int volume);
  105. #endif /* CONFIG_PLATFORM & PLATFORM_NATIVE) && !__PCTOOL__ */
  106.  
  107.  
  108. /* Function declarations */
  109. extern int     close(int fd);
  110. extern int     creat(const char *pathname, mode_t mode);
  111. extern off_t   filesize(int fd);
  112. extern int     fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
  113. extern int     fsync(int fd);
  114. extern int     ftruncate(int fd, off_t length);
  115. extern off_t   lseek(int fildes, off_t offset, int whence);
  116. extern int     open(const char* pathname, int flags, ...);
  117. extern ssize_t read(int fd, void *buf, size_t count);
  118. extern int     remove(const char* pathname);
  119. extern int     rename(const char* path, const char* newname);
  120. extern ssize_t write(int fd, const void *buf, size_t count);
  121.  
  122. #endif /* !PLUGIN && !CODEC */
  123.  
  124. #endif /* _FILE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement