op_fileio.c File Reference

Reading from / writing to files. More...

#include <unistd.h>
#include "op_fileio.h"
#include "op_libiberty.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
Include dependency graph for op_fileio.c:

Functions

FILE * op_try_open_file (char const *name, char const *mode)
 op_try_open_file - open a file
FILE * op_open_file (char const *name, char const *mode)
 op_open_file - open a file
void op_close_file (FILE *fp)
 op_close_file - close a file
void op_write_file (FILE *fp, void const *buf, size_t size)
 op_write_file - write to a file
void op_write_u8 (FILE *fp, u8 val)
 op_write_u8 - write a byte to a file
void op_write_u32 (FILE *fp, u32 val)
 op_write_u32 - write four bytes to a file
void op_write_u64 (FILE *fp, u64 val)
 op_write_u64 - write eight bytes to a file
unsigned long op_read_long_from_file (char const *filename, int fatal)
 op_read_long_from_file - parse an ASCII value from a file into an unsigned long
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
char * op_get_line (FILE *fp)
 op_get_line - read an ASCII line from a file
unsigned long calc_crc32 (unsigned long crc, unsigned char *buf, size_t len)
 calc_crc32

Detailed Description

Reading from / writing to files.

Remarks:
Copyright 2002 OProfile authors
Read the file COPYING
Author:
John Levon
Philippe Elie

Function Documentation

unsigned long calc_crc32 ( unsigned long  crc,
unsigned char *  buf,
size_t  len 
)

calc_crc32

Parameters:
crc current value
buf pointer to buffer
len Returns current crc computed from the crc argument and the characters in len characters in buf.
void op_close_file ( FILE *  fp  ) 

op_close_file - close a file

Parameters:
fp file pointer

Closes a file pointer. A non-fatal error message is produced if the close fails.

Referenced by opd_reread_module_info().

char* op_get_line ( FILE *  fp  ) 

op_get_line - read an ASCII line from a file

Parameters:
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

Referenced by opd_reread_module_info().

FILE* op_open_file ( char const *  name,
char const *  mode 
)

op_open_file - open a file

Parameters:
name file name
mode mode string

Open a file name. Failure to open is fatal.

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

Parameters:
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.

Referenced by opd_read_fs_int().

unsigned long op_read_long_from_file ( char const *  filename,
int  fatal 
)

op_read_long_from_file - parse an ASCII value from a file into an unsigned long

Parameters:
filename name of file to parse value from
fatal non-zero if any error must be fatal

Reads an ASCII unsigned long number from the given file. If an error occurs,and the passed 'fatal' arg is zero, then (unsigned long)-1 is returned; else the value read in is returned.

FILE* op_try_open_file ( char const *  name,
char const *  mode 
)

op_try_open_file - open a file

Parameters:
name file name
mode mode string

Open a file name. Returns file handle or NULL on failure.

Referenced by opd_reread_module_info().

void op_write_file ( FILE *  fp,
void const *  buf,
size_t  size 
)

op_write_file - write to a file

Parameters:
fp file pointer
buf buffer
size nr. of bytes to write

Write size bytes of buffer buf to a file. Failure is fatal.

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

Parameters:
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.

References op_write_file().

void op_write_u64 ( FILE *  fp,
u64  val 
)

op_write_u64 - write eight bytes to a file

Parameters:
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.

References op_write_file().

void op_write_u8 ( FILE *  fp,
u8  val 
)

op_write_u8 - write a byte to a file

Parameters:
fp file pointer
val value to write

Write an unsigned byte value val to a file. Failure is fatal.

References op_write_file().


Generated on 29 Jul 2013 for oprofile by  doxygen 1.6.1