| 1 |
greg |
2.1 |
#ifndef lint
|
| 2 |
greg |
2.11 |
static const char RCSid[] = "$Id: fdate.c,v 2.10 2019/02/27 21:30:01 greg Exp $";
|
| 3 |
greg |
2.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* Return file date (UNIX seconds as returned by time(2) call)
|
| 6 |
greg |
2.5 |
*
|
| 7 |
greg |
2.8 |
* External symbols declared in rtio.h
|
| 8 |
greg |
2.5 |
*/
|
| 9 |
|
|
|
| 10 |
greg |
2.6 |
#include "copyright.h"
|
| 11 |
greg |
2.1 |
|
| 12 |
greg |
2.8 |
#include "rtio.h"
|
| 13 |
greg |
2.1 |
#include <sys/stat.h>
|
| 14 |
schorsch |
2.9 |
#if defined(_WIN32) || defined(_WIN64)
|
| 15 |
greg |
2.10 |
#include <sys/utime.h>
|
| 16 |
schorsch |
2.7 |
#else
|
| 17 |
greg |
2.10 |
#include <utime.h>
|
| 18 |
schorsch |
2.7 |
#endif
|
| 19 |
greg |
2.1 |
|
| 20 |
|
|
|
| 21 |
greg |
2.3 |
time_t
|
| 22 |
greg |
2.10 |
fdate( /* get file date */
|
| 23 |
greg |
2.11 |
const char *fname
|
| 24 |
greg |
2.10 |
)
|
| 25 |
greg |
2.1 |
{
|
| 26 |
|
|
struct stat sbuf;
|
| 27 |
|
|
|
| 28 |
greg |
2.11 |
if (stat(fname, &sbuf) < 0)
|
| 29 |
greg |
2.2 |
return(0);
|
| 30 |
greg |
2.1 |
|
| 31 |
|
|
return(sbuf.st_mtime);
|
| 32 |
greg |
2.4 |
}
|
| 33 |
|
|
|
| 34 |
|
|
|
| 35 |
greg |
2.11 |
time_t
|
| 36 |
|
|
fddate( /* get file descriptor date */
|
| 37 |
|
|
int fd
|
| 38 |
|
|
)
|
| 39 |
|
|
{
|
| 40 |
|
|
struct stat sbuf;
|
| 41 |
|
|
|
| 42 |
|
|
if (fstat(fd, &sbuf) < 0)
|
| 43 |
|
|
return(0);
|
| 44 |
|
|
|
| 45 |
|
|
return(sbuf.st_mtime);
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
greg |
2.4 |
int
|
| 49 |
greg |
2.10 |
setfdate( /* set file date */
|
| 50 |
greg |
2.11 |
const char *fname,
|
| 51 |
|
|
long ftim
|
| 52 |
greg |
2.10 |
)
|
| 53 |
greg |
2.4 |
{
|
| 54 |
schorsch |
2.7 |
struct utimbuf utb;
|
| 55 |
|
|
|
| 56 |
|
|
utb.actime = utb.modtime = ftim;
|
| 57 |
greg |
2.10 |
|
| 58 |
schorsch |
2.7 |
return(utime(fname, &utb));
|
| 59 |
greg |
2.1 |
}
|