Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 3rd, 2011  |  syntax: C  |  size: 4.55 KB  |  views: 70  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. */
  63.  
  64. #if !defined(PLUGIN) && !defined(CODEC)
  65.  
  66. #if defined(APPLICATION)
  67. #   define FN_PREFIX       app_
  68. #elif defined(SIMULATOR)
  69. #   define FN_PREFIX       sim_
  70. #endif /* SIMULATOR */
  71.  
  72. /*
  73.    Define to what the function names should expand
  74.    (alphabetically ordered for easier matching with declarations below)
  75. */
  76. #ifdef FN_PREFIX
  77. #define close(x)       FN_PREFIX ## close(x)
  78. #define creat(x,m)     FN_PREFIX ## creat(x,m)
  79. #define fdprintf (fd, fmt, ...) FN_PREFIX ## fdprintf(fd, fmt, __VA_ARGS__)
  80. #define filesize(x)    FN_PREFIX ## filesize(x)
  81. #define fsync(x)       FN_PREFIX ## fsync(x)
  82. #define ftruncate(x,y) FN_PREFIX ## ftruncate(x,y)
  83. #define lseek(x,y,z)   FN_PREFIX ## lseek(x,y,z)
  84. #define open(x, ...)   FN_PREFIX ## open(x, __VA_ARGS__)
  85. #define read(x,y,z)    FN_PREFIX ## read(x,y,z)
  86. #define remove(x)      FN_PREFIX ## remove(x)
  87. #define rename(x,y)    FN_PREFIX ## rename(x,y)
  88. #define write(x,y,z)   FN_PREFIX ## write(x,y,z)
  89. #undef FN_PREFIX
  90. #endif /* FN_PREFIX */
  91.  
  92.  
  93. #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(__PCTOOL__)
  94. /* posix compatibility function */
  95. static inline int creat(const char *pathname, mode_t mode)
  96. {
  97.     (void)mode;
  98.     return file_creat(pathname);
  99. }
  100. #define creat(path, mode) file_creat(path)
  101. #define open(x, y, ...)   file_open(x,y)
  102. extern int release_files(int volume);
  103. #endif /* CONFIG_PLATFORM & PLATFORM_NATIVE) && !__PCTOOL__ */
  104.  
  105.  
  106. /* Function declarations */
  107. extern int     close(int fd);
  108. extern int     creat(const char *pathname, mode_t mode);
  109. extern off_t   filesize(int fd);
  110. extern int     fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
  111. extern int     fsync(int fd);
  112. extern int     ftruncate(int fd, off_t length);
  113. extern off_t   lseek(int fildes, off_t offset, int whence);
  114. extern int     open(const char* pathname, int flags, ...);
  115. extern ssize_t read(int fd, void *buf, size_t count);
  116. extern int     remove(const char* pathname);
  117. extern int     rename(const char* path, const char* newname);
  118. extern ssize_t write(int fd, const void *buf, size_t count);
  119.  
  120. #endif /* !PLUGIN && !CODEC */
  121.  
  122. #endif /* _FILE_H_ */
clone this paste RAW Paste Data