Home > OS >  where is it documented where O_NOATIME is declared?
where is it documented where O_NOATIME is declared?

Time:09-08

When I try to compile this SSCCE code (on Ubuntu 16.04 , Kernel 4.15)

// defines and include needed according to openat manpage at man7.org
#define _POSIX_C_SOURCE 200809L
#define _ATFILE_SOURCE
#include <sys/types.h>  // additional include according to die.net , but not man7.org
#include <sys/stat.h>   // additional include according to die.net , but not man7.org
#include <fcntl.h>  

int main() {
    openat(3, "foobar", O_NOATIME, 0);
}

I get

error: ‘O_NOATIME’ undeclared 

I am not really looking for someone tell me: "it is in the file <xxx.h> , include that". I can find myself where it happens to be on my system.

I am writing code that not only I have to compile on this system and I am happy, but will be compiled by other people or other systems. I have to write all code according to what is documented in some reputable source (such as man7 or die.net, but their documentation does not work for me). The reason for this is "plausible deniability" - if they fail to compile, I can't just say "it worked for me" - that would be lame; I need to be able to say "it says in so-and-so godly source that it should work" AND "I checked that".

CodePudding user response:

From https://man7.org/linux/man-pages/man2/open.2.html :

The O_DIRECT, O_NOATIME, O_PATH, and O_TMPFILE flags are Linux- specific. One must define _GNU_SOURCE to obtain their definitions.

You have to define _GNU_SOURCE and #include <fcntl.h>.

  • Related