File: stat.cc

package info (click to toggle)
icmake 13.05.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,132 kB
  • sloc: cpp: 11,595; fortran: 883; makefile: 853; sh: 546; pascal: 342
file content (28 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#define XERR
#include "builtin.ih"

//  This function expects a filename as last pushed
//  value. The file attributes are retrieved by Stat
//  A list is returned, containing:
//
//      [0]: the file's attributes.
//      [1]: the file size.

void Builtin::stat()
{
    int check = d_stack[2].value();
    Stat st{ d_stack[3].str() };

    if (not st)
    {
        if (check == P_CHECK)
            throw Exception{} << "can't stat `" << st.name() << '\'';
        d_reg = vector<string>{ "-1" };
    }
    else
    {
        auto &stat = st.statStruct();
        d_reg = vector<string>{ to_string(stat.st_mode),
                                to_string(stat.st_size) };
    }
}