file_stream.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (C) 2010-2018 The RetroArch team
  2. *
  3. * ---------------------------------------------------------------------------------------
  4. * The following license statement only applies to this file (file_stream.h).
  5. * ---------------------------------------------------------------------------------------
  6. *
  7. * Permission is hereby granted, free of charge,
  8. * to any person obtaining a copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  11. * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef __LIBRETRO_SDK_FILE_STREAM_H
  23. #define __LIBRETRO_SDK_FILE_STREAM_H
  24. #include <stdio.h>
  25. #include <stdint.h>
  26. #include <stdlib.h>
  27. #include <stddef.h>
  28. #include <sys/types.h>
  29. #include <libretro.h>
  30. #include <retro_common_api.h>
  31. #include <retro_inline.h>
  32. #include <boolean.h>
  33. #include <stdarg.h>
  34. #include <vfs/vfs_implementation.h>
  35. #define FILESTREAM_REQUIRED_VFS_VERSION 2
  36. RETRO_BEGIN_DECLS
  37. typedef struct RFILE RFILE;
  38. #define FILESTREAM_REQUIRED_VFS_VERSION 2
  39. void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info);
  40. int64_t filestream_get_size(RFILE *stream);
  41. int64_t filestream_truncate(RFILE *stream, int64_t length);
  42. /**
  43. * filestream_open:
  44. * @path : path to file
  45. * @mode : file mode to use when opening (read/write)
  46. * @bufsize : optional buffer size (-1 or 0 to use default)
  47. *
  48. * Opens a file for reading or writing, depending on the requested mode.
  49. * Returns a pointer to an RFILE if opened successfully, otherwise NULL.
  50. **/
  51. RFILE* filestream_open(const char *path, unsigned mode, unsigned hints);
  52. int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position);
  53. int64_t filestream_read(RFILE *stream, void *data, int64_t len);
  54. int64_t filestream_write(RFILE *stream, const void *data, int64_t len);
  55. int64_t filestream_tell(RFILE *stream);
  56. void filestream_rewind(RFILE *stream);
  57. int filestream_close(RFILE *stream);
  58. int64_t filestream_read_file(const char *path, void **buf, int64_t *len);
  59. char* filestream_gets(RFILE *stream, char *s, size_t len);
  60. int filestream_getc(RFILE *stream);
  61. int filestream_scanf(RFILE *stream, const char* format, ...);
  62. int filestream_eof(RFILE *stream);
  63. bool filestream_write_file(const char *path, const void *data, int64_t size);
  64. int filestream_putc(RFILE *stream, int c);
  65. int filestream_vprintf(RFILE *stream, const char* format, va_list args);
  66. int filestream_printf(RFILE *stream, const char* format, ...);
  67. int filestream_error(RFILE *stream);
  68. int filestream_flush(RFILE *stream);
  69. int filestream_delete(const char *path);
  70. int filestream_rename(const char *old_path, const char *new_path);
  71. const char* filestream_get_path(RFILE *stream);
  72. bool filestream_exists(const char *path);
  73. /* Returned pointer must be freed by the caller. */
  74. char* filestream_getline(RFILE *stream);
  75. libretro_vfs_implementation_file* filestream_get_vfs_handle(RFILE *stream);
  76. RETRO_END_DECLS
  77. #endif