FBB::Stat(3) Determines File Characteristics

SYNOPSIS

#include <bobcat/stat>
Linking option: -lbobcat

DESCRIPTION

Stat is a wrapper around the stat(2) system function. In particular, it offers features to test directly for object characteristics offered by stat(2). To determine whether an object exists the Stat bool conversion operator can be used.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

ENUMERATIONS

Stat::Combine:
This enumeration defines the following values:

  • ALL: require all of the specified Mode or SpecialMode values to match;
  • ANY: require any match of the specified Mode or SpecialMode values (one match suffices);

Stat::Mode:
This enumeration defines the following values:

  • UR: the owner of the object has read permissions
  • UW: the owner of the object has write permissions
  • UX: the owner of the object has execute permissions
  • GR: the group to which the object belongs has read permissions
  • GW: the group to which the object belongs has write permissions
  • GX: the group to which the object belongs has execute permissions
  • OR: others have read permissions
  • OW: others have write permissions
  • OX: others have execute permissions
  • READ: equal to UR | GR | OR
  • WRITE: equal to UW | GW | OW
  • EXEC: equal to UX | GX | OX
  • RWX: all of the above.

Stat::SpecialMode:
This enumeration defines the following values:

  • SUID: set UID bit is up
  • SGID: set GID bit is up
  • SB: sticky bit is up

Stat::Type:
This enumeration, which is identical to the glob(3bobcat) Type enumeration, defines the following values:

  • BLOCK_DEVICE: the object represents a block device
  • CHARACTER_DEVICE: the object represents a character device
  • DIRECTORY: the object represents a directory
  • FIFO: the object represents a named pipe (a queue)
  • REGULAR_FILE: the object represents a regular file
  • SOCKET: the object represents a socket
  • SYMBOLIC_LINK: the object represents a symbolic link
  • ANY: any of the above types

CONSTRUCTORS

  • Stat():
    The default constructor, creating an empty Stat object.
  • Stat(std::string const &fname):
    Initializes a Stat with a given object name.
  • Stat(std::string const &fname, std::string const &searchPath):
    Initializes a Stat with a given object name, where the object is searched in the searchPath directories, which is a colon-separated string of directory names. The filenames are constructed by appending fname to each of the elements of searchPath until an existing object is found. This object is then used. If fname is an absolute path, searchPath is ignored. The copy constructor is available.

OVERLOADED OPERATORS

  • operator bool() const:
    This operator returns true if the Stat object holds information about an existing object. Otherwise false is returned.

The default assignment operator is available.

MEMBER FUNCTIONS

  • bool access(FBB::User const &user, size_t spec, bool useEffective = true) const:
    Returns true if user has the permissions as specified at spec (of which only the defined Mode bits are interpreted). If a combination of read, write and/or execute permissions are specified, then at least one of the read permissions, one of the write permissions and one of the execute permissions must be granted or the function returns false. E.g, when specifying access(user, UW | UR | GR) then the user must have write permissions, but either the user or the user's group must have read permissions. If multiple read, multiple write or multiple execute permissions are specified (like UR | GR) then this member returns true if at least one of the requested read, write, or execute permissions are granted for user.
  • size_t blockSize() const:
    Returns the blocksize (st_blksize) for filesystem I/O
  • size_t device() const:
    Returns the device id (st_dev).
  • size_t deviceType() const:
    Returns the device type number, but only if the object type is DEVICE (st_rdev).
  • size_t error() const:
    Returns the error number associated with an error, in cases where operator bool() returns false. A returned value of 0 indicates `no errors'.
  • bool isType(Stat::Type probe):
    Returns true if the object has the probed type otherwise false is returned.
  • size_t inode() const:
    Returns the inode number (st_ino).
  • size_t gid() const:
    Returns the group ID of the object's owner (st_gid).
  • FBB::DateTime lastAccess() const:
    Returns a FBB::DateTime object holding information about the object's time of last access (st_atime) (using UTC).
  • FBB::DateTime lastChange() const:
    Returns a FBB::DateTime object holding information about the object's time of last status change (st_ctime) (using UTC).
  • FBB::DateTime lastModification() const:
    Returns a FBB::DateTime object holding information about the object's last modification time (st_mtime) (using UTC).
  • size_t mode() const:
    Returns the object's raw, uninterpreted mode (st_mode & RWX). Note that this value is usually displayed (and is processed most easily) as an octal value.
  • bool mode(size_t mode, Combine combine = ALL):
    Returns true if the object has the indicated mode. Multiple modes may be set, which can be combined by the logical bitor operator. By default, if multiple modes are specified, the resulting pattern must exactly represent the object's mode for the member function to return true. An optional argument ANY may be specified if the function should return true if at least one specified mode matches the object's actual mode. An Exception exception is thrown if the specified mode contains other values than the defined Mode or SpecialMode values.
  • std::string modeStr() const:
    Returns the standard string-representation of the object's mode (e.g., rw-r--r--). Special modes (e.g., suid) are indicated by s instead of x when the object is user and/or group executable and by S if the object has the special mode bit(s) set, but is not executable. For the `other' executable mode flag t is used (`sticky' bit) and T if the object is not `other' executable.
  • std::string const &name() const:
    Returns the object's name as specified in the constructor or set() member function.
  • size_t nBlocks() const:
    Returns the object's number of allocated blocks (st_blocks).
  • size_t nLinks() const:
    Returns the object's number of hard links (st_nlink).
  • std::string path() const:
    Returns the object's full pathname. If the full pathname could not be determined, an empty string is returned.
  • bool set(std::string const &name):
    Redefine the Stat object to represent the information about the indicated object name.
  • bool set(std::string const &name, std::string const &pathlist):
    Redefine the Stat object to represent the information about the indicated object name, where the object is searched in the pathlist directories, which is a colon-separated string of directory names. The object names are constructed by appending fname to each of the elements of searchPath until an existing object is found. This object is then used. If fname is an absolute path, searchPath is ignored.
  • off_t size() const:
    Returns the object's size in number of bytes (st_size).
  • bool specialMode(size_t special, Combine combine = ALL):
    Returns true if the object has the indicated special modes. Multiple special modes may be specified, which can be combined by the logical bitor operator. By default, if multiple modes are specified, the resulting pattern must exactly represent the object's mode for the member function to return true. An optional argument ANY may be specified if the function should return true if at least one specified mode matches the object's actual mode. The non-special modes are ignored but a Exception exception is thrown if special contains other values than those defined by the SpecialMode enum.
  • Stat::stat const &statStruct() const:
    Returns a reference to the object's stat struct.
  • Stat::Type type() const:
    Returns the Stat::Type value of the object.
  • std::string typeStr() const:
    Returns a textual representation of the object's type as returned by the Stat::type() member function.
  • size_t uid() const:
    Returns the user ID of the object's owner (st_uid).

EXAMPLE

/*
                              driver.cc
*/
#include <iostream>
#include <string>
#include <bobcat/stat>
#include <bobcat/datetime>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
    if (argc == 1)
    {
        cout << "Usage: driver object [colon-separated searchpath]\n";
        return 1;
    }
    Stat st;
    if (argc == 2)
        st.set(argv[1]);
    else if (argc == 3)
        st.set(argv[1], argv[2]);
    if (!st)
    {
        cout << "Can't stat " << argv[1] << ", errno = " << st.error() << endl;
        return 1;
    }
    cout << st.name() << ": access: " << st.lastAccess() << "\n" <<
            st.name() << ": change: " << st.lastChange() << "\n" <<
            st.name() << ": modif:  " << st.lastModification() << "\n"   
            "Mode: " << oct << st.mode() <<  " (" << st.modeStr() << ")\n" 
            "Type: " << st.type() << " (" << st.typeStr() << ")\n"
            "Full path:  " << st.path()  << endl;
    return 0;
}

FILES

bobcat/stat - defines the class interface

BUGS

None Reported.

DISTRIBUTION FILES

  • bobcat_4.02.00-x.dsc: detached signature;
  • bobcat_4.02.00-x.tar.gz: source archive;
  • bobcat_4.02.00-x_i386.changes: change log;
  • libbobcat1_4.02.00-x_*.deb: debian package holding the libraries;
  • libbobcat1-dev_4.02.00-x_*.deb: debian package holding the libraries, headers and manual pages;
  • http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken ([email protected]).