file.h File Reference

OS file-system querying and manipulation. More...

#include <unistd.h>
#include <string>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <cstddef>
#include <ctime>
#include "debugging/debugging.h"
Include dependency graph for file.h:

Go to the source code of this file.

Namespaces

namespace  FileAccess

Defines

#define INCLUDED_OS_FILE_H

Typedefs

typedef std::size_t FileSize
typedef std::time_t FileTime
 Seconds elapsed since Jan 1, 1970.
typedef unsigned char byte

Enumerations

enum  FileAccess::Mode { FileAccess::Read = R_OK, FileAccess::Write = W_OK, FileAccess::ReadWrite = Read | Write, FileAccess::Exists = F_OK }

Functions

bool file_move (const std::string &from, const std::string &to)
 Attempts to move the file identified by from to to and returns true if the operation was successful.
bool file_remove (const std::string &path)
 Attempts to remove the file identified by path and returns true if the operation was successful.
bool file_accessible (const std::string &path, FileAccess::Mode mode)
 Returns true if the file or directory identified by path exists and/or may be accessed for reading, writing or both, depending on the value of mode.
bool file_readable (const std::string &path)
 Returns true if the file or directory identified by path exists and may be opened for reading.
bool file_writeable (const std::string &path)
 Returns true if the file or directory identified by path exists and may be opened for writing.
bool file_exists (const std::string &path)
 Returns true if the file or directory identified by path exists.
bool file_is_directory (const std::string &path)
 Returns true if the file or directory identified by path exists and is a directory.
FileSize file_size (const std::string &path)
 Returns the size in bytes of the file identified by path, or 0 if the file was not found.
FileTime file_modified (const std::string &path)
 Returns the time that the file identified by path was last modified, or c_invalidFileTime if the file was not found.
int file_write (const void *buffer, int len, FILE *f)
 Properly handles partial writes.

Variables

const FileTime c_invalidFileTime = -1
 No file can have been modified earlier than this time.

Detailed Description

OS file-system querying and manipulation.

Definition in file file.h.


Define Documentation

#define INCLUDED_OS_FILE_H

Definition at line 28 of file file.h.


Typedef Documentation

typedef unsigned char byte

Definition at line 134 of file file.h.

typedef std::size_t FileSize

Definition at line 109 of file file.h.

typedef std::time_t FileTime

Seconds elapsed since Jan 1, 1970.

Definition at line 121 of file file.h.


Function Documentation

bool file_accessible ( const std::string path,
FileAccess::Mode  mode 
) [inline]

Returns true if the file or directory identified by path exists and/or may be accessed for reading, writing or both, depending on the value of mode.

Definition at line 77 of file file.h.

Referenced by file_exists(), file_readable(), and file_writeable().

bool file_exists ( const std::string path  )  [inline]

Returns true if the file or directory identified by path exists.

Definition at line 95 of file file.h.

References FileAccess::Exists, and file_accessible().

bool file_is_directory ( const std::string path  )  [inline]

Returns true if the file or directory identified by path exists and is a directory.

Definition at line 101 of file file.h.

FileTime file_modified ( const std::string path  )  [inline]

Returns the time that the file identified by path was last modified, or c_invalidFileTime if the file was not found.

Definition at line 126 of file file.h.

References c_invalidFileTime.

bool file_move ( const std::string from,
const std::string to 
) [inline]

Attempts to move the file identified by from to to and returns true if the operation was successful.

The operation will fail unless:

  • The path from identifies an existing file which is accessible for writing.
  • The directory component of from identifies an existing directory which is accessible for writing.
  • The path to does not identify an existing file or directory.
  • The directory component of to identifies an existing directory which is accessible for writing.

Definition at line 53 of file file.h.

bool file_readable ( const std::string path  )  [inline]

Returns true if the file or directory identified by path exists and may be opened for reading.

Definition at line 83 of file file.h.

References file_accessible(), and FileAccess::Read.

bool file_remove ( const std::string path  )  [inline]

Attempts to remove the file identified by path and returns true if the operation was successful.

The operation will fail unless:

  • The path identifies an existing file.
  • The parent-directory component of path identifies an existing directory which is accessible for writing.

Definition at line 63 of file file.h.

FileSize file_size ( const std::string path  )  [inline]

Returns the size in bytes of the file identified by path, or 0 if the file was not found.

Definition at line 112 of file file.h.

int file_write ( const void *  buffer,
int  len,
FILE *  f 
) [inline]

Properly handles partial writes.

Definition at line 139 of file file.h.

References block(), and byte.

bool file_writeable ( const std::string path  )  [inline]

Returns true if the file or directory identified by path exists and may be opened for writing.

Definition at line 89 of file file.h.

References file_accessible(), and FileAccess::Write.


Variable Documentation

No file can have been modified earlier than this time.

Definition at line 123 of file file.h.

Referenced by file_modified().


Generated by  doxygen 1.6.2