#include <unistd.h>
#include "op_fileio.h"
#include "op_libiberty.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
Go to the source code of this file.
Functions | |
static FILE * | op_do_open_file (char const *name, char const *mode, int fatal) |
FILE * | op_try_open_file (char const *name, char const *mode) |
FILE * | op_open_file (char const *name, char const *mode) |
void | op_close_file (FILE *fp) |
void | op_write_file (FILE *fp, void const *buf, size_t size) |
void | op_write_u8 (FILE *fp, u8 val) |
void | op_write_u32 (FILE *fp, u32 val) |
void | op_write_u64 (FILE *fp, u64 val) |
u32 | op_read_int_from_file (char const *filename, int fatal) |
char * | op_get_line (FILE *fp) |
unsigned long | calc_crc32 (unsigned long crc, unsigned char *buf, size_t len) |
Reading from / writing to files
Definition in file op_fileio.c.
unsigned long calc_crc32 | ( | unsigned long | crc, | |
unsigned char * | buf, | |||
size_t | len | |||
) |
calc_crc32
crc | current value | |
buf | pointer to buffer | |
len | Returns current crc computed from the crc argument and the characters in len characters in buf. |
Definition at line 165 of file op_fileio.c.
void op_close_file | ( | FILE * | fp | ) |
op_close_file - close a file
fp | file pointer |
Closes a file pointer. A non-fatal error message is produced if the close fails.
Definition at line 52 of file op_fileio.c.
Referenced by op_cpu_freq_cpuinfo(), op_cpu_freq_sys_devices(), opd_get_ascii_maps(), opd_get_module_info(), opd_reread_module_info(), and read_tgid().
static FILE* op_do_open_file | ( | char const * | name, | |
char const * | mode, | |||
int | fatal | |||
) | [static] |
Definition at line 22 of file op_fileio.c.
Referenced by op_open_file(), and op_try_open_file().
char* op_get_line | ( | FILE * | fp | ) |
op_get_line - read an ASCII line from a file
fp | file pointer |
Get a line of ASCII text from a file. The file is read up to the first '' or '
'. A trailing '
' is deleted.
Returns the dynamically-allocated string containing that line. At the end of a file NULL will be returned. be returned.
The string returned must be free()d by the caller.
getline() is not a proper solution to replace this function
Definition at line 126 of file op_fileio.c.
References buf.
Referenced by _record_module_info(), get_mapping(), op_cpu_freq_cpuinfo(), op_cpu_freq_sys_devices(), opd_get_ascii_maps(), opd_get_module_info(), opd_reread_module_info(), read_events(), read_tgid(), and read_unit_masks().
FILE* op_open_file | ( | char const * | name, | |
char const * | mode | |||
) |
op_open_file - open a file
name | file name | |
mode | mode string |
Open a file name. Failure to open is fatal.
Definition at line 46 of file op_fileio.c.
References op_do_open_file().
u32 op_read_int_from_file | ( | char const * | filename, | |
int | fatal | |||
) |
op_read_int_from_file - parse an ASCII value from a file into an integer
filename | name of file to parse integer value from | |
fatal | non-zero if any error must be fatal |
Reads an ASCII integer from the given file. If an error occur and fatal is zero (u32)-1 is returned else the value read in is returned.
Definition at line 95 of file op_fileio.c.
Referenced by opd_read_fs_int().
FILE* op_try_open_file | ( | char const * | name, | |
char const * | mode | |||
) |
op_try_open_file - open a file
name | file name | |
mode | mode string |
Open a file name. Returns file handle or NULL on failure.
Definition at line 40 of file op_fileio.c.
References op_do_open_file().
Referenced by op_cpu_freq_cpuinfo(), op_cpu_freq_sys_devices(), opd_get_ascii_maps(), opd_get_module_info(), opd_reread_module_info(), and read_tgid().
void op_write_file | ( | FILE * | fp, | |
void const * | buf, | |||
size_t | size | |||
) |
op_write_file - write to a file
fp | file pointer | |
buf | buffer | |
size | nr. of bytes to write |
Write size bytes of buffer buf to a file. Failure is fatal.
Definition at line 59 of file op_fileio.c.
Referenced by op_write_u32(), op_write_u64(), and op_write_u8().
void op_write_u32 | ( | FILE * | fp, | |
u32 | val | |||
) |
op_write_u32 - write four bytes to a file
fp | file pointer | |
val | value to write |
Write an unsigned four-byte value val to a file. Failure is fatal.
No byte-swapping is done.
Definition at line 83 of file op_fileio.c.
References op_write_file().
void op_write_u64 | ( | FILE * | fp, | |
u64 | val | |||
) |
op_write_u64 - write eight bytes to a file
fp | file pointer | |
val | value to write |
Write an unsigned eight-byte value val to a file. Failure is fatal.
No byte-swapping is done.
Definition at line 89 of file op_fileio.c.
References op_write_file().
void op_write_u8 | ( | FILE * | fp, | |
u8 | val | |||
) |
op_write_u8 - write a byte to a file
fp | file pointer | |
val | value to write |
Write an unsigned byte value val to a file. Failure is fatal.
Definition at line 77 of file op_fileio.c.
References op_write_file().