Max 5 API Reference
00001 00002 #ifndef _SYSFILE_H_ 00003 #define _SYSFILE_H_ 00004 00005 00006 00007 /** A t_filehandle is a cross-platform way of referring to an open file. 00008 It is an opaque structure, meaning you don’t have access to the individual 00009 elements of the data structure. You can use a t_filehandle only 00010 with the file routines in the Sysfile API. Do not use other platform- 00011 specific file functions in conjunction with these functions. 00012 The perm parameter can be either READ_PERM, WRITE_PERM, or RW_PERM. 00013 00014 @ingroup files */ 00015 typedef void *t_filehandle; 00016 00017 00018 /** Modes used by sysfile_setpos() 00019 @ingroup files */ 00020 typedef enum { 00021 SYSFILE_ATMARK = 0, ///< ? 00022 SYSFILE_FROMSTART, ///< Calculate the file position from the start of the file. 00023 SYSFILE_FROMLEOF, ///< Calculate the file position from the logical end of the file. 00024 SYSFILE_FROMMARK ///< Calculate the file position from the current file position. 00025 } e_max_sysfile_posmodes; 00026 00027 00028 /** Flags used reading and writing text files. 00029 @ingroup files */ 00030 typedef enum { 00031 TEXT_LB_NATIVE = 0x00000001L, ///< Use the linebreak format native to the current platform. 00032 TEXT_LB_MAC = 0x00000002L, ///< Use Macintosh line breaks 00033 TEXT_LB_PC = 0x00000004L, ///< Use Windows line breaks 00034 TEXT_LB_UNIX = 0x00000008L, ///< Use Unix line breaks 00035 TEXT_ENCODING_USE_FILE = 0x00000100L, ///< If this flag is not set then the encoding is forced to UTF8 00036 TEXT_NULL_TERMINATE = 0x00000200L ///< Terminate memory returned from sysfile_readtextfile() with a NULL character 00037 } e_max_sysfile_textflags; 00038 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 00045 /** Close a file opened with sysfile_open(). 00046 This function is similar to FSClose() or fclose(). 00047 It should be used instead of system-specific file closing routines in order to make max external 00048 code that will compile cross-platform. 00049 00050 @ingroup files 00051 @param f The #t_filehandle structure of the file the user wants to close. 00052 @return An error code. 00053 */ 00054 extern long sysfile_close(t_filehandle f); 00055 00056 00057 /** Read a file from disk. 00058 This function is similar to FSRead() or fread(). It should be used instead of 00059 these functions (or other system-specific file reading routines) in order 00060 to make max external code that will compile cross-platform. It reads 00061 “count” bytes from file handle at current file position into “bufptr”. 00062 The byte count actually read is set in “count”, and the file position is 00063 updated by the actual byte count read. 00064 00065 @ingroup files 00066 @param f The #t_filehandle structure of the file the user wants to open. 00067 @param count Pointer to the number of bytes that will be read from the file at the current file position. 00068 The byte count actually read is returned to this value. 00069 @param bufptr Pointer to the buffer that the data will be read into. 00070 @return An error code. 00071 */ 00072 extern long sysfile_read(t_filehandle f, long *count, void *bufptr); 00073 00074 00075 /** Read the contents of a file into a handle. 00076 @ingroup files 00077 @param f The open #t_filehandle structure to read into the handle. 00078 @param h The address of a handle into which the file will be read. 00079 @return An error code. 00080 @remark You should free the pointer, when you are done with it, using sysmem_freehandle(). 00081 */ 00082 extern long sysfile_readtohandle(t_filehandle f, char ***h); 00083 00084 00085 /** Read the contents of a file into a pointer. 00086 @ingroup files 00087 @param f The open #t_filehandle structure to read into the handle. 00088 @param p The address of a pointer into which the file will be read. 00089 @return An error code. 00090 @remark You should free the pointer, when you are done with it, using sysmem_freeptr(). 00091 */ 00092 extern long sysfile_readtoptr(t_filehandle f, char **p); 00093 00094 00095 /** Write part of a file to disk. 00096 This function is similar to FSWrite() or fwrite(). It should be used instead 00097 of these functions (or other system-specific file reading routines) in 00098 order to make max external code that will compile cross-platform. The 00099 function writes “count” bytes from “bufptr” into file handle at current 00100 file position. The byte count actually written is set in "count", and the 00101 file position is updated by the actual byte count written. 00102 00103 @ingroup files 00104 @param f The t_filehandle structure of the file to which the user wants to write. 00105 @param count Pointer to the number of bytes that will be written to the file at the current file position. 00106 The byte count actually written is returned to this value. 00107 @param bufptr Pointer to the buffer that the data will be read from. 00108 @return An error code. 00109 */ 00110 extern long sysfile_write(t_filehandle f, long *count, const void *bufptr); 00111 00112 00113 /** Set the size of a file handle. 00114 This function is similar to and should be used instead of SetEOF(). 00115 The function sets the size of file handle in bytes, specified by “logeof”. 00116 00117 @ingroup files 00118 @param f The file's #t_filehandle structure. 00119 @param logeof The file size in bytes. 00120 @return An error code. 00121 */ 00122 extern long sysfile_seteof(t_filehandle f, long logeof); 00123 00124 00125 /** Get the size of a file handle. 00126 This function is similar to and should be used instead of GetEOF(). 00127 The function gets the size of file handle in bytes, and places it in “logeof”. 00128 00129 @ingroup files 00130 @param f The file's #t_filehandle structure. 00131 @param logeof The file size in bytes is returned to this value. 00132 @return An error code. 00133 */ 00134 extern long sysfile_geteof(t_filehandle f, long *logeof); 00135 00136 00137 /** Set the current file position of a file handle. 00138 This function is similar to and should be used instead of SetFPos(). 00139 It is used to set the current file position of file handle to by the given 00140 number of offset bytes relative to the mode used, as defined in #e_max_sysfile_posmodes. 00141 00142 @ingroup files 00143 @param f The file's #t_filehandle structure. 00144 @param mode Mode from which the offset will be calculated, as defined in #e_max_sysfile_posmodes. 00145 @param offset The offset in bytes relative to the mode. 00146 @return An error code. 00147 */ 00148 extern long sysfile_setpos(t_filehandle f, long mode, long offset); 00149 00150 00151 /** Get the current file position of a file handle. 00152 This function is similar to and should be used instead of GetFPos(). 00153 The function gets the current file position of file handle in bytes, and places it in "filepos". 00154 00155 @ingroup files 00156 @param f The file's #t_filehandle structure. 00157 @param filepos The address of a variable to hold the current file position of file handle in bytes. 00158 @return An error code. 00159 */ 00160 extern long sysfile_getpos(t_filehandle f, long *filepos); 00161 00162 00163 /** Copy the contents of one file handle to another file handle. 00164 @ingroup files 00165 @param src The file handle from which to copy. 00166 @param dst The file handle to which the copy is written. 00167 @param size The number of bytes to copy. If 0 the size of src will be used. 00168 @return An error code. 00169 */ 00170 long sysfile_spoolcopy(t_filehandle src, t_filehandle dst, long size); 00171 00172 00173 // private 00174 void sysfile_setobject(t_filehandle f, t_object *o); 00175 00176 00177 00178 /** Read a text file from disk. 00179 This function reads up to the maximum number of bytes given by 00180 maxlen from file handle at current file position into the htext 00181 handle, performing linebreak translation if set in flags. 00182 00183 @ingroup files 00184 @param f The #t_filehandle structure of the text file the user wants to open. 00185 @param htext Handle that the data will be read into. 00186 @param maxlen The maximum length in bytes to be read into the handle. 00187 Passing the value 0L indicates no maximum (i.e. read the entire file). 00188 @param flags Flags to set linebreak translation as defined in #e_max_sysfile_textflags. 00189 @return An error code. 00190 */ 00191 extern long sysfile_readtextfile(t_filehandle f, t_handle htext, long maxlen, long flags); 00192 00193 00194 /** Write a text file to disk. 00195 This function writes a text handle to a text file performing linebreak 00196 translation if set in flags. 00197 00198 @ingroup files 00199 @param f The #t_filehandle structure of the text file to which the user wants to write. 00200 @param htext Handle that the data that will be read from. 00201 @param flags Flags to set linebreak translation as defined in #e_max_sysfile_textflags. 00202 @return An error code. 00203 */ 00204 extern long sysfile_writetextfile(t_filehandle f, t_handle htext, long flags); 00205 00206 00207 /** Create a #t_filehandle from a pre-existing handle. 00208 @ingroup files 00209 @param h A handle for some data. 00210 @param flags Pass 0 (additional flags are private). 00211 @param fh The address of a #t_filehandle which will be allocated. 00212 @return An error code. 00213 */ 00214 short sysfile_openhandle(char **h, long flags, t_filehandle *fh); 00215 00216 00217 /** Create a #t_filehandle from a pre-existing pointer. 00218 @ingroup files 00219 @param p A pointer to some data. 00220 @param length The size of p. 00221 @param flags Pass 0 (additional flags are private). 00222 @param fh The address of a #t_filehandle which will be allocated. 00223 @return An error code. 00224 */ 00225 short sysfile_openptrsize(char *p, long length, long flags, t_filehandle *fh); 00226 00227 00228 #ifdef __cplusplus 00229 } 00230 #endif 00231 00232 #endif // _SYSFILE_H_ 00233
Copyright © 2008, Cycling '74