libgpio
Functions
file.h File Reference

File Helper Library API. More...

#include <unistd.h>
#include <stdbool.h>
Include dependency graph for file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int file_get_size (char *filename, off_t *size)
 Get size of file in bytes. More...
 
bool file_is_present (char *filename)
 Determine if file is present (i.e., exists) More...
 
int file_read (int fd, void *buf, size_t len)
 Read specified number of bytes from file or socket. More...
 
int file_write (int fd, void *buf, size_t len)
 Write specified number of bytes to file or socket. More...
 
int file_owc (char *filename, void *buf, size_t len)
 Open, write to, and close a file. More...
 

Detailed Description

File Helper Library API.

Author
Mark Greer mgree.nosp@m.r@an.nosp@m.imalc.nosp@m.reek.nosp@m..com

Function Documentation

int file_get_size ( char *  filename,
off_t *  size 
)

Get size of file in bytes.

Parameters
[in]filenamePointer to filename string
[out]sizePointer to where file size is placed
Returns
0 on success, negative errno on failure
bool file_is_present ( char *  filename)

Determine if file is present (i.e., exists)

Parameters
[in]filenamePointer to filename string
Returns
true when file exists, false when it doesn't exist
int file_owc ( char *  filename,
void *  buf,
size_t  len 
)

Open, write to, and close a file.

Parameters
[in]filenamePointer to filename string
[in]bufBuffer containing data to write
[in]lenNumber of bytes to write
Returns
0 on success, negative errno on failure

Open the specified file, write the specified number of bytes, and close the file. It may block indefinitely as described by the file_write() documentation.

int file_read ( int  fd,
void *  buf,
size_t  len 
)

Read specified number of bytes from file or socket.

Parameters
[in]fdFile descriptor to read from
[out]bufBuffer to place incoming data
[in]lenNumber of bytes to read
Returns
0 on success, negative errno on failure

Read the specified number of bytes from the file/pipe/socket associated with the passed in file descriptor. It will block waiting indefinitely for the specified number of bytes to be received or until it is interrupted. If the read() system call returns with a return code of zero, -ECONNRESET will be returned.

int file_write ( int  fd,
void *  buf,
size_t  len 
)

Write specified number of bytes to file or socket.

Parameters
[in]fdFile descriptor to write to
[in]bufBuffer containing data to write
[in]lenNumber of bytes to write
Returns
0 on success, negative errno on failure

Write the specified number of bytes to the file/pipe/socket associated with the passed in file descriptor. It will block indefinitely until the specified number of bytes have been accepted by the kernel or until it is interrupted.