FreeBASIC  0.91.0
file_datetime.c
Go to the documentation of this file.
1 /* get file date/time by filename */
2 
3 #include "fb.h"
4 #include <time.h>
5 #include <sys/stat.h>
6 
7 FBCALL double fb_FileDateTime( const char *filename )
8 {
9 #ifdef HOST_MINGW
10  struct _stat buf;
11  if( _stat( filename, &buf ) != 0 )
12 #else
13  struct stat buf;
14  if( stat( filename, &buf ) != 0 )
15 #endif
16  return 0.0;
17 
18  struct tm *tm = localtime( &buf.st_mtime );
19  if( tm == NULL )
20  return 0.0;
21 
22  return fb_DateSerial( 1900 + tm->tm_year, 1+tm->tm_mon, tm->tm_mday ) +
23  fb_TimeSerial( tm->tm_hour, tm->tm_min, tm->tm_sec );
24 }