-1

I'm writing a C program using nftw() to walk a filesystem and retrieve file modification times for each file.

nftw() calls a supplied function pointer and provides a struct stat as an argument.

man stat(2) states that the time modification fields are:

struct timespec st_atim;  /* time of last access */
struct timespec st_mtim;  /* time of last modification */
struct timespec st_ctim;  /* time of last status change */

However, whilst man stat(2) provides an example of how to print the time fields, it doesn't tell me how to find information about struct timespec, nor how to query/manipulate the time modification fields.

How should I go about finding that information on my computer alone, without resorting to Google?

retrodev
  • 2,323
  • 6
  • 24
  • 48

3 Answers3

1

Typically one of the man pages describes what these structures contain. If you tell us your platform I can give further details. Otherwise, open up the header /usr/include/time.h to see what struct timespec is defined as.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • I'm running Ubuntu 15.10 64bit. – retrodev Jan 20 '16 at 12:38
  • I'm guessing you know to open up time.h from experience. The man page makes no reference to that header. How could I have come to that conclusion myself? – retrodev Jan 20 '16 at 12:40
  • @retrodev [POSIX specifies](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html) that this is the place where `struct timespec` is declared. – fuz Jan 20 '16 at 12:58
  • @retrodev You could also search for `struct timespec` in `/usr/include` to find potential declarations. – fuz Jan 20 '16 at 12:59
0
$ apropos timespec
clock_gettime        (2)  - Return the current timespec value of tp for the specified clock
$ man 2 clock_gettime
Andrea Bergia
  • 5,502
  • 1
  • 23
  • 38
0

Usually, when I need information on data types or functions, if not included in the man pages, I issue a command like the following:

grep -r "timespec" /usr/include/

in the path where are the header files.

terence hill
  • 3,354
  • 18
  • 31