ssi_pal_file.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**************************************************************************************
  2. * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
  3. * *
  4. * This file and the related binary are licensed under the following license: *
  5. * *
  6. * ARM Object Code and Header Files License, v1.0 Redistribution. *
  7. * *
  8. * Redistribution and use of object code, header files, and documentation, without *
  9. * modification, are permitted provided that the following conditions are met: *
  10. * *
  11. * 1) Redistributions must reproduce the above copyright notice and the *
  12. * following disclaimer in the documentation and/or other materials *
  13. * provided with the distribution. *
  14. * *
  15. * 2) Unless to the extent explicitly permitted by law, no reverse *
  16. * engineering, decompilation, or disassembly of is permitted. *
  17. * *
  18. * 3) Redistribution and use is permitted solely for the purpose of *
  19. * developing or executing applications that are targeted for use *
  20. * on an ARM-based product. *
  21. * *
  22. * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  23. * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
  24. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
  25. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  33. **************************************************************************************/
  34. #ifndef _SSI_PAL_FILE_H
  35. #define _SSI_PAL_FILE_H
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. #include "ssi_pal_types.h"
  41. #include "ssi_pal_file_plat.h"
  42. /**
  43. * @brief File Description:
  44. * This file contains functions for file related operations. The functions implementations
  45. * are generally just wrappers to different operating system calls.
  46. * None of the described functions will check the input parameters so the behavior
  47. * of the APIs in illegal parameters case is dependent on the operating system behavior.
  48. *
  49. */
  50. /**** ----- Files General Definitions ----- ****/
  51. typedef enum
  52. {
  53. SASI_PAL_Read = 0, /* "r", read only */
  54. SASI_PAL_ReadAndWrite = 1, /* "r+", read and write */
  55. SASI_PAL_Write = 2, /* "w", write only */
  56. SASI_PAL_WriteAndRead = 3, /* "w+", write and read */
  57. SASI_PAL_Append = 4, /* "a", append to the end of file */
  58. SASI_PAL_AppendAndRead = 5, /* "a+", append (to the end of file) and read */
  59. SASI_PAL_ReadBinary = 6, /* "rb", read binary */
  60. SASI_PAL_ReadAndWriteBinary = 7, /* "r+b" read and write binary */
  61. SASI_PAL_WriteBinary = 8, /* "wb" write binary */
  62. SASI_PAL_WriteAndReadBinary = 9, /* "w+b" write and read binary */
  63. SASI_PAL_AppendBinary = 10, /* "ab" append binary */
  64. SASI_PAL_AppendAndReadBinary = 11, /* "a+b" append and read binary */
  65. SASI_PAL_DummyMode = 0x7FFFFFFF
  66. }SaSi_PalFileMode_t;
  67. /* Definitions for SEEK positions */
  68. #define SASI_PAL_SEEK_START 0 /* Seek from start of file */
  69. #define SASI_PAL_SEEK_CUR 1 /* Seek from current position */
  70. #define SASI_PAL_SEEK_END 2 /* Seek from end of file */
  71. /* Definition for DxFile */
  72. typedef struct _SaSiFile_t* SaSiFile_t;
  73. /**** ------------------------------------- ****/
  74. /*----------------------------
  75. PUBLIC FUNCTIONS
  76. -----------------------------------*/
  77. /**
  78. * @brief This function purpose is to create a new file. The function will delete a file
  79. * If it is already exist.
  80. *
  81. *
  82. * @param[in] aFileName - The file name to create
  83. *
  84. * @return The function returns a FILE handle to the opened file, in case of failure
  85. * the function will return NULL
  86. */
  87. SaSiFile_t SaSi_PalFileCreate( char *aFileName );
  88. /* Definition for SaSi_PalFileCreate */
  89. #define SaSi_PalFileCreate(aFileName) _SaSi_PalFileCreate(aFileName)
  90. /**
  91. * @brief This function purpose is to create a new file. The function will delete a file
  92. * If it is already exist.
  93. *
  94. *
  95. * @param[in] aFileName - The file name to open
  96. * @param[in] aFileMode - The mode to open the file
  97. *
  98. * @return The function returns a FILE handle to the opened file, in case of failure
  99. * the function will return NULL
  100. */
  101. SaSiFile_t SaSi_PalFOpen( char *aFileName, SaSi_PalFileMode_t aFileMode );
  102. /* Definition for fopen */
  103. #define SaSi_PalFOpen(aFileName, aFileMode) _SaSi_PalFOpen(aFileName, aFileMode)
  104. /**
  105. * @brief This function purpose is to close a file (pointed by aFileHandle), The function
  106. * will dissociate the file from the handle.
  107. *
  108. *
  109. * @param[in] aFileHandle - The file name to create
  110. *
  111. * @return The return values is according to operating system return values.
  112. */
  113. SaSiError_t SaSi_PalFClose( SaSiFile_t aFileHandle );
  114. /* Definition for fclose */
  115. #define SaSi_PalFClose(aFileHandle) _SaSi_PalFClose(aFileHandle)
  116. /**
  117. * @brief This function purpose is to change the file pointer position according to aOffset
  118. *
  119. *
  120. * @param[in] aFileHandle - The file handle
  121. * @param[in] aOffset - offset to move the file pointer inside the file
  122. * @param[in] aSeekOrigin - seek origin (current, end or start) to move aOffset from
  123. *
  124. * @return The return values is according to operating system return values.
  125. */
  126. SaSiError_t SaSi_PalFSeek( SaSiFile_t aFileHandle, int32_t aOffset, uint8_t aSeekOrigin );
  127. /* Definition for fseek */
  128. #define SaSi_PalFSeek(aFileHandle ,aOffset, aSeekOrigin) _SaSi_PalFSeek(aFileHandle, aOffset, aSeekOrigin)
  129. /**
  130. * @brief This function purpose is to return the file pointer position
  131. *
  132. *
  133. * @param[in] aFileHandle - The file handle
  134. *
  135. * @return The file pointer position
  136. */
  137. uint32_t SaSi_PalFTell( SaSiFile_t aFileHandle );
  138. /* definition for SaSi_PalFTell */
  139. #define SaSi_PalFTell(aFileHandle) _SaSi_PalFTell(aFileHandle)
  140. /**
  141. * @brief This function purpose is to read aSize of bytes from the file and write it
  142. * to aBuffer. In case EOF reached before aSize is read the returned size is smaller
  143. * than aSize.
  144. *
  145. *
  146. * @param[in] aFileHandle - The file handle
  147. * @param[in] aBuffer - Pointer to buffer to read the data into
  148. * @param[in] aSize - Number of bytes to read from file
  149. *
  150. * @return The number of bytes read from the file
  151. */
  152. uint32_t SaSi_PalFRead(SaSiFile_t aFileHandle, void *aBuffer, uint32_t aSize );
  153. /* Definition for fread */
  154. #define SaSi_PalFRead(aFileHandle, aBuffer, aSize) _SaSi_PalFRead(aFileHandle, aBuffer, aSize)
  155. /**
  156. * @brief This function purpose is to write aSize bytes from aBuffer to the file pointed
  157. * by aFileHandle.
  158. *
  159. *
  160. * @param[in] aFileHandle - The file handle
  161. * @param[in] aBuffer - Pointer to buffer to read the data into
  162. * @param[in] aSize - Number of bytes to read from file
  163. *
  164. * @return The number of bytes written to the file
  165. */
  166. uint32_t SaSi_PalFWrite( SaSiFile_t aFileHandle, const void *aBuffer, uint32_t aSize );
  167. #define SaSi_PalFWrite(aFileHandle, aBuffer, aSize) _SaSi_PalFWrite(aFileHandle, aBuffer, aSize)
  168. /**
  169. * @brief This function purpose is to save all buffered data to disk
  170. *
  171. *
  172. * @param[in] aFileHandle - The file handle
  173. *
  174. * @return The return values is according to operating system return values.
  175. */
  176. SaSiError_t SaSi_PalFFlush( SaSiFile_t aFileHandle );
  177. /* Definition for fflush */
  178. #define SaSi_PalFFlush(aFileHandle) _SaSi_PalFFlush(aFileHandle)
  179. /**
  180. * @brief This function purpose is to return the file size
  181. *
  182. *
  183. * @param[in] aFileHandle - The file handle
  184. * @param[out] aFileSize - The returned file size
  185. *
  186. * @return The function will return SASI_SUCCESS in case of success, else errors from
  187. * ssi_pal_error.h is returned.
  188. */
  189. SaSiError_t SaSi_PalFGetFileSize( SaSiFile_t aFileHandle, uint32_t *aFileSize );
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #endif