Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stat st_mode is always equal to 16877

I want to know if a file is a directory or a regular file with stat :

#define _DEFAULT_SOURCE

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int is_regular_file(const char *path)
{
    struct stat path_stat;
    stat(path, &path_stat);
    return S_ISREG(path_stat.st_mode);
}

I try on Mac and Linux and when I print S_ISREG(path_stat.st_mode) is always equal to 1 and path_stat.st_mode is always equal to 16877.

like image 638
Max0u Avatar asked Sep 20 '25 20:09

Max0u


1 Answers

16877 is octal 40755, which denotes a directory (octal 40000) with permissions 755 (user has full rights, everyone else has read and traversal rights). As suggested, the stat and chmod manual pages are useful.

Just for example, here is a screenshot with my directory-editor showing octal modes (an option) rather than the usual symbol ones:

ded showing octal permissions

like image 193
Thomas Dickey Avatar answered Sep 22 '25 09:09

Thomas Dickey