00001 /** 00002 * @file op_fileio.h 00003 * Reading from / writing to files 00004 * 00005 * @remark Copyright 2002 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author John Levon 00009 * @author Philippe Elie 00010 */ 00011 00012 #ifndef OP_FILEIO_H 00013 #define OP_FILEIO_H 00014 00015 #ifdef __cplusplus 00016 extern "C" { 00017 #endif 00018 00019 #include "op_types.h" 00020 00021 #include <stdio.h> 00022 00023 /** 00024 * op_try_open_file - open a file 00025 * @param name file name 00026 * @param mode mode string 00027 * 00028 * Open a file name. 00029 * Returns file handle or %NULL on failure. 00030 */ 00031 FILE * op_try_open_file(char const * name, char const * mode); 00032 00033 /** 00034 * op_open_file - open a file 00035 * @param name file name 00036 * @param mode mode string 00037 * 00038 * Open a file name. 00039 * Failure to open is fatal. 00040 */ 00041 FILE * op_open_file(char const * name, char const * mode); 00042 00043 /** 00044 * op_read_int_from_file - parse an ASCII value from a file into an integer 00045 * @param filename name of file to parse integer value from 00046 * @param fatal non-zero if any error must be fatal 00047 * 00048 * Reads an ASCII integer from the given file. If an error occur and fatal is 00049 * zero (u32)-1 is returned else the value read in is returned. 00050 */ 00051 u32 op_read_int_from_file(char const * filename, int fatal); 00052 00053 /** 00054 * op_close_file - close a file 00055 * @param fp file pointer 00056 * 00057 * Closes a file pointer. A non-fatal 00058 * error message is produced if the 00059 * close fails. 00060 */ 00061 void op_close_file(FILE * fp); 00062 00063 /** 00064 * op_write_file - write to a file 00065 * @param fp file pointer 00066 * @param buf buffer 00067 * @param size nr. of bytes to write 00068 * 00069 * Write size bytes of buffer buf to a file. 00070 * Failure is fatal. 00071 */ 00072 void op_write_file(FILE * fp, void const * buf, size_t size); 00073 00074 /** 00075 * op_write_u32 - write four bytes to a file 00076 * @param fp file pointer 00077 * @param val value to write 00078 * 00079 * Write an unsigned four-byte value val to a file. 00080 * Failure is fatal. 00081 * 00082 * No byte-swapping is done. 00083 */ 00084 void op_write_u32(FILE * fp, u32 val); 00085 00086 /** 00087 * op_write_u64 - write eight bytes to a file 00088 * @param fp file pointer 00089 * @param val value to write 00090 * 00091 * Write an unsigned eight-byte value val to a file. 00092 * Failure is fatal. 00093 * 00094 * No byte-swapping is done. 00095 */ 00096 void op_write_u64(FILE * fp, u64 val); 00097 00098 /** 00099 * op_write_u8 - write a byte to a file 00100 * @param fp file pointer 00101 * @param val value to write 00102 * 00103 * Write an unsigned byte value val to a file. 00104 * Failure is fatal. 00105 */ 00106 void op_write_u8(FILE * fp, u8 val); 00107 00108 /** 00109 * op_get_line - read an ASCII line from a file 00110 * @param fp file pointer 00111 * 00112 * Get a line of ASCII text from a file. The file is read 00113 * up to the first '\0' or '\n'. A trailing '\n' is deleted. 00114 * 00115 * Returns the dynamically-allocated string containing 00116 * that line. At the end of a file NULL will be returned. 00117 * be returned. 00118 * 00119 * The string returned must be free()d by the caller. 00120 * 00121 * getline() is not a proper solution to replace this function 00122 */ 00123 char * op_get_line(FILE * fp); 00124 00125 /** 00126 * calc_crc32 00127 * @param crc current value 00128 * @param buf pointer to buffer 00129 * @param len 00130 * 00131 * Returns current crc computed from the crc argument and the 00132 * characters in len characters in buf. 00133 */ 00134 unsigned long calc_crc32(unsigned long crc, unsigned char * buf, size_t len); 00135 00136 #ifdef __cplusplus 00137 } 00138 #endif 00139 00140 #endif /* OP_FILEIO_H */
1.6.1