Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7712357
libewf_date_time.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
3 KB
Referenced Files
None
Subscribers
None
libewf_date_time.c
View Options
/*
* Date and time functions
*
* Copyright (c) 2006-2009, Joachim Metz <forensics@hoffmannbv.nl>,
* Hoffmann Investigations. All rights reserved.
*
* Refer to AUTHORS for acknowledgements.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <narrow_string.h>
#include <memory.h>
#include <wide_string.h>
#include <types.h>
#include <liberror.h>
#if defined( TIME_WITH_SYS_TIME )
#include <sys/time.h>
#include <time.h>
#elif defined( HAVE_SYS_TIME_H )
#include <sys/time.h>
#else
#include <time.h>
#endif
#include "libewf_date_time.h"
/* Returns a structured representation of a time using the local time zone, or NULL on error
*/
struct tm *libewf_date_time_localtime(
const time_t *timestamp,
liberror_error_t **error )
{
#if !defined( HAVE_LOCALTIME_R ) && defined( HAVE_LOCALTIME )
struct tm *static_time_elements = NULL;
#endif
struct tm *time_elements = NULL;
static char *function = "libewf_date_time_localtime";
if( timestamp == NULL )
{
liberror_error_set(
error,
LIBERROR_ERROR_DOMAIN_ARGUMENTS,
LIBERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid time stamp.",
function );
return( NULL );
}
time_elements = (struct tm *) memory_allocate(
sizeof( struct tm ) );
if( time_elements == NULL )
{
liberror_error_set(
error,
LIBERROR_ERROR_DOMAIN_MEMORY,
LIBERROR_MEMORY_ERROR_INSUFFICIENT,
"%s: unable to create time elements.",
function );
return( NULL );
}
#if defined( HAVE_LOCALTIME_R )
#if defined( WINAPI )
if( localtime_s(
time_elements,
timestamp ) != 0 )
#else
if( localtime_r(
timestamp,
time_elements ) == NULL )
#endif
{
liberror_error_set(
error,
LIBERROR_ERROR_DOMAIN_RUNTIME,
LIBERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set time elements.",
function );
memory_free(
time_elements );
return( NULL );
}
#elif defined( HAVE_LOCALTIME )
static_time_elements = localtime(
timestamp );
if( static_time_elements == NULL )
{
liberror_error_set(
error,
LIBERROR_ERROR_DOMAIN_RUNTIME,
LIBERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create static time elements.",
function );
memory_free(
time_elements );
return( NULL );
}
if( memory_copy(
time_elements,
static_time_elements,
sizeof( struct tm ) ) == NULL )
{
liberror_error_set(
error,
LIBERROR_ERROR_DOMAIN_MEMORY,
LIBERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to set time elements.",
function );
memory_free(
time_elements );
return( NULL );
}
#endif
return( time_elements );
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Nov 21, 3:16 AM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1360801
Default Alt Text
libewf_date_time.c (3 KB)
Attached To
Mode
rXMOUNT xmount
Attached
Detach File
Event Timeline
Log In to Comment