Does ROOT TSystem or FileStat_t support creation date?

I’m working with ROOT 6.08/06 and 5.34/32 on MacOSX. I would like to be able to access file creation times within a ROOT macro. FileStat_t does not provide this (only the last modification time).

Under MacOSX, the “filestat” struct is extended on 64-bit systems to include the “birthtime” of the file as well as other information. I understand that FileStat_t is meant to be cross-platform; is there some other way to access file creation time on platforms which support it?

In general, in a ROOT macro, you can call any C/C++ function (including these coming from system libraries).

Yes, that’s true in general, but it doesn’t appear to apply to <sys/stat.h>. If I try to #include the headers directly, ROOT won’t parse them appropriately.

I tried just calling stat(…) directly, without the #include, but it wouldn’t get that far. I’m not allowed to declare the necessary struct argument:

  struct stat filestat;
  if (0 != stat(fname.Data(), &filestat)) return 0.;	// Failed

Produces the ROOT error:

In file included from input_line_8:1:
/Users/kelsey/cdms/supersim-tests/dmc/weights/downsampling_analysis.C:137:15: error: 
      variable has incomplete type 'struct stat'
  struct stat filestat;
              ^
/Users/kelsey/cdms/supersim-tests/dmc/weights/downsampling_analysis.C:137:10: note: 
      forward declaration of 'stat'
  struct stat filestat;
         ^

I think #include <sys/stat.h> should be fine in ROOT 6, in interpreted and (pre)compiled macros. In ROOT 5 you will usually need to (pre)compile your macros (i.e. using ACLiC).

Huh. It seems that you’re right. Despite the “error:” messages I reported above from <sys/stat.h>, ROOT went ahead and successfully executed the stat() function to give me the file creation time. Thank you!

You should not get any errors after you #include <sys/stat.h> and, if you do, try to #include <sys/types.h> before it.

I still get the errors, but I realize that I did not quote them previously (the complaint about “incomplete type” was when I didn’t have the #include at all). Using <sys/types.h> doesn’t make a difference.

Here is the error I get from #include <sys/stat.h>:

{michaels-mbp:63} root -l -q -b downsampling_analysis.C
root [0] 
Processing downsampling_analysis.C...
In file included from input_line_8:1:
In file included from /Users/kelsey/cdms/supersim-tests/dmc/weights/downsampling_analysis.C:51:
/usr/include/sys/stat.h:373:58: error: expected function body after function
      declarator
int     futimens(int __fd, const struct timespec __times[2]) __API_AVAIL...
                                                             ^
/usr/include/sys/stat.h:375:15: error: expected function body after function
      declarator
                int __flag) __API_AVAILABLE(macosx(10.13), ios(11.0), tv...
                            ^

It seems that “__API_AVAILABLE” is a MacOS-specific thing defined in /usr/include/Availability.h and AvailabilityInternal.h (which sys/stat.h does itself include). Despite these error messages, ROOT does handle the functions and structs correctly.

Well, you might try to #include <fcntl.h> first, but I guess it’s a case for @Axel

Hi Michael,

Could you send a reproducer? A simple source file containing

#include <sys/stat.h>

works for me when loading it with .L file.C on MacOS 10.13, Xcode 9.3.1 with the master of ROOT.

Cheers, Axel.

Hi, Axel! Interesting. I’m also on Mac OS 10.13 with Xcode 9.3.1. I am using ROOT 6.08/06, though; maybe that’s the difference.
I reduced, like you, to a single line ROOT file with just the #include:

root [0] .L sys_stat.C
In file included from input_line_8:1:
In file included from /Users/kelsey/cdms/supersim-tests/dmc/weights/sys_stat.C:1:
/usr/include/sys/stat.h:373:58: error: expected function body after function
      declarator
int     futimens(int __fd, const struct timespec __times[2]) __API_AVAIL...
                                                             ^
/usr/include/sys/stat.h:375:15: error: expected function body after function
      declarator
                int __flag) __API_AVAILABLE(macosx(10.13), ios(11.0), tv...
                            ^
root [1] 

I will install the latest ROOT and see if this has gone away.

Try in ROOT 6:

root [0] .x trial.cxx

trial.cxx (403 Bytes)

Sorry I didn’t see this sooner! I just tried this, in ROOT 6.08/06, and got even more complaints than before :slight_smile:

root [0] .x /Users/kelsey/Desktop/trial.cxx
input_line_9:1:10: warning: non-portable path to file
      '"/uusrllocalRROOT66.08-06iincluderROOTTTString.h"'; specified path
      differs in case from file name on disk [-Wnonportable-include-path]
#include "/usr/local/ROOT/6.08-06/include/root/TString.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         "/uusrllocalRROOT66.08-06iincluderROOTTTString.h"
input_line_10:1:10: warning: non-portable path to file
      '"/uusrllocalRROOT66.08-06iincluderROOTTTSystem.h"'; specified path
      differs in case from file name on disk [-Wnonportable-include-path]
#include "/usr/local/ROOT/6.08-06/include/root/TSystem.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         "/uusrllocalRROOT66.08-06iincluderROOTTTSystem.h"
In file included from input_line_8:1:
In file included from /Users/kelsey/Desktop/trial.cxx:6:
/usr/include/sys/stat.h:373:58: error: expected function body after function
      declarator
int     futimens(int __fd, const struct timespec __times[2]) __API_AVAIL...
                                                             ^
/usr/include/sys/stat.h:375:15: error: expected function body after function
      declarator
                int __flag) __API_AVAILABLE(macosx(10.13), ios(11.0), tv...
                            ^
status = 0
(int) 0

Notice, though, that at the end the same complaints from sys/stat.h. I think this must be a Mac thing. Since it doesn’t appear to cause the command to fail, I’m not going to worry too much.

Please try with 6.12 - this problem was fixed some time after 6.08!
Axel.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.