bio.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* =============================================================================
  2. * PROGRAM: CODE LIBRARY
  3. * FILENAME: bio.h
  4. *
  5. * DESCRIPTION:
  6. *
  7. * Buffered I/O package.
  8. *
  9. * Allows multiple small reads and writes to be handled efficiently.
  10. * Probably not so good for large reads/writes.
  11. * Excellent for reading IFF pictures though.
  12. *
  13. * Duplicates the Amiga DOS functions and are used in exactly the same
  14. * way as their counterparts as described in the Amiga technical reference
  15. * Manual (Libraries and devices).
  16. *
  17. * =============================================================================
  18. * COPYRIGHT:
  19. *
  20. * Copyright (c) 1996, 2004, Julian Olds
  21. * All rights reserved.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. *
  27. * . Redistributions of source code must retain the above copyright notice,
  28. * this list of conditions and the following disclaimer.
  29. *
  30. * . Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in the
  32. * documentation and/or other materials provided with the distribution.
  33. *
  34. * The name of the author may not be used to endorse or promote products
  35. * derived from this software without specific prior written permission.
  36. *
  37. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  38. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  41. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  42. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  43. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  44. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  47. * THE POSSIBILITY OF SUCH DAMAGE.
  48. *
  49. * =============================================================================
  50. * EXPORTED VARIABLES
  51. *
  52. * None
  53. *
  54. * =============================================================================
  55. * EXPORTED FUNCTIONS
  56. *
  57. * BOpen : Open a buffered I/O file.
  58. * BClose : Close a buffered I/O file.
  59. * BRead : Read from a buffered I/O file.
  60. * BSeek : Seek a position in a buffered I/O file.
  61. * BWrite : Write to a buffered I/O file.
  62. *
  63. * =============================================================================
  64. */
  65. #ifndef __BIO_H
  66. #define __BIO_H
  67. #include <libraries/dos.h>
  68. #include <libraries/dosextens.h>
  69. /*
  70. ** NOTE : The buffer is used for either input out output at any one time.
  71. ** Any read after a write, or write after a read will cause the
  72. ** buffer to be flushed.
  73. ** The seek operation will also cause the buffer to be flushed.
  74. */
  75. struct BFile {
  76. BPTR file; /* Pointer to a DOS file handle */
  77. UBYTE *buffer; /* Pointer to Input/Output buffer */
  78. long file_offset; /* Current position in buffered file */
  79. long buffer_size; /* Number of bytes read into the buffer */
  80. long in_buffer_count; /* Position in the buffer for input */
  81. long out_buffer_count; /* Position in the buffer for output */
  82. };
  83. /* =============================================================================
  84. * FUNCTION: BOpen
  85. *
  86. * DESCRIPTION:
  87. * This function opens a file for buffered I/O reading and/or writing.
  88. *
  89. * PARAMETERS:
  90. *
  91. * name : The name of the file to open.
  92. *
  93. * accessMode : The access mode for the file.
  94. *
  95. * RETURN VALUE:
  96. *
  97. * BFile *: A pointer the the buffered I/O file opened, or NULL if the
  98. * open failed.
  99. */
  100. struct BFile *BOpen(char *name, long accessMode);
  101. /* =============================================================================
  102. * FUNCTION: BClose
  103. *
  104. * DESCRIPTION:
  105. * This function closes a buffered I/O file.
  106. *
  107. * PARAMETERS:
  108. *
  109. * file : A pointer to the file to close.
  110. *
  111. * RETURN VALUE:
  112. *
  113. * None.
  114. */
  115. void BClose(struct BFile *file);
  116. /* =============================================================================
  117. * FUNCTION: BRead
  118. *
  119. * DESCRIPTION:
  120. * This function reads 'length' bytes from 'file' into the buffer 'buff'.
  121. *
  122. * PARAMETERS:
  123. *
  124. * file : A pointer to the buffered I/O file handle of the file to read.
  125. *
  126. * buff : A pointer to the buffer to hold the data read.
  127. *
  128. * length : The number of bytes to read.
  129. *
  130. * RETURN VALUE:
  131. *
  132. * long: The number of bytes actually read.
  133. */
  134. long BRead(struct BFile *file, UBYTE *buff, long length);
  135. /* =============================================================================
  136. * FUNCTION: BSeek
  137. *
  138. * DESCRIPTION:
  139. * This function seeks a position in a bufferd I/O file.
  140. *
  141. * PARAMETERS:
  142. *
  143. * file : A pointer to the buffered I/O file handle of the file to seek.
  144. *
  145. * position : The position in the file to seek.
  146. *
  147. * mod : The seek mode.
  148. *
  149. * RETURN VALUE:
  150. *
  151. * long: The new file position.
  152. */
  153. long BSeek(struct BFile *file, long position, long mod);
  154. /* =============================================================================
  155. * FUNCTION: BWrite
  156. *
  157. * DESCRIPTION:
  158. * This function write 'length' bytes from 'buff' to a buffered I/O file.
  159. *
  160. * PARAMETERS:
  161. *
  162. * file : A pointer to the bufferd I/O file handle of the file to write.
  163. *
  164. * buff : A pointer to the buffer containing the data to be written.
  165. *
  166. * length : The number of bytes to write.
  167. *
  168. * RETURN VALUE:
  169. *
  170. * long: The number of bytes actually written to the file.
  171. */
  172. long BWrite(struct BFile *file, UBYTE *buff, long length);
  173. #endif