Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Fileio.cxx File Reference
#include "Devtab.hxx"
#include <cstdarg>
#include <fcntl.h>
#include <reent.h>
#include <unistd.h>
#include <sys/select.h>

Go to the source code of this file.

Functions

int _open_r (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
int _close_r (struct _reent *reent, int fd)
 Close a file or device.
 
ssize_t _read_r (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
ssize_t _write_r (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
int _stat_r (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
int _fstat_r (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
int _isatty_r (struct _reent *reent, int fd)
 Get the tty information of a file or device.
 
int _unlink_r (struct _reent *reent, const char *path)
 remove a file.
 
_off_t _lseek_r (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
int fsync (int fd)
 Synchronize (flush) a file to disk.
 
int ioctl (int fd, unsigned long int key,...)
 Request and ioctl transaction.
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 POSIX select().
 
int fcntl (int fd, int cmd,...)
 Manipulate a file descriptor.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This file implements the generic fileio.

Author
Stuart W. Baker
Date
27 December 2012

Definition in file Fileio.cxx.

Function Documentation

◆ _close_r()

int _close_r ( struct _reent *  reent,
int  fd 
)

Close a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to close
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 347 of file Fileio.cxx.

◆ _fstat_r()

int _fstat_r ( struct _reent *  reent,
int  fd,
struct stat *  stat 
)

Get the status information of a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to get status of
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 400 of file Fileio.cxx.

◆ _isatty_r()

int _isatty_r ( struct _reent *  reent,
int  fd 
)

Get the tty information of a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor determine if it is a tty
Returns
1 if a tty, else 0

Definition at line 410 of file Fileio.cxx.

◆ _lseek_r()

_off_t _lseek_r ( struct _reent *  reent,
int  fd,
_off_t  offset,
int  whence 
)

Change the offset index of a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to seek
offsetoffset within file
whencetype of seek to complete
Returns
resulting offset from beginning of file, -1 upon failure with errno containing the cause

Definition at line 432 of file Fileio.cxx.

◆ _open_r()

int _open_r ( struct _reent *  reent,
const char *  path,
int  flags,
int  mode 
)

Open a file or device.

Parameters
reentthread safe reentrant structure
pathfile or device name
flagsopen flags
modeopen mode, ignored in this implementation
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 331 of file Fileio.cxx.

◆ _read_r()

ssize_t _read_r ( struct _reent *  reent,
int  fd,
void *  buf,
size_t  count 
)

Read from a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to read
buflocation to place read data
countnumber of bytes to read
Returns
number of bytes read upon success, -1 upon failure with errno containing the cause

Definition at line 360 of file Fileio.cxx.

◆ _stat_r()

int _stat_r ( struct _reent *  reent,
const char *  path,
struct stat *  stat 
)

Get the status information of a file or device.

Parameters
reentthread safe reentrant structure
pathfile or device name
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 383 of file Fileio.cxx.

◆ _unlink_r()

int _unlink_r ( struct _reent *  reent,
const char *  path 
)

remove a file.

Parameters
reentthread safe reentrant structure
pathfile name
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 420 of file Fileio.cxx.

◆ _write_r()

ssize_t _write_r ( struct _reent *  reent,
int  fd,
const void *  buf,
size_t  count 
)

Write to a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to write
buflocation to find write data
countnumber of bytes to write
Returns
number of bytes written upon success, -1 upon failure with errno containing the cause

Definition at line 372 of file Fileio.cxx.

◆ fcntl()

int fcntl ( int  fd,
int  cmd,
  ... 
)

Manipulate a file descriptor.

Parameters
fdfile descriptor
cmdoperation to perform
...parameter to the cmd operation
Returns
dependent on the operation (POSIX compliant where applicable) or -1 on error with errno set appropriately

Definition at line 494 of file Fileio.cxx.

◆ fsync()

int fsync ( int  fd)

Synchronize (flush) a file to disk.

Parameters
fdfile descriptor to synch
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 441 of file Fileio.cxx.

◆ ioctl()

int ioctl ( int  fd,
unsigned long int  key,
  ... 
)

Request and ioctl transaction.

Parameters
fdfile descriptor
keyioctl key
...key data
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 452 of file Fileio.cxx.

◆ select()

int select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout 
)

POSIX select().

Parameters
nfdshighest numbered file descriptor in any of the three, sets plus 1
readfdsfd_set of file descritpors to pend on read active
writefdsfd_set of file descritpors to pend on write active
exceptfdsfd_set of file descritpors to pend on error active
timeouttimeout value to wait, if 0, return immediately, if NULL wait forever
Returns
on success, number of file descriptors in the three sets that are active, 0 on timeout, -1 with errno set appropriately upon error.

Definition at line 473 of file Fileio.cxx.