| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <common.h> |
| 23 |
|
| 24 |
#if defined( HAVE_SYS_TIME_H ) |
| 25 |
#include <sys/time.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <time.h> |
| 29 |
|
| 30 |
#include "libfcache_date_time.h" |
| 31 |
#include "libfcache_libcerror.h" |
| 32 |
#include "libfcache_types.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
int libfcache_date_time_get_timestamp( |
| 38 |
int64_t *timestamp, |
| 39 |
libcerror_error_t **error ) |
| 40 |
{ |
| 41 |
#if defined( HAVE_CLOCK_GETTIME ) |
| 42 |
struct timespec time_structure; |
| 43 |
#endif |
| 44 |
|
| 45 |
static char *function = "libfcache_date_time_get_timestamp"; |
| 46 |
|
| 47 |
if( timestamp == NULL ) |
| 48 |
{ |
| 49 |
libcerror_error_set( |
| 50 |
error, |
| 51 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 52 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 53 |
"%s: invalid timestamp.", |
| 54 |
function ); |
| 55 |
|
| 56 |
return( -1 ); |
| 57 |
} |
| 58 |
#if defined( HAVE_CLOCK_GETTIME ) |
| 59 |
if( clock_gettime( |
| 60 |
CLOCK_REALTIME, |
| 61 |
&time_structure ) != 0 ) |
| 62 |
{ |
| 63 |
libcerror_error_set( |
| 64 |
error, |
| 65 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 66 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 67 |
"%s: unable to retrieve current time structure.", |
| 68 |
function ); |
| 69 |
|
| 70 |
return( -1 ); |
| 71 |
} |
| 72 |
*timestamp = ( (int64_t) time_structure.tv_sec * 1000000000 ) + time_structure.tv_nsec; |
| 73 |
|
| 74 |
#else |
| 75 |
*timestamp = (int64_t) time( NULL ); |
| 76 |
|
| 77 |
if( *timestamp == (time_t) -1 ) |
| 78 |
{ |
| 79 |
libcerror_error_set( |
| 80 |
error, |
| 81 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 82 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 83 |
"%s: unable to retrieve current time.", |
| 84 |
function ); |
| 85 |
|
| 86 |
return( -1 ); |
| 87 |
} |
| 88 |
#endif |
| 89 |
|
| 90 |
return( 1 ); |
| 91 |
} |
| 92 |
|