You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

152 lines
3.8 KiB

  1. /*
  2. * FILE stream functions
  3. *
  4. * Copyright (C) 2008-2019, Joachim Metz <joachim.metz@gmail.com>
  5. *
  6. * Refer to AUTHORS for acknowledgements.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #if !defined( _FILE_STREAM_H )
  22. #define _FILE_STREAM_H
  23. #include "common.h"
  24. #if defined( HAVE_GLIB_H )
  25. #include <glib.h>
  26. #include <glib/gstdio.h>
  27. #endif
  28. #include <stdio.h>
  29. #if defined( __cplusplus )
  30. extern "C" {
  31. #endif
  32. #define FILE_STREAM_OPEN_APPEND "a"
  33. #define FILE_STREAM_OPEN_READ "r"
  34. #define FILE_STREAM_OPEN_WRITE "w"
  35. #if defined( WINAPI )
  36. #define FILE_STREAM_BINARY_OPEN_APPEND "ab"
  37. #define FILE_STREAM_BINARY_OPEN_READ "rb"
  38. #define FILE_STREAM_BINARY_OPEN_WRITE "wb"
  39. #else
  40. #define FILE_STREAM_BINARY_OPEN_APPEND "a"
  41. #define FILE_STREAM_BINARY_OPEN_READ "r"
  42. #define FILE_STREAM_BINARY_OPEN_WRITE "w"
  43. #endif
  44. /* narrow character FILE stream open
  45. */
  46. #if defined( HAVE_GLIB_H )
  47. #define file_stream_open( filename, mode ) \
  48. g_fopen( filename, mode )
  49. #elif defined( HAVE_FOPEN ) || defined( WINAPI )
  50. #define file_stream_open( filename, mode ) \
  51. fopen( filename, mode )
  52. #endif
  53. /* wide character FILE stream open
  54. */
  55. #if defined( WINAPI )
  56. #define file_stream_open_wide( filename, mode ) \
  57. _wfopen( filename, mode )
  58. #endif
  59. /* FILE stream close
  60. */
  61. #if defined( HAVE_FCLOSE ) || defined( WINAPI )
  62. #define file_stream_close( stream ) \
  63. fclose( stream )
  64. #endif
  65. /* FILE stream read
  66. */
  67. #if defined( HAVE_FREAD ) || defined( WINAPI )
  68. #define file_stream_read( stream, data, size ) \
  69. fread( data, 1, size, stream )
  70. #endif
  71. /* FILE stream write
  72. */
  73. #if defined( HAVE_FWRITE ) || defined( WINAPI )
  74. #define file_stream_write( stream, data, size ) \
  75. fwrite( data, 1, size, stream )
  76. #endif
  77. /* FILE stream seek
  78. */
  79. #if defined( WINAPI )
  80. #define file_stream_seek_offset( stream, offset, whence ) \
  81. fseek( stream, offset, whence )
  82. #elif defined( HAVE_FSEEKO )
  83. #define file_stream_seek_offset( stream, offset, whence ) \
  84. fseeko( stream, offset, whence )
  85. #elif defined( HAVE_FSEEKO64 )
  86. #define file_stream_seek_offset( stream, offset, whence ) \
  87. fseeko64( stream, offset, whence )
  88. #endif
  89. /* End of FILE stream
  90. */
  91. #if defined( HAVE_FEOF ) || defined( WINAPI )
  92. #define file_stream_at_end( stream ) \
  93. feof( stream )
  94. #endif
  95. /* Get narrow character string from FILE stream
  96. */
  97. #if defined( HAVE_FGETS ) || defined( WINAPI )
  98. #define file_stream_get_string( stream, string, size ) \
  99. fgets( string, size, stream )
  100. #endif
  101. /* Get wide characters string from FILE stream
  102. */
  103. #if defined( HAVE_FGETWS ) || defined( WINAPI )
  104. #define file_stream_get_string_wide( stream, string, size ) \
  105. fgetws( string, size, stream )
  106. #endif
  107. /* Variable arguments formatted print to stream function
  108. */
  109. #if defined( HAVE_GLIB_H )
  110. #define file_stream_vfprintf( stream, format, ... ) \
  111. g_vfprintf( stream, format, __VA_ARGS__ )
  112. /* Borland BCC previous to version 5.6.0 cannot handle the macro form: MACRO( ... )
  113. */
  114. #elif defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
  115. #define file_stream_vfprintf \
  116. vfprintf
  117. #elif defined( HAVE_VFPRINTF ) || defined( WINAPI )
  118. #define file_stream_vfprintf( stream, format, ... ) \
  119. vfprintf( stream, format, __VA_ARGS__ )
  120. #endif
  121. #if defined( __cplusplus )
  122. }
  123. #endif
  124. #endif /* !defined( _FILE_STREAM_H ) */