Skip to content

Commit

Permalink
Add configure checks for st_atim and st_atimespec
Browse files Browse the repository at this point in the history
Darwin uses st_atimespec
  • Loading branch information
nwellnhof committed Feb 16, 2011
1 parent 9f51ff2 commit 6de456e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ config/auto/snprintf.pm []
config/auto/snprintf/test_c.in []
config/auto/socklen_t.pm []
config/auto/stat.pm []
config/auto/stat/test_atim_c.in []
config/auto/stat/test_atimespec_c.in []
config/auto/stat/test_c.in []
config/auto/thread.pm []
config/auto/timespec.pm []
Expand Down
28 changes: 28 additions & 0 deletions config/auto/stat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ sub runstep {
$self->_handle_bsd_stat($conf, $bsd_stat);
$conf->cc_clean();

my $stat_atim = 0;

$conf->cc_gen('config/auto/stat/test_atim_c.in');
eval { $conf->cc_build(); };
if (!$@) {
my $output = eval { $conf->cc_run() };
if (!$@ && $output =~ /OK/) {
$stat_atim = 1;
}
}
$conf->cc_clean();

$conf->data->set( HAS_STAT_ATIM => $stat_atim );

my $stat_atimespec = 0;

$conf->cc_gen('config/auto/stat/test_atimespec_c.in');
eval { $conf->cc_build(); };
if (!$@) {
my $output = eval { $conf->cc_run() };
if (!$@ && $output =~ /OK/) {
$stat_atimespec = 1;
}
}
$conf->cc_clean();

$conf->data->set( HAS_STAT_ATIMESPEC => $stat_atimespec );

return 1;
}

Expand Down
31 changes: 31 additions & 0 deletions config/auto/stat/test_atim_c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (C) 2010, Parrot Foundation.

check if struct stat has st_atim, st_mtim and st_ctim

*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>

int
main()
{
struct stat st;
st.st_atim.tv_sec = 22;
st.st_atim.tv_nsec = 500;
st.st_mtim.tv_sec = 22;
st.st_mtim.tv_nsec = 500;
st.st_ctim.tv_sec = 22;
st.st_ctim.tv_nsec = 500;
printf("OK\n");
return EXIT_SUCCESS;
}

/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/
31 changes: 31 additions & 0 deletions config/auto/stat/test_atimespec_c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (C) 2010, Parrot Foundation.

check if struct stat has st_atimespec, st_mtimespec and st_ctimespec

*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>

int
main()
{
struct stat st;
st.st_atimespec.tv_sec = 22;
st.st_atimespec.tv_nsec = 500;
st.st_mtimespec.tv_sec = 22;
st.st_mtimespec.tv_nsec = 500;
st.st_ctimespec.tv_sec = 22;
st.st_ctimespec.tv_nsec = 500;
printf("OK\n");
return EXIT_SUCCESS;
}

/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/
15 changes: 15 additions & 0 deletions src/platform/generic/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,24 @@ convert_stat_buf(PARROT_INTERP, ARGIN(struct stat *stat_buf),
#endif

buf->create_time = zero;
#ifdef PARROT_HAS_STAT_ATIM
buf->access_time = stat_buf->st_atim;
buf->modify_time = stat_buf->st_mtim;
buf->change_time = stat_buf->st_ctim;
#else
# ifdef PARROT_HAS_STAT_ATIMESPEC
buf->access_time = stat_buf->st_atimespec;
buf->modify_time = stat_buf->st_mtimespec;
buf->change_time = stat_buf->st_ctimespec;
# else
buf->access_time.tv_sec = stat_buf->st_atime;
buf->access_time.tv_nsec = 0;
buf->modify_time.tv_sec = stat_buf->st_mtime;
buf->modify_time.tv_nsec = 0;
buf->change_time.tv_sec = stat_buf->st_ctime;
buf->change_time.tv_nsec = 0;
# endif
#endif
}

/*
Expand Down

0 comments on commit 6de456e

Please sign in to comment.