Search code examples
statibm-doors

What Stat type store in Doors DXL?


What is the purpose of the Stat type? Something like the status of an operation? I did not find much in the DXL Reference Manual 9.6.

The functions that use the Stat data type work on the stat API provided by the operating system, which enables DXL programs to determine the status of files and directories

To be more clear I will post one of its usages:

/************************************
    isDirectory

    Returns true if string parameter is a valid directory
************************************/
bool isDirectory(string dn)
{
    Stat s = create dn

    if (null s) return false
    if (directory s)
    {
        delete s
        return true
    }
    delete s
    return false
} 

Or the code like this:

/************************************
    getFileSize

    returns the size (in bytes) of a file. note that files smaller than
    the block size on the disc still take up a whole block.
************************************/
int getFileSize(string fn)
{
    int fSize = 0
    Stat s = create fn
    if (null s) return(0)

    fSize = size(s)
    if (fSize < BLOCK_SIZE) fSize = BLOCK_SIZE

    delete s
    return(fSize)
}

Edit:

Or Perms like:

Date modified (Stat)

bool symbolic (Stat)

Date accessed (Stat)

Stat create (Symbolic__)

void delete (Stat)

string user (Stat)

int size (Stat)


Solution

  • Stat is a data structure describing files and file-like elements like directories. You already found the purpose of this structure: to determine the status of files and directories. As the Reference Manual mentions in section 11, subsection Operating system commands, it is just a way to access OS stat function and datatype using DXL.

    For *nix based systems, the structure is fully described at http://man7.org/linux/man-pages/man2/stat.2.html. For Windows based systems, see https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx. You will notice that the concept is basically identical.

    The _stat function obtains information about the file or directory specified by path and stores it in the structure pointed to by buffer. [Windows]

    These functions return information about a file. [Linux]

    Since handling bit masks is not too handy, it is common practice to have a set of functions like bool directory (Stat) to check distinct flags in a more readable manner. If you are not interested in using the stat buffer at all, you usually create a layer of convenience functions on top, like bool isDirectory(string) in your example, so that you can check even more readable if a file/directory is a directory, is readable etc.