/src/libmsiecf/libfdatetime/libfdatetime_posix_time.c
Line | Count | Source |
1 | | /* |
2 | | * POSIX time functions |
3 | | * |
4 | | * Copyright (C) 2009-2026, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libfdatetime_definitions.h" |
28 | | #include "libfdatetime_date_time_values.h" |
29 | | #include "libfdatetime_libcerror.h" |
30 | | #include "libfdatetime_posix_time.h" |
31 | | #include "libfdatetime_types.h" |
32 | | |
33 | | /* Creates a POSIX time |
34 | | * Make sure the value posix_time is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libfdatetime_posix_time_initialize( |
38 | | libfdatetime_posix_time_t **posix_time, |
39 | | libcerror_error_t **error ) |
40 | 0 | { |
41 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
42 | 0 | static char *function = "libfdatetime_posix_time_initialize"; |
43 | |
|
44 | 0 | if( posix_time == NULL ) |
45 | 0 | { |
46 | 0 | libcerror_error_set( |
47 | 0 | error, |
48 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
49 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
50 | 0 | "%s: invalid POSIX time.", |
51 | 0 | function ); |
52 | |
|
53 | 0 | return( -1 ); |
54 | 0 | } |
55 | 0 | if( *posix_time != NULL ) |
56 | 0 | { |
57 | 0 | libcerror_error_set( |
58 | 0 | error, |
59 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
60 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
61 | 0 | "%s: invalid POSIX time value already set.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 0 | internal_posix_time = memory_allocate_structure( |
67 | 0 | libfdatetime_internal_posix_time_t ); |
68 | |
|
69 | 0 | if( internal_posix_time == NULL ) |
70 | 0 | { |
71 | 0 | libcerror_error_set( |
72 | 0 | error, |
73 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
74 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
75 | 0 | "%s: unable to create POSIX time.", |
76 | 0 | function ); |
77 | |
|
78 | 0 | goto on_error; |
79 | 0 | } |
80 | 0 | if( memory_set( |
81 | 0 | internal_posix_time, |
82 | 0 | 0, |
83 | 0 | sizeof( libfdatetime_internal_posix_time_t ) ) == NULL ) |
84 | 0 | { |
85 | 0 | libcerror_error_set( |
86 | 0 | error, |
87 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
88 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
89 | 0 | "%s: unable to clear POSIX time.", |
90 | 0 | function ); |
91 | |
|
92 | 0 | goto on_error; |
93 | 0 | } |
94 | 0 | *posix_time = (libfdatetime_posix_time_t *) internal_posix_time; |
95 | |
|
96 | 0 | return( 1 ); |
97 | | |
98 | 0 | on_error: |
99 | 0 | if( internal_posix_time != NULL ) |
100 | 0 | { |
101 | 0 | memory_free( |
102 | 0 | internal_posix_time ); |
103 | 0 | } |
104 | 0 | return( -1 ); |
105 | 0 | } |
106 | | |
107 | | /* Frees a POSIX time |
108 | | * Returns 1 if successful or -1 on error |
109 | | */ |
110 | | int libfdatetime_posix_time_free( |
111 | | libfdatetime_posix_time_t **posix_time, |
112 | | libcerror_error_t **error ) |
113 | 0 | { |
114 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
115 | 0 | static char *function = "libfdatetime_posix_time_free"; |
116 | |
|
117 | 0 | if( posix_time == NULL ) |
118 | 0 | { |
119 | 0 | libcerror_error_set( |
120 | 0 | error, |
121 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
122 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
123 | 0 | "%s: invalid POSIX time.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | return( -1 ); |
127 | 0 | } |
128 | 0 | if( *posix_time != NULL ) |
129 | 0 | { |
130 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) *posix_time; |
131 | 0 | *posix_time = NULL; |
132 | |
|
133 | 0 | memory_free( |
134 | 0 | internal_posix_time ); |
135 | 0 | } |
136 | 0 | return( 1 ); |
137 | 0 | } |
138 | | |
139 | | /* Converts a byte stream into a POSIX time |
140 | | * Returns 1 if successful or -1 on error |
141 | | */ |
142 | | int libfdatetime_posix_time_copy_from_byte_stream( |
143 | | libfdatetime_posix_time_t *posix_time, |
144 | | const uint8_t *byte_stream, |
145 | | size_t byte_stream_size, |
146 | | int byte_order, |
147 | | uint8_t value_type, |
148 | | libcerror_error_t **error ) |
149 | 0 | { |
150 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
151 | 0 | static char *function = "libfdatetime_posix_time_copy_from_byte_stream"; |
152 | 0 | uint64_t value_64bit = 0; |
153 | 0 | uint8_t is_signed = 0; |
154 | |
|
155 | 0 | if( posix_time == NULL ) |
156 | 0 | { |
157 | 0 | libcerror_error_set( |
158 | 0 | error, |
159 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
160 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
161 | 0 | "%s: invalid POSIX time.", |
162 | 0 | function ); |
163 | |
|
164 | 0 | return( -1 ); |
165 | 0 | } |
166 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
167 | |
|
168 | 0 | if( byte_stream == NULL ) |
169 | 0 | { |
170 | 0 | libcerror_error_set( |
171 | 0 | error, |
172 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
173 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
174 | 0 | "%s: invalid byte stream.", |
175 | 0 | function ); |
176 | |
|
177 | 0 | return( -1 ); |
178 | 0 | } |
179 | 0 | if( byte_stream_size > (size_t) SSIZE_MAX ) |
180 | 0 | { |
181 | 0 | libcerror_error_set( |
182 | 0 | error, |
183 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
184 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
185 | 0 | "%s: byte stream size exceeds maximum.", |
186 | 0 | function ); |
187 | |
|
188 | 0 | return( -1 ); |
189 | 0 | } |
190 | 0 | if( ( byte_order != LIBFDATETIME_ENDIAN_BIG ) |
191 | 0 | && ( byte_order != LIBFDATETIME_ENDIAN_LITTLE ) ) |
192 | 0 | { |
193 | 0 | libcerror_error_set( |
194 | 0 | error, |
195 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
196 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
197 | 0 | "%s: unsupported byte order.", |
198 | 0 | function ); |
199 | |
|
200 | 0 | return( -1 ); |
201 | 0 | } |
202 | 0 | if( ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
203 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
204 | 0 | { |
205 | 0 | if( byte_stream_size < 4 ) |
206 | 0 | { |
207 | 0 | libcerror_error_set( |
208 | 0 | error, |
209 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
210 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
211 | 0 | "%s: byte stream too small.", |
212 | 0 | function ); |
213 | |
|
214 | 0 | return( -1 ); |
215 | 0 | } |
216 | 0 | if( byte_order == LIBFDATETIME_ENDIAN_LITTLE ) |
217 | 0 | { |
218 | 0 | byte_stream_copy_to_uint32_little_endian( |
219 | 0 | byte_stream, |
220 | 0 | value_64bit ); |
221 | 0 | } |
222 | 0 | else if( byte_order == LIBFDATETIME_ENDIAN_BIG ) |
223 | 0 | { |
224 | 0 | byte_stream_copy_to_uint32_big_endian( |
225 | 0 | byte_stream, |
226 | 0 | value_64bit ); |
227 | 0 | } |
228 | 0 | is_signed = (uint8_t) ( value_64bit >> 31 ); |
229 | |
|
230 | 0 | if( ( is_signed != 0 ) |
231 | 0 | && ( ( value_64bit & 0x7fffffffUL ) == 0 ) ) |
232 | 0 | { |
233 | 0 | libcerror_error_set( |
234 | 0 | error, |
235 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
236 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
237 | 0 | "%s: unsupported timestamp.", |
238 | 0 | function ); |
239 | |
|
240 | 0 | return( -1 ); |
241 | 0 | } |
242 | 0 | } |
243 | 0 | else if( ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
244 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
245 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
246 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
247 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
248 | 0 | || ( value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
249 | 0 | { |
250 | 0 | if( byte_stream_size < 8 ) |
251 | 0 | { |
252 | 0 | libcerror_error_set( |
253 | 0 | error, |
254 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
255 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
256 | 0 | "%s: byte stream too small.", |
257 | 0 | function ); |
258 | |
|
259 | 0 | return( -1 ); |
260 | 0 | } |
261 | 0 | if( byte_order == LIBFDATETIME_ENDIAN_LITTLE ) |
262 | 0 | { |
263 | 0 | byte_stream_copy_to_uint64_little_endian( |
264 | 0 | byte_stream, |
265 | 0 | value_64bit ); |
266 | 0 | } |
267 | 0 | else if( byte_order == LIBFDATETIME_ENDIAN_BIG ) |
268 | 0 | { |
269 | 0 | byte_stream_copy_to_uint64_big_endian( |
270 | 0 | byte_stream, |
271 | 0 | value_64bit ); |
272 | 0 | } |
273 | 0 | is_signed = (uint8_t) ( value_64bit >> 63 ); |
274 | |
|
275 | | #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) |
276 | | if( ( is_signed != 0 ) |
277 | | && ( ( value_64bit & 0x7fffffffffffffffUL ) == 0 ) ) |
278 | | #else |
279 | 0 | if( ( is_signed != 0 ) |
280 | 0 | && ( ( value_64bit & 0x7fffffffffffffffULL ) == 0 ) ) |
281 | 0 | #endif |
282 | 0 | { |
283 | 0 | libcerror_error_set( |
284 | 0 | error, |
285 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
286 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
287 | 0 | "%s: unsupported timestamp.", |
288 | 0 | function ); |
289 | |
|
290 | 0 | return( -1 ); |
291 | 0 | } |
292 | 0 | } |
293 | 0 | else |
294 | 0 | { |
295 | 0 | libcerror_error_set( |
296 | 0 | error, |
297 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
298 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
299 | 0 | "%s: unsupported value type.", |
300 | 0 | function ); |
301 | |
|
302 | 0 | return( -1 ); |
303 | 0 | } |
304 | 0 | internal_posix_time->timestamp = value_64bit; |
305 | 0 | internal_posix_time->value_type = value_type; |
306 | |
|
307 | 0 | return( 1 ); |
308 | 0 | } |
309 | | |
310 | | /* Converts a 32-bit value into a POSIX time |
311 | | * Returns 1 if successful or -1 on error |
312 | | */ |
313 | | int libfdatetime_posix_time_copy_from_32bit( |
314 | | libfdatetime_posix_time_t *posix_time, |
315 | | uint32_t value_32bit, |
316 | | uint8_t value_type, |
317 | | libcerror_error_t **error ) |
318 | 0 | { |
319 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
320 | 0 | static char *function = "libfdatetime_posix_time_copy_from_32bit"; |
321 | 0 | uint8_t is_signed = 0; |
322 | |
|
323 | 0 | if( posix_time == NULL ) |
324 | 0 | { |
325 | 0 | libcerror_error_set( |
326 | 0 | error, |
327 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
328 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
329 | 0 | "%s: invalid POSIX time.", |
330 | 0 | function ); |
331 | |
|
332 | 0 | return( -1 ); |
333 | 0 | } |
334 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
335 | |
|
336 | 0 | if( ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
337 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
338 | 0 | { |
339 | 0 | libcerror_error_set( |
340 | 0 | error, |
341 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
342 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
343 | 0 | "%s: unsupported value type.", |
344 | 0 | function ); |
345 | |
|
346 | 0 | return( -1 ); |
347 | 0 | } |
348 | 0 | is_signed = (uint8_t) ( value_32bit >> 31 ); |
349 | |
|
350 | 0 | if( ( is_signed != 0 ) |
351 | 0 | && ( ( value_32bit & 0x7fffffffUL ) == 0 ) ) |
352 | 0 | { |
353 | 0 | libcerror_error_set( |
354 | 0 | error, |
355 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
356 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
357 | 0 | "%s: unsupported timestamp.", |
358 | 0 | function ); |
359 | |
|
360 | 0 | return( -1 ); |
361 | 0 | } |
362 | 0 | internal_posix_time->timestamp = (uint64_t) value_32bit; |
363 | 0 | internal_posix_time->value_type = value_type; |
364 | |
|
365 | 0 | return( 1 ); |
366 | 0 | } |
367 | | |
368 | | /* Converts a POSIX time into a 32-bit value |
369 | | * Returns 1 if successful or -1 on error |
370 | | */ |
371 | | int libfdatetime_posix_time_copy_to_32bit( |
372 | | libfdatetime_posix_time_t *posix_time, |
373 | | uint32_t *value_32bit, |
374 | | uint8_t *value_type, |
375 | | libcerror_error_t **error ) |
376 | 0 | { |
377 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
378 | 0 | static char *function = "libfdatetime_posix_time_copy_to_32bit"; |
379 | |
|
380 | 0 | if( posix_time == NULL ) |
381 | 0 | { |
382 | 0 | libcerror_error_set( |
383 | 0 | error, |
384 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
385 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
386 | 0 | "%s: invalid POSIX time.", |
387 | 0 | function ); |
388 | |
|
389 | 0 | return( -1 ); |
390 | 0 | } |
391 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
392 | |
|
393 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
394 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
395 | 0 | { |
396 | 0 | libcerror_error_set( |
397 | 0 | error, |
398 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
399 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
400 | 0 | "%s: invalid POSIX time - unsupported value type.", |
401 | 0 | function ); |
402 | |
|
403 | 0 | return( -1 ); |
404 | 0 | } |
405 | 0 | if( value_32bit == NULL ) |
406 | 0 | { |
407 | 0 | libcerror_error_set( |
408 | 0 | error, |
409 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
410 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
411 | 0 | "%s: invalid 32-bit value.", |
412 | 0 | function ); |
413 | |
|
414 | 0 | return( -1 ); |
415 | 0 | } |
416 | 0 | if( value_type == NULL ) |
417 | 0 | { |
418 | 0 | libcerror_error_set( |
419 | 0 | error, |
420 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
421 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
422 | 0 | "%s: invalid value type.", |
423 | 0 | function ); |
424 | |
|
425 | 0 | return( -1 ); |
426 | 0 | } |
427 | 0 | *value_32bit = (uint32_t) internal_posix_time->timestamp; |
428 | 0 | *value_type = internal_posix_time->value_type; |
429 | |
|
430 | 0 | return( 1 ); |
431 | 0 | } |
432 | | |
433 | | /* Converts a 64-bit value into a POSIX time |
434 | | * Returns 1 if successful or -1 on error |
435 | | */ |
436 | | int libfdatetime_posix_time_copy_from_64bit( |
437 | | libfdatetime_posix_time_t *posix_time, |
438 | | uint64_t value_64bit, |
439 | | uint8_t value_type, |
440 | | libcerror_error_t **error ) |
441 | 0 | { |
442 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
443 | 0 | static char *function = "libfdatetime_posix_time_copy_from_64bit"; |
444 | 0 | uint8_t is_signed = 0; |
445 | |
|
446 | 0 | if( posix_time == NULL ) |
447 | 0 | { |
448 | 0 | libcerror_error_set( |
449 | 0 | error, |
450 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
451 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
452 | 0 | "%s: invalid POSIX time.", |
453 | 0 | function ); |
454 | |
|
455 | 0 | return( -1 ); |
456 | 0 | } |
457 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
458 | |
|
459 | 0 | if( ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
460 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
461 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
462 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
463 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
464 | 0 | && ( value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
465 | 0 | { |
466 | 0 | libcerror_error_set( |
467 | 0 | error, |
468 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
469 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
470 | 0 | "%s: unsupported value type.", |
471 | 0 | function ); |
472 | |
|
473 | 0 | return( -1 ); |
474 | 0 | } |
475 | 0 | is_signed = (uint8_t) ( value_64bit >> 63 ); |
476 | |
|
477 | | #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) |
478 | | if( ( is_signed != 0 ) |
479 | | && ( ( value_64bit & 0x7fffffffffffffffUL ) == 0 ) ) |
480 | | #else |
481 | 0 | if( ( is_signed != 0 ) |
482 | 0 | && ( ( value_64bit & 0x7fffffffffffffffULL ) == 0 ) ) |
483 | 0 | #endif |
484 | 0 | { |
485 | 0 | libcerror_error_set( |
486 | 0 | error, |
487 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
488 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
489 | 0 | "%s: unsupported timestamp.", |
490 | 0 | function ); |
491 | |
|
492 | 0 | return( -1 ); |
493 | 0 | } |
494 | 0 | internal_posix_time->timestamp = value_64bit; |
495 | 0 | internal_posix_time->value_type = value_type; |
496 | |
|
497 | 0 | return( 1 ); |
498 | 0 | } |
499 | | |
500 | | /* Converts a POSIX time into a 64-bit value |
501 | | * Returns 1 if successful or -1 on error |
502 | | */ |
503 | | int libfdatetime_posix_time_copy_to_64bit( |
504 | | libfdatetime_posix_time_t *posix_time, |
505 | | uint64_t *value_64bit, |
506 | | uint8_t *value_type, |
507 | | libcerror_error_t **error ) |
508 | 0 | { |
509 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
510 | 0 | static char *function = "libfdatetime_posix_time_copy_to_64bit"; |
511 | |
|
512 | 0 | if( posix_time == NULL ) |
513 | 0 | { |
514 | 0 | libcerror_error_set( |
515 | 0 | error, |
516 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
517 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
518 | 0 | "%s: invalid POSIX time.", |
519 | 0 | function ); |
520 | |
|
521 | 0 | return( -1 ); |
522 | 0 | } |
523 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
524 | |
|
525 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
526 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
527 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
528 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
529 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
530 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
531 | 0 | { |
532 | 0 | libcerror_error_set( |
533 | 0 | error, |
534 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
535 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
536 | 0 | "%s: invalid POSIX time - unsupported value type.", |
537 | 0 | function ); |
538 | |
|
539 | 0 | return( -1 ); |
540 | 0 | } |
541 | 0 | if( value_64bit == NULL ) |
542 | 0 | { |
543 | 0 | libcerror_error_set( |
544 | 0 | error, |
545 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
546 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
547 | 0 | "%s: invalid 64-bit value.", |
548 | 0 | function ); |
549 | |
|
550 | 0 | return( -1 ); |
551 | 0 | } |
552 | 0 | if( value_type == NULL ) |
553 | 0 | { |
554 | 0 | libcerror_error_set( |
555 | 0 | error, |
556 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
557 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
558 | 0 | "%s: invalid value type.", |
559 | 0 | function ); |
560 | |
|
561 | 0 | return( -1 ); |
562 | 0 | } |
563 | 0 | *value_64bit = internal_posix_time->timestamp; |
564 | 0 | *value_type = internal_posix_time->value_type; |
565 | |
|
566 | 0 | return( 1 ); |
567 | 0 | } |
568 | | |
569 | | /* Converts a POSIX time into date time values |
570 | | * Returns 1 if successful or -1 on error |
571 | | */ |
572 | | int libfdatetime_internal_posix_time_copy_to_date_time_values( |
573 | | libfdatetime_internal_posix_time_t *internal_posix_time, |
574 | | libfdatetime_date_time_values_t *date_time_values, |
575 | | libcerror_error_t **error ) |
576 | 0 | { |
577 | 0 | static char *function = "libfdatetime_internal_posix_time_copy_to_date_time_values"; |
578 | 0 | uint64_t posix_timestamp = 0; |
579 | 0 | uint64_t remaining_years = 0; |
580 | 0 | uint32_t days_in_century = 0; |
581 | 0 | uint16_t days_in_year = 0; |
582 | 0 | uint8_t days_in_month = 0; |
583 | 0 | uint8_t is_signed = 0; |
584 | |
|
585 | 0 | if( internal_posix_time == NULL ) |
586 | 0 | { |
587 | 0 | libcerror_error_set( |
588 | 0 | error, |
589 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
590 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
591 | 0 | "%s: invalid POSIX time.", |
592 | 0 | function ); |
593 | |
|
594 | 0 | return( -1 ); |
595 | 0 | } |
596 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
597 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) |
598 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
599 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
600 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
601 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
602 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
603 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
604 | 0 | { |
605 | 0 | libcerror_error_set( |
606 | 0 | error, |
607 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
608 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
609 | 0 | "%s: invalid POSIX time - unsupported value type.", |
610 | 0 | function ); |
611 | |
|
612 | 0 | return( -1 ); |
613 | 0 | } |
614 | 0 | if( date_time_values == NULL ) |
615 | 0 | { |
616 | 0 | libcerror_error_set( |
617 | 0 | error, |
618 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
619 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
620 | 0 | "%s: invalid date time values.", |
621 | 0 | function ); |
622 | |
|
623 | 0 | return( -1 ); |
624 | 0 | } |
625 | 0 | posix_timestamp = internal_posix_time->timestamp; |
626 | |
|
627 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
628 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
629 | 0 | { |
630 | 0 | is_signed = (uint8_t) ( posix_timestamp >> 31 ); |
631 | |
|
632 | 0 | if( is_signed != 0 ) |
633 | 0 | { |
634 | 0 | if( ( posix_timestamp & 0x7fffffffUL ) == 0 ) |
635 | 0 | { |
636 | 0 | libcerror_error_set( |
637 | 0 | error, |
638 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
639 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
640 | 0 | "%s: unsupported timestamp.", |
641 | 0 | function ); |
642 | |
|
643 | 0 | return( -1 ); |
644 | 0 | } |
645 | 0 | posix_timestamp = -( (int32_t) posix_timestamp ); |
646 | 0 | } |
647 | 0 | } |
648 | 0 | else if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
649 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
650 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
651 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
652 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
653 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
654 | 0 | { |
655 | 0 | is_signed = (uint8_t) ( posix_timestamp >> 63 ); |
656 | |
|
657 | 0 | if( is_signed != 0 ) |
658 | 0 | { |
659 | | #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) |
660 | | if( ( posix_timestamp & 0x7fffffffffffffffUL ) == 0 ) |
661 | | #else |
662 | 0 | if( ( posix_timestamp & 0x7fffffffffffffffULL ) == 0 ) |
663 | 0 | #endif |
664 | 0 | { |
665 | 0 | libcerror_error_set( |
666 | 0 | error, |
667 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
668 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
669 | 0 | "%s: unsupported timestamp.", |
670 | 0 | function ); |
671 | |
|
672 | 0 | return( -1 ); |
673 | 0 | } |
674 | 0 | posix_timestamp = -( (int64_t) posix_timestamp ); |
675 | 0 | } |
676 | 0 | } |
677 | 0 | date_time_values->nano_seconds = 0; |
678 | |
|
679 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
680 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
681 | 0 | { |
682 | | /* The timestamp is in units of nano seconds correct the value to seconds |
683 | | */ |
684 | 0 | date_time_values->nano_seconds = posix_timestamp % 1000; |
685 | 0 | posix_timestamp /= 1000; |
686 | |
|
687 | 0 | if( ( is_signed != 0 ) |
688 | 0 | && ( date_time_values->nano_seconds > 0 ) ) |
689 | 0 | { |
690 | 0 | date_time_values->nano_seconds = 999 - date_time_values->nano_seconds; |
691 | 0 | } |
692 | 0 | } |
693 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
694 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
695 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
696 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
697 | 0 | { |
698 | | /* The timestamp is in units of micro seconds correct the value to seconds |
699 | | */ |
700 | 0 | date_time_values->micro_seconds = posix_timestamp % 1000; |
701 | 0 | posix_timestamp /= 1000; |
702 | |
|
703 | 0 | if( ( is_signed != 0 ) |
704 | 0 | && ( date_time_values->micro_seconds > 0 ) ) |
705 | 0 | { |
706 | 0 | date_time_values->micro_seconds = 999 - date_time_values->micro_seconds; |
707 | 0 | } |
708 | 0 | date_time_values->milli_seconds = posix_timestamp % 1000; |
709 | 0 | posix_timestamp /= 1000; |
710 | |
|
711 | 0 | if( ( is_signed != 0 ) |
712 | 0 | && ( date_time_values->milli_seconds > 0 ) ) |
713 | 0 | { |
714 | 0 | date_time_values->milli_seconds = 999 - date_time_values->milli_seconds; |
715 | 0 | } |
716 | 0 | } |
717 | 0 | else |
718 | 0 | { |
719 | 0 | date_time_values->micro_seconds = 0; |
720 | 0 | date_time_values->milli_seconds = 0; |
721 | 0 | } |
722 | 0 | if( is_signed != 0 ) |
723 | 0 | { |
724 | 0 | posix_timestamp -= 1; |
725 | 0 | } |
726 | | /* There are 60 seconds in a minute correct the value to minutes |
727 | | */ |
728 | 0 | date_time_values->seconds = posix_timestamp % 60; |
729 | 0 | posix_timestamp /= 60; |
730 | |
|
731 | 0 | if( ( is_signed != 0 ) |
732 | 0 | && ( date_time_values->seconds > 0 ) ) |
733 | 0 | { |
734 | 0 | date_time_values->seconds = 59 - date_time_values->seconds; |
735 | 0 | } |
736 | | /* There are 60 minutes in an hour correct the value to hours |
737 | | */ |
738 | 0 | date_time_values->minutes = posix_timestamp % 60; |
739 | 0 | posix_timestamp /= 60; |
740 | |
|
741 | 0 | if( ( is_signed != 0 ) |
742 | 0 | && ( date_time_values->minutes > 0 ) ) |
743 | 0 | { |
744 | 0 | date_time_values->minutes = 59 - date_time_values->minutes; |
745 | 0 | } |
746 | | /* There are 24 hours in a day correct the value to days |
747 | | */ |
748 | 0 | date_time_values->hours = posix_timestamp % 24; |
749 | 0 | posix_timestamp /= 24; |
750 | |
|
751 | 0 | if( ( is_signed != 0 ) |
752 | 0 | && ( date_time_values->hours > 0 ) ) |
753 | 0 | { |
754 | 0 | date_time_values->hours = 23 - date_time_values->hours; |
755 | 0 | } |
756 | | /* Determine the number of years starting at 'Jan 1, 1970 00:00:00' |
757 | | * correct the value to days within the year |
758 | | */ |
759 | 0 | if( is_signed == 0 ) |
760 | 0 | { |
761 | | /* Add 1 day to compensate that Jan 1, 1970 is represented as 0 |
762 | | */ |
763 | 0 | posix_timestamp += 1; |
764 | |
|
765 | 0 | if( posix_timestamp >= 10957 ) |
766 | 0 | { |
767 | 0 | date_time_values->year = 2000; |
768 | |
|
769 | 0 | posix_timestamp -= 10957; |
770 | 0 | } |
771 | 0 | else |
772 | 0 | { |
773 | 0 | date_time_values->year = 1970; |
774 | 0 | } |
775 | 0 | } |
776 | 0 | else |
777 | 0 | { |
778 | 0 | date_time_values->year = 1969; |
779 | 0 | } |
780 | 0 | remaining_years = posix_timestamp % 100; |
781 | |
|
782 | 0 | while( remaining_years > 0 ) |
783 | 0 | { |
784 | | /* Check for a leap year |
785 | | * The year is ( ( dividable by 4 ) and ( not dividable by 100 ) ) or ( dividable by 400 ) |
786 | | */ |
787 | 0 | if( ( ( ( date_time_values->year % 4 ) == 0 ) |
788 | 0 | && ( ( date_time_values->year % 100 ) != 0 ) ) |
789 | 0 | || ( ( date_time_values->year % 400 ) == 0 ) ) |
790 | 0 | { |
791 | 0 | days_in_year = 366; |
792 | 0 | } |
793 | 0 | else |
794 | 0 | { |
795 | 0 | days_in_year = 365; |
796 | 0 | } |
797 | 0 | if( posix_timestamp <= days_in_year ) |
798 | 0 | { |
799 | 0 | break; |
800 | 0 | } |
801 | 0 | posix_timestamp -= days_in_year; |
802 | |
|
803 | 0 | if( is_signed == 0 ) |
804 | 0 | { |
805 | 0 | date_time_values->year += 1; |
806 | 0 | } |
807 | 0 | else |
808 | 0 | { |
809 | 0 | date_time_values->year -= 1; |
810 | 0 | } |
811 | 0 | remaining_years -= 1; |
812 | 0 | } |
813 | 0 | while( posix_timestamp > 0 ) |
814 | 0 | { |
815 | | /* Check for a leap year |
816 | | * The year is ( ( dividable by 4 ) and ( not dividable by 100 ) ) or ( dividable by 400 ) |
817 | | */ |
818 | 0 | if( ( ( ( date_time_values->year % 4 ) == 0 ) |
819 | 0 | && ( ( date_time_values->year % 100 ) != 0 ) ) |
820 | 0 | || ( ( date_time_values->year % 400 ) == 0 ) ) |
821 | 0 | { |
822 | 0 | days_in_century = 36525; |
823 | 0 | } |
824 | 0 | else |
825 | 0 | { |
826 | 0 | days_in_century = 36524; |
827 | 0 | } |
828 | 0 | if( posix_timestamp <= days_in_century ) |
829 | 0 | { |
830 | 0 | break; |
831 | 0 | } |
832 | 0 | posix_timestamp -= days_in_century; |
833 | |
|
834 | 0 | if( is_signed == 0 ) |
835 | 0 | { |
836 | 0 | date_time_values->year += 100; |
837 | 0 | } |
838 | 0 | else |
839 | 0 | { |
840 | 0 | date_time_values->year -= 100; |
841 | 0 | } |
842 | 0 | } |
843 | 0 | while( posix_timestamp > 0 ) |
844 | 0 | { |
845 | | /* Check for a leap year |
846 | | * The year is ( ( dividable by 4 ) and ( not dividable by 100 ) ) or ( dividable by 400 ) |
847 | | */ |
848 | 0 | if( ( ( ( date_time_values->year % 4 ) == 0 ) |
849 | 0 | && ( ( date_time_values->year % 100 ) != 0 ) ) |
850 | 0 | || ( ( date_time_values->year % 400 ) == 0 ) ) |
851 | 0 | { |
852 | 0 | days_in_year = 366; |
853 | 0 | } |
854 | 0 | else |
855 | 0 | { |
856 | 0 | days_in_year = 365; |
857 | 0 | } |
858 | 0 | if( posix_timestamp <= days_in_year ) |
859 | 0 | { |
860 | 0 | break; |
861 | 0 | } |
862 | 0 | posix_timestamp -= days_in_year; |
863 | |
|
864 | 0 | if( is_signed == 0 ) |
865 | 0 | { |
866 | 0 | date_time_values->year += 1; |
867 | 0 | } |
868 | 0 | else |
869 | 0 | { |
870 | 0 | date_time_values->year -= 1; |
871 | 0 | } |
872 | 0 | } |
873 | | /* Determine the month correct the value to days within the month |
874 | | */ |
875 | 0 | if( is_signed == 0 ) |
876 | 0 | { |
877 | 0 | date_time_values->month = 1; |
878 | 0 | } |
879 | 0 | else |
880 | 0 | { |
881 | 0 | date_time_values->month = 12; |
882 | 0 | } |
883 | 0 | do |
884 | 0 | { |
885 | | /* February (2) |
886 | | */ |
887 | 0 | if( date_time_values->month == 2 ) |
888 | 0 | { |
889 | 0 | if( ( ( ( date_time_values->year % 4 ) == 0 ) |
890 | 0 | && ( ( date_time_values->year % 100 ) != 0 ) ) |
891 | 0 | || ( ( date_time_values->year % 400 ) == 0 ) ) |
892 | 0 | { |
893 | 0 | days_in_month = 29; |
894 | 0 | } |
895 | 0 | else |
896 | 0 | { |
897 | 0 | days_in_month = 28; |
898 | 0 | } |
899 | 0 | } |
900 | | /* April (4), June (6), September (9), November (11) |
901 | | */ |
902 | 0 | else if( ( date_time_values->month == 4 ) |
903 | 0 | || ( date_time_values->month == 6 ) |
904 | 0 | || ( date_time_values->month == 9 ) |
905 | 0 | || ( date_time_values->month == 11 ) ) |
906 | 0 | { |
907 | 0 | days_in_month = 30; |
908 | 0 | } |
909 | | /* January (1), March (3), May (5), July (7), August (8), October (10), December (12) |
910 | | */ |
911 | 0 | else if( ( date_time_values->month == 1 ) |
912 | 0 | || ( date_time_values->month == 3 ) |
913 | 0 | || ( date_time_values->month == 5 ) |
914 | 0 | || ( date_time_values->month == 7 ) |
915 | 0 | || ( date_time_values->month == 8 ) |
916 | 0 | || ( date_time_values->month == 10 ) |
917 | 0 | || ( date_time_values->month == 12 ) ) |
918 | 0 | { |
919 | 0 | days_in_month = 31; |
920 | 0 | } |
921 | | /* This should never happen, but just in case |
922 | | */ |
923 | 0 | else |
924 | 0 | { |
925 | 0 | libcerror_error_set( |
926 | 0 | error, |
927 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
928 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
929 | 0 | "%s: unsupported month: %d.", |
930 | 0 | function, |
931 | 0 | date_time_values->month ); |
932 | |
|
933 | 0 | return( -1 ); |
934 | 0 | } |
935 | 0 | if( posix_timestamp <= days_in_month ) |
936 | 0 | { |
937 | 0 | break; |
938 | 0 | } |
939 | 0 | posix_timestamp -= days_in_month; |
940 | |
|
941 | 0 | if( is_signed == 0 ) |
942 | 0 | { |
943 | 0 | date_time_values->month += 1; |
944 | 0 | } |
945 | 0 | else |
946 | 0 | { |
947 | 0 | date_time_values->month -= 1; |
948 | 0 | } |
949 | 0 | } |
950 | 0 | while( posix_timestamp > 0 ); |
951 | | |
952 | | /* Determine the day |
953 | | */ |
954 | 0 | date_time_values->day = (uint8_t) posix_timestamp; |
955 | |
|
956 | 0 | if( is_signed != 0 ) |
957 | 0 | { |
958 | 0 | date_time_values->day = days_in_month - date_time_values->day; |
959 | 0 | } |
960 | 0 | return( 1 ); |
961 | 0 | } |
962 | | |
963 | | /* Deterimes the size of the string for the POSIX time |
964 | | * The string size includes the end of string character |
965 | | * Returns 1 if successful or -1 on error |
966 | | */ |
967 | | int libfdatetime_posix_time_get_string_size( |
968 | | libfdatetime_posix_time_t *posix_time, |
969 | | size_t *string_size, |
970 | | uint32_t string_format_flags, |
971 | | libcerror_error_t **error ) |
972 | 0 | { |
973 | 0 | libfdatetime_date_time_values_t date_time_values; |
974 | |
|
975 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
976 | 0 | static char *function = "libfdatetime_posix_time_get_string_size"; |
977 | 0 | int result = 0; |
978 | |
|
979 | 0 | if( posix_time == NULL ) |
980 | 0 | { |
981 | 0 | libcerror_error_set( |
982 | 0 | error, |
983 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
984 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
985 | 0 | "%s: invalid POSIX time.", |
986 | 0 | function ); |
987 | |
|
988 | 0 | return( -1 ); |
989 | 0 | } |
990 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
991 | |
|
992 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
993 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) |
994 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
995 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
996 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
997 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
998 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
999 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
1000 | 0 | { |
1001 | 0 | libcerror_error_set( |
1002 | 0 | error, |
1003 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1004 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1005 | 0 | "%s: invalid POSIX time - unsupported value type.", |
1006 | 0 | function ); |
1007 | |
|
1008 | 0 | return( -1 ); |
1009 | 0 | } |
1010 | 0 | if( string_size == NULL ) |
1011 | 0 | { |
1012 | 0 | libcerror_error_set( |
1013 | 0 | error, |
1014 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1015 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1016 | 0 | "%s: invalid string size.", |
1017 | 0 | function ); |
1018 | |
|
1019 | 0 | return( -1 ); |
1020 | 0 | } |
1021 | 0 | result = libfdatetime_internal_posix_time_copy_to_date_time_values( |
1022 | 0 | (libfdatetime_internal_posix_time_t *) posix_time, |
1023 | 0 | &date_time_values, |
1024 | 0 | error ); |
1025 | |
|
1026 | 0 | if( result != 1 ) |
1027 | 0 | { |
1028 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1029 | | libcerror_error_set( |
1030 | | error, |
1031 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1032 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1033 | | "%s: unable to set date time values.", |
1034 | | function ); |
1035 | | |
1036 | | /* TODO debug print error */ |
1037 | | |
1038 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1039 | |
|
1040 | 0 | if( ( error != NULL ) |
1041 | 0 | && ( *error != NULL ) ) |
1042 | 0 | { |
1043 | 0 | libcerror_error_free( |
1044 | 0 | error ); |
1045 | 0 | } |
1046 | 0 | } |
1047 | 0 | else |
1048 | 0 | { |
1049 | 0 | result = libfdatetime_date_time_values_get_string_size( |
1050 | 0 | &date_time_values, |
1051 | 0 | string_size, |
1052 | 0 | string_format_flags, |
1053 | 0 | error ); |
1054 | |
|
1055 | 0 | if( result == -1 ) |
1056 | 0 | { |
1057 | 0 | libcerror_error_set( |
1058 | 0 | error, |
1059 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1060 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1061 | 0 | "%s: unable to get string size.", |
1062 | 0 | function ); |
1063 | |
|
1064 | 0 | return( -1 ); |
1065 | 0 | } |
1066 | 0 | } |
1067 | 0 | if( result != 1 ) |
1068 | 0 | { |
1069 | | /* Make sure the string can hold the hexadecimal representation of the POSIX time |
1070 | | */ |
1071 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1072 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
1073 | 0 | { |
1074 | 0 | *string_size = 13; |
1075 | 0 | } |
1076 | 0 | else |
1077 | 0 | { |
1078 | 0 | *string_size = 21; |
1079 | 0 | } |
1080 | 0 | } |
1081 | 0 | return( 1 ); |
1082 | 0 | } |
1083 | | |
1084 | | /* Converts the POSIX time into an UTF-8 string in hexadecimal representation |
1085 | | * The string size should include the end of string character |
1086 | | * Returns 1 if successful or -1 on error |
1087 | | */ |
1088 | | int libfdatetime_internal_posix_time_copy_to_utf8_string_in_hexadecimal( |
1089 | | libfdatetime_internal_posix_time_t *internal_posix_time, |
1090 | | uint8_t *utf8_string, |
1091 | | size_t utf8_string_size, |
1092 | | size_t *utf8_string_index, |
1093 | | libcerror_error_t **error ) |
1094 | 0 | { |
1095 | 0 | static char *function = "libfdatetime_internal_posix_time_copy_to_utf8_string_in_hexadecimal"; |
1096 | 0 | size_t string_index = 0; |
1097 | 0 | size_t string_size = 0; |
1098 | 0 | uint8_t byte_value = 0; |
1099 | 0 | int8_t byte_shift = 0; |
1100 | |
|
1101 | 0 | if( internal_posix_time == NULL ) |
1102 | 0 | { |
1103 | 0 | libcerror_error_set( |
1104 | 0 | error, |
1105 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1106 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1107 | 0 | "%s: invalid POSIX time.", |
1108 | 0 | function ); |
1109 | |
|
1110 | 0 | return( -1 ); |
1111 | 0 | } |
1112 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1113 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) |
1114 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
1115 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
1116 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
1117 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
1118 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
1119 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
1120 | 0 | { |
1121 | 0 | libcerror_error_set( |
1122 | 0 | error, |
1123 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1124 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1125 | 0 | "%s: invalid POSIX time - unsupported value type.", |
1126 | 0 | function ); |
1127 | |
|
1128 | 0 | return( -1 ); |
1129 | 0 | } |
1130 | 0 | if( utf8_string == NULL ) |
1131 | 0 | { |
1132 | 0 | libcerror_error_set( |
1133 | 0 | error, |
1134 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1135 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1136 | 0 | "%s: invalid UTF-8 string.", |
1137 | 0 | function ); |
1138 | |
|
1139 | 0 | return( -1 ); |
1140 | 0 | } |
1141 | 0 | if( utf8_string_size > (size_t) SSIZE_MAX ) |
1142 | 0 | { |
1143 | 0 | libcerror_error_set( |
1144 | 0 | error, |
1145 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1146 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1147 | 0 | "%s: invalid UTF-8 string size value exceeds maximum.", |
1148 | 0 | function ); |
1149 | |
|
1150 | 0 | return( -1 ); |
1151 | 0 | } |
1152 | 0 | if( utf8_string_index == NULL ) |
1153 | 0 | { |
1154 | 0 | libcerror_error_set( |
1155 | 0 | error, |
1156 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1157 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1158 | 0 | "%s: invalid UTF-8 string index.", |
1159 | 0 | function ); |
1160 | |
|
1161 | 0 | return( -1 ); |
1162 | 0 | } |
1163 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1164 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
1165 | 0 | { |
1166 | 0 | string_size = 13; |
1167 | 0 | byte_shift = 28; |
1168 | 0 | } |
1169 | 0 | else |
1170 | 0 | { |
1171 | 0 | string_size = 21; |
1172 | 0 | byte_shift = 60; |
1173 | 0 | } |
1174 | 0 | if( ( utf8_string_size < string_size ) |
1175 | 0 | || ( *utf8_string_index > ( utf8_string_size - string_size ) ) ) |
1176 | 0 | { |
1177 | 0 | libcerror_error_set( |
1178 | 0 | error, |
1179 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1180 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1181 | 0 | "%s: UTF-8 string is too small.", |
1182 | 0 | function ); |
1183 | |
|
1184 | 0 | return( -1 ); |
1185 | 0 | } |
1186 | 0 | string_index = *utf8_string_index; |
1187 | |
|
1188 | 0 | utf8_string[ string_index++ ] = (uint8_t) '('; |
1189 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
1190 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
1191 | |
|
1192 | 0 | do |
1193 | 0 | { |
1194 | 0 | byte_value = ( internal_posix_time->timestamp >> byte_shift ) & 0x0f; |
1195 | |
|
1196 | 0 | if( byte_value <= 9 ) |
1197 | 0 | { |
1198 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
1199 | 0 | } |
1200 | 0 | else |
1201 | 0 | { |
1202 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
1203 | 0 | } |
1204 | 0 | byte_shift -= 4; |
1205 | 0 | } |
1206 | 0 | while( byte_shift >= 0 ); |
1207 | |
|
1208 | 0 | utf8_string[ string_index++ ] = (uint8_t) ')'; |
1209 | |
|
1210 | 0 | utf8_string[ string_index++ ] = 0; |
1211 | |
|
1212 | 0 | *utf8_string_index = string_index; |
1213 | |
|
1214 | 0 | return( 1 ); |
1215 | 0 | } |
1216 | | |
1217 | | /* Converts the POSIX time into an UTF-8 string |
1218 | | * The string size should include the end of string character |
1219 | | * Returns 1 if successful or -1 on error |
1220 | | */ |
1221 | | int libfdatetime_posix_time_copy_to_utf8_string( |
1222 | | libfdatetime_posix_time_t *posix_time, |
1223 | | uint8_t *utf8_string, |
1224 | | size_t utf8_string_size, |
1225 | | uint32_t string_format_flags, |
1226 | | libcerror_error_t **error ) |
1227 | 0 | { |
1228 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf8_string"; |
1229 | 0 | size_t utf8_string_index = 0; |
1230 | |
|
1231 | 0 | if( libfdatetime_posix_time_copy_to_utf8_string_with_index( |
1232 | 0 | posix_time, |
1233 | 0 | utf8_string, |
1234 | 0 | utf8_string_size, |
1235 | 0 | &utf8_string_index, |
1236 | 0 | string_format_flags, |
1237 | 0 | error ) != 1 ) |
1238 | 0 | { |
1239 | 0 | libcerror_error_set( |
1240 | 0 | error, |
1241 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1242 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1243 | 0 | "%s: unable to copy POSIX time to UTF-8 string.", |
1244 | 0 | function ); |
1245 | |
|
1246 | 0 | return( -1 ); |
1247 | 0 | } |
1248 | 0 | return( 1 ); |
1249 | 0 | } |
1250 | | |
1251 | | /* Converts the POSIX time into an UTF-8 string |
1252 | | * The string size should include the end of string character |
1253 | | * Returns 1 if successful or -1 on error |
1254 | | */ |
1255 | | int libfdatetime_posix_time_copy_to_utf8_string_with_index( |
1256 | | libfdatetime_posix_time_t *posix_time, |
1257 | | uint8_t *utf8_string, |
1258 | | size_t utf8_string_size, |
1259 | | size_t *utf8_string_index, |
1260 | | uint32_t string_format_flags, |
1261 | | libcerror_error_t **error ) |
1262 | 0 | { |
1263 | 0 | libfdatetime_date_time_values_t date_time_values; |
1264 | |
|
1265 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
1266 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf8_string_with_index"; |
1267 | 0 | int result = 0; |
1268 | |
|
1269 | 0 | if( posix_time == NULL ) |
1270 | 0 | { |
1271 | 0 | libcerror_error_set( |
1272 | 0 | error, |
1273 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1274 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1275 | 0 | "%s: invalid POSIX time.", |
1276 | 0 | function ); |
1277 | |
|
1278 | 0 | return( -1 ); |
1279 | 0 | } |
1280 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
1281 | |
|
1282 | 0 | result = libfdatetime_internal_posix_time_copy_to_date_time_values( |
1283 | 0 | internal_posix_time, |
1284 | 0 | &date_time_values, |
1285 | 0 | error ); |
1286 | |
|
1287 | 0 | if( result != 1 ) |
1288 | 0 | { |
1289 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1290 | | libcerror_error_set( |
1291 | | error, |
1292 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1293 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1294 | | "%s: unable to set date time values.", |
1295 | | function ); |
1296 | | |
1297 | | /* TODO debug print error */ |
1298 | | |
1299 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1300 | |
|
1301 | 0 | if( ( error != NULL ) |
1302 | 0 | && ( *error != NULL ) ) |
1303 | 0 | { |
1304 | 0 | libcerror_error_free( |
1305 | 0 | error ); |
1306 | 0 | } |
1307 | 0 | } |
1308 | 0 | else |
1309 | 0 | { |
1310 | 0 | result = libfdatetime_date_time_values_copy_to_utf8_string_with_index( |
1311 | 0 | &date_time_values, |
1312 | 0 | utf8_string, |
1313 | 0 | utf8_string_size, |
1314 | 0 | utf8_string_index, |
1315 | 0 | string_format_flags, |
1316 | 0 | error ); |
1317 | |
|
1318 | 0 | if( result == -1 ) |
1319 | 0 | { |
1320 | 0 | libcerror_error_set( |
1321 | 0 | error, |
1322 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1323 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1324 | 0 | "%s: unable to copy date time values to UTF-8 string.", |
1325 | 0 | function ); |
1326 | |
|
1327 | 0 | return( -1 ); |
1328 | 0 | } |
1329 | 0 | } |
1330 | 0 | if( result != 1 ) |
1331 | 0 | { |
1332 | 0 | result = libfdatetime_internal_posix_time_copy_to_utf8_string_in_hexadecimal( |
1333 | 0 | internal_posix_time, |
1334 | 0 | utf8_string, |
1335 | 0 | utf8_string_size, |
1336 | 0 | utf8_string_index, |
1337 | 0 | error ); |
1338 | |
|
1339 | 0 | if( result == -1 ) |
1340 | 0 | { |
1341 | 0 | libcerror_error_set( |
1342 | 0 | error, |
1343 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1344 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1345 | 0 | "%s: unable to POSIX time to hexadecimal UTF-8 string.", |
1346 | 0 | function ); |
1347 | |
|
1348 | 0 | return( -1 ); |
1349 | 0 | } |
1350 | 0 | } |
1351 | 0 | return( 1 ); |
1352 | 0 | } |
1353 | | |
1354 | | /* Converts the POSIX time into an UTF-16 string in hexadecimal representation |
1355 | | * The string size should include the end of string character |
1356 | | * Returns 1 if successful or -1 on error |
1357 | | */ |
1358 | | int libfdatetime_internal_posix_time_copy_to_utf16_string_in_hexadecimal( |
1359 | | libfdatetime_internal_posix_time_t *internal_posix_time, |
1360 | | uint16_t *utf16_string, |
1361 | | size_t utf16_string_size, |
1362 | | size_t *utf16_string_index, |
1363 | | libcerror_error_t **error ) |
1364 | 0 | { |
1365 | 0 | static char *function = "libfdatetime_internal_posix_time_copy_to_utf16_string_in_hexadecimal"; |
1366 | 0 | size_t string_index = 0; |
1367 | 0 | size_t string_size = 0; |
1368 | 0 | uint8_t byte_value = 0; |
1369 | 0 | int8_t byte_shift = 0; |
1370 | |
|
1371 | 0 | if( internal_posix_time == NULL ) |
1372 | 0 | { |
1373 | 0 | libcerror_error_set( |
1374 | 0 | error, |
1375 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1376 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1377 | 0 | "%s: invalid POSIX time.", |
1378 | 0 | function ); |
1379 | |
|
1380 | 0 | return( -1 ); |
1381 | 0 | } |
1382 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1383 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) |
1384 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
1385 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
1386 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
1387 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
1388 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
1389 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
1390 | 0 | { |
1391 | 0 | libcerror_error_set( |
1392 | 0 | error, |
1393 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1394 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1395 | 0 | "%s: invalid POSIX time - unsupported value type.", |
1396 | 0 | function ); |
1397 | |
|
1398 | 0 | return( -1 ); |
1399 | 0 | } |
1400 | 0 | if( utf16_string == NULL ) |
1401 | 0 | { |
1402 | 0 | libcerror_error_set( |
1403 | 0 | error, |
1404 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1405 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1406 | 0 | "%s: invalid UTF-16 string.", |
1407 | 0 | function ); |
1408 | |
|
1409 | 0 | return( -1 ); |
1410 | 0 | } |
1411 | 0 | if( utf16_string_size > (size_t) SSIZE_MAX ) |
1412 | 0 | { |
1413 | 0 | libcerror_error_set( |
1414 | 0 | error, |
1415 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1416 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1417 | 0 | "%s: invalid UTF-16 string size value exceeds maximum.", |
1418 | 0 | function ); |
1419 | |
|
1420 | 0 | return( -1 ); |
1421 | 0 | } |
1422 | 0 | if( utf16_string_index == NULL ) |
1423 | 0 | { |
1424 | 0 | libcerror_error_set( |
1425 | 0 | error, |
1426 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1427 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1428 | 0 | "%s: invalid UTF-16 string index.", |
1429 | 0 | function ); |
1430 | |
|
1431 | 0 | return( -1 ); |
1432 | 0 | } |
1433 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1434 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
1435 | 0 | { |
1436 | 0 | string_size = 13; |
1437 | 0 | byte_shift = 28; |
1438 | 0 | } |
1439 | 0 | else |
1440 | 0 | { |
1441 | 0 | string_size = 21; |
1442 | 0 | byte_shift = 60; |
1443 | 0 | } |
1444 | 0 | if( ( utf16_string_size < string_size ) |
1445 | 0 | || ( *utf16_string_index > ( utf16_string_size - string_size ) ) ) |
1446 | 0 | { |
1447 | 0 | libcerror_error_set( |
1448 | 0 | error, |
1449 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1450 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1451 | 0 | "%s: UTF-16 string is too small.", |
1452 | 0 | function ); |
1453 | |
|
1454 | 0 | return( -1 ); |
1455 | 0 | } |
1456 | 0 | string_index = *utf16_string_index; |
1457 | |
|
1458 | 0 | utf16_string[ string_index++ ] = (uint16_t) '('; |
1459 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1460 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1461 | |
|
1462 | 0 | do |
1463 | 0 | { |
1464 | 0 | byte_value = ( internal_posix_time->timestamp >> byte_shift ) & 0x0f; |
1465 | |
|
1466 | 0 | if( byte_value <= 9 ) |
1467 | 0 | { |
1468 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1469 | 0 | } |
1470 | 0 | else |
1471 | 0 | { |
1472 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1473 | 0 | } |
1474 | 0 | byte_shift -= 4; |
1475 | 0 | } |
1476 | 0 | while( byte_shift >= 0 ); |
1477 | |
|
1478 | 0 | utf16_string[ string_index++ ] = (uint16_t) ')'; |
1479 | |
|
1480 | 0 | utf16_string[ string_index++ ] = 0; |
1481 | |
|
1482 | 0 | *utf16_string_index = string_index; |
1483 | |
|
1484 | 0 | return( 1 ); |
1485 | 0 | } |
1486 | | |
1487 | | /* Converts the POSIX time into an UTF-16 string |
1488 | | * The string size should include the end of string character |
1489 | | * Returns 1 if successful or -1 on error |
1490 | | */ |
1491 | | int libfdatetime_posix_time_copy_to_utf16_string( |
1492 | | libfdatetime_posix_time_t *posix_time, |
1493 | | uint16_t *utf16_string, |
1494 | | size_t utf16_string_size, |
1495 | | uint32_t string_format_flags, |
1496 | | libcerror_error_t **error ) |
1497 | 0 | { |
1498 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf16_string"; |
1499 | 0 | size_t utf16_string_index = 0; |
1500 | |
|
1501 | 0 | if( libfdatetime_posix_time_copy_to_utf16_string_with_index( |
1502 | 0 | posix_time, |
1503 | 0 | utf16_string, |
1504 | 0 | utf16_string_size, |
1505 | 0 | &utf16_string_index, |
1506 | 0 | string_format_flags, |
1507 | 0 | error ) != 1 ) |
1508 | 0 | { |
1509 | 0 | libcerror_error_set( |
1510 | 0 | error, |
1511 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1512 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1513 | 0 | "%s: unable to copy POSIX time to UTF-16 string.", |
1514 | 0 | function ); |
1515 | |
|
1516 | 0 | return( -1 ); |
1517 | 0 | } |
1518 | 0 | return( 1 ); |
1519 | 0 | } |
1520 | | |
1521 | | /* Converts the POSIX time into an UTF-16 string |
1522 | | * The string size should include the end of string character |
1523 | | * Returns 1 if successful or -1 on error |
1524 | | */ |
1525 | | int libfdatetime_posix_time_copy_to_utf16_string_with_index( |
1526 | | libfdatetime_posix_time_t *posix_time, |
1527 | | uint16_t *utf16_string, |
1528 | | size_t utf16_string_size, |
1529 | | size_t *utf16_string_index, |
1530 | | uint32_t string_format_flags, |
1531 | | libcerror_error_t **error ) |
1532 | 0 | { |
1533 | 0 | libfdatetime_date_time_values_t date_time_values; |
1534 | |
|
1535 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
1536 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf16_string_with_index"; |
1537 | 0 | int result = 0; |
1538 | |
|
1539 | 0 | if( posix_time == NULL ) |
1540 | 0 | { |
1541 | 0 | libcerror_error_set( |
1542 | 0 | error, |
1543 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1544 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1545 | 0 | "%s: invalid POSIX time.", |
1546 | 0 | function ); |
1547 | |
|
1548 | 0 | return( -1 ); |
1549 | 0 | } |
1550 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
1551 | |
|
1552 | 0 | result = libfdatetime_internal_posix_time_copy_to_date_time_values( |
1553 | 0 | internal_posix_time, |
1554 | 0 | &date_time_values, |
1555 | 0 | error ); |
1556 | |
|
1557 | 0 | if( result != 1 ) |
1558 | 0 | { |
1559 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1560 | | libcerror_error_set( |
1561 | | error, |
1562 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1563 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1564 | | "%s: unable to set date time values.", |
1565 | | function ); |
1566 | | |
1567 | | /* TODO debug print error */ |
1568 | | |
1569 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1570 | |
|
1571 | 0 | if( ( error != NULL ) |
1572 | 0 | && ( *error != NULL ) ) |
1573 | 0 | { |
1574 | 0 | libcerror_error_free( |
1575 | 0 | error ); |
1576 | 0 | } |
1577 | 0 | } |
1578 | 0 | else |
1579 | 0 | { |
1580 | 0 | result = libfdatetime_date_time_values_copy_to_utf16_string_with_index( |
1581 | 0 | &date_time_values, |
1582 | 0 | utf16_string, |
1583 | 0 | utf16_string_size, |
1584 | 0 | utf16_string_index, |
1585 | 0 | string_format_flags, |
1586 | 0 | error ); |
1587 | |
|
1588 | 0 | if( result == -1 ) |
1589 | 0 | { |
1590 | 0 | libcerror_error_set( |
1591 | 0 | error, |
1592 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1593 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1594 | 0 | "%s: unable to copy date time values to UTF-16 string.", |
1595 | 0 | function ); |
1596 | |
|
1597 | 0 | return( -1 ); |
1598 | 0 | } |
1599 | 0 | } |
1600 | 0 | if( result != 1 ) |
1601 | 0 | { |
1602 | 0 | result = libfdatetime_internal_posix_time_copy_to_utf16_string_in_hexadecimal( |
1603 | 0 | internal_posix_time, |
1604 | 0 | utf16_string, |
1605 | 0 | utf16_string_size, |
1606 | 0 | utf16_string_index, |
1607 | 0 | error ); |
1608 | |
|
1609 | 0 | if( result == -1 ) |
1610 | 0 | { |
1611 | 0 | libcerror_error_set( |
1612 | 0 | error, |
1613 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1614 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1615 | 0 | "%s: unable to POSIX time to hexadecimal UTF-16 string.", |
1616 | 0 | function ); |
1617 | |
|
1618 | 0 | return( -1 ); |
1619 | 0 | } |
1620 | 0 | } |
1621 | 0 | return( 1 ); |
1622 | 0 | } |
1623 | | |
1624 | | /* Converts the POSIX time into an UTF-32 string in hexadecimal representation |
1625 | | * The string size should include the end of string character |
1626 | | * Returns 1 if successful or -1 on error |
1627 | | */ |
1628 | | int libfdatetime_internal_posix_time_copy_to_utf32_string_in_hexadecimal( |
1629 | | libfdatetime_internal_posix_time_t *internal_posix_time, |
1630 | | uint32_t *utf32_string, |
1631 | | size_t utf32_string_size, |
1632 | | size_t *utf32_string_index, |
1633 | | libcerror_error_t **error ) |
1634 | 0 | { |
1635 | 0 | static char *function = "libfdatetime_internal_posix_time_copy_to_utf32_string_in_hexadecimal"; |
1636 | 0 | size_t string_index = 0; |
1637 | 0 | size_t string_size = 0; |
1638 | 0 | uint8_t byte_value = 0; |
1639 | 0 | int8_t byte_shift = 0; |
1640 | |
|
1641 | 0 | if( internal_posix_time == NULL ) |
1642 | 0 | { |
1643 | 0 | libcerror_error_set( |
1644 | 0 | error, |
1645 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1646 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1647 | 0 | "%s: invalid POSIX time.", |
1648 | 0 | function ); |
1649 | |
|
1650 | 0 | return( -1 ); |
1651 | 0 | } |
1652 | 0 | if( ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1653 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) |
1654 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) |
1655 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) |
1656 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) |
1657 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) |
1658 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_SIGNED ) |
1659 | 0 | && ( internal_posix_time->value_type != LIBFDATETIME_POSIX_TIME_VALUE_TYPE_NANO_SECONDS_64BIT_UNSIGNED ) ) |
1660 | 0 | { |
1661 | 0 | libcerror_error_set( |
1662 | 0 | error, |
1663 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1664 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1665 | 0 | "%s: invalid POSIX time - unsupported value type.", |
1666 | 0 | function ); |
1667 | |
|
1668 | 0 | return( -1 ); |
1669 | 0 | } |
1670 | 0 | if( utf32_string == NULL ) |
1671 | 0 | { |
1672 | 0 | libcerror_error_set( |
1673 | 0 | error, |
1674 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1675 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1676 | 0 | "%s: invalid UTF-32 string.", |
1677 | 0 | function ); |
1678 | |
|
1679 | 0 | return( -1 ); |
1680 | 0 | } |
1681 | 0 | if( utf32_string_size > (size_t) SSIZE_MAX ) |
1682 | 0 | { |
1683 | 0 | libcerror_error_set( |
1684 | 0 | error, |
1685 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1686 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1687 | 0 | "%s: invalid UTF-32 string size value exceeds maximum.", |
1688 | 0 | function ); |
1689 | |
|
1690 | 0 | return( -1 ); |
1691 | 0 | } |
1692 | 0 | if( utf32_string_index == NULL ) |
1693 | 0 | { |
1694 | 0 | libcerror_error_set( |
1695 | 0 | error, |
1696 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1697 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1698 | 0 | "%s: invalid UTF-32 string index.", |
1699 | 0 | function ); |
1700 | |
|
1701 | 0 | return( -1 ); |
1702 | 0 | } |
1703 | 0 | if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_SIGNED ) |
1704 | 0 | || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_32BIT_UNSIGNED ) ) |
1705 | 0 | { |
1706 | 0 | string_size = 13; |
1707 | 0 | byte_shift = 28; |
1708 | 0 | } |
1709 | 0 | else |
1710 | 0 | { |
1711 | 0 | string_size = 21; |
1712 | 0 | byte_shift = 60; |
1713 | 0 | } |
1714 | 0 | if( ( utf32_string_size < string_size ) |
1715 | 0 | || ( *utf32_string_index > ( utf32_string_size - string_size ) ) ) |
1716 | 0 | { |
1717 | 0 | libcerror_error_set( |
1718 | 0 | error, |
1719 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1720 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1721 | 0 | "%s: UTF-32 string is too small.", |
1722 | 0 | function ); |
1723 | |
|
1724 | 0 | return( -1 ); |
1725 | 0 | } |
1726 | 0 | string_index = *utf32_string_index; |
1727 | |
|
1728 | 0 | utf32_string[ string_index++ ] = (uint32_t) '('; |
1729 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0'; |
1730 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'x'; |
1731 | |
|
1732 | 0 | do |
1733 | 0 | { |
1734 | 0 | byte_value = ( internal_posix_time->timestamp >> byte_shift ) & 0x0f; |
1735 | |
|
1736 | 0 | if( byte_value <= 9 ) |
1737 | 0 | { |
1738 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value; |
1739 | 0 | } |
1740 | 0 | else |
1741 | 0 | { |
1742 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10; |
1743 | 0 | } |
1744 | 0 | byte_shift -= 4; |
1745 | 0 | } |
1746 | 0 | while( byte_shift >= 0 ); |
1747 | |
|
1748 | 0 | utf32_string[ string_index++ ] = (uint32_t) ')'; |
1749 | |
|
1750 | 0 | utf32_string[ string_index++ ] = 0; |
1751 | |
|
1752 | 0 | *utf32_string_index = string_index; |
1753 | |
|
1754 | 0 | return( 1 ); |
1755 | 0 | } |
1756 | | |
1757 | | /* Converts the POSIX time into an UTF-32 string |
1758 | | * The string size should include the end of string character |
1759 | | * Returns 1 if successful or -1 on error |
1760 | | */ |
1761 | | int libfdatetime_posix_time_copy_to_utf32_string( |
1762 | | libfdatetime_posix_time_t *posix_time, |
1763 | | uint32_t *utf32_string, |
1764 | | size_t utf32_string_size, |
1765 | | uint32_t string_format_flags, |
1766 | | libcerror_error_t **error ) |
1767 | 0 | { |
1768 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf32_string"; |
1769 | 0 | size_t utf32_string_index = 0; |
1770 | |
|
1771 | 0 | if( libfdatetime_posix_time_copy_to_utf32_string_with_index( |
1772 | 0 | posix_time, |
1773 | 0 | utf32_string, |
1774 | 0 | utf32_string_size, |
1775 | 0 | &utf32_string_index, |
1776 | 0 | string_format_flags, |
1777 | 0 | error ) != 1 ) |
1778 | 0 | { |
1779 | 0 | libcerror_error_set( |
1780 | 0 | error, |
1781 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1782 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1783 | 0 | "%s: unable to copy POSIX time to UTF-32 string.", |
1784 | 0 | function ); |
1785 | |
|
1786 | 0 | return( -1 ); |
1787 | 0 | } |
1788 | 0 | return( 1 ); |
1789 | 0 | } |
1790 | | |
1791 | | /* Converts the POSIX time into an UTF-32 string |
1792 | | * The string size should include the end of string character |
1793 | | * Returns 1 if successful or -1 on error |
1794 | | */ |
1795 | | int libfdatetime_posix_time_copy_to_utf32_string_with_index( |
1796 | | libfdatetime_posix_time_t *posix_time, |
1797 | | uint32_t *utf32_string, |
1798 | | size_t utf32_string_size, |
1799 | | size_t *utf32_string_index, |
1800 | | uint32_t string_format_flags, |
1801 | | libcerror_error_t **error ) |
1802 | 0 | { |
1803 | 0 | libfdatetime_date_time_values_t date_time_values; |
1804 | |
|
1805 | 0 | libfdatetime_internal_posix_time_t *internal_posix_time = NULL; |
1806 | 0 | static char *function = "libfdatetime_posix_time_copy_to_utf32_string_with_index"; |
1807 | 0 | int result = 0; |
1808 | |
|
1809 | 0 | if( posix_time == NULL ) |
1810 | 0 | { |
1811 | 0 | libcerror_error_set( |
1812 | 0 | error, |
1813 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1814 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1815 | 0 | "%s: invalid POSIX time.", |
1816 | 0 | function ); |
1817 | |
|
1818 | 0 | return( -1 ); |
1819 | 0 | } |
1820 | 0 | internal_posix_time = (libfdatetime_internal_posix_time_t *) posix_time; |
1821 | |
|
1822 | 0 | result = libfdatetime_internal_posix_time_copy_to_date_time_values( |
1823 | 0 | internal_posix_time, |
1824 | 0 | &date_time_values, |
1825 | 0 | error ); |
1826 | |
|
1827 | 0 | if( result != 1 ) |
1828 | 0 | { |
1829 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1830 | | libcerror_error_set( |
1831 | | error, |
1832 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1833 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1834 | | "%s: unable to set date time values.", |
1835 | | function ); |
1836 | | |
1837 | | /* TODO debug print error */ |
1838 | | |
1839 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1840 | |
|
1841 | 0 | if( ( error != NULL ) |
1842 | 0 | && ( *error != NULL ) ) |
1843 | 0 | { |
1844 | 0 | libcerror_error_free( |
1845 | 0 | error ); |
1846 | 0 | } |
1847 | 0 | } |
1848 | 0 | else |
1849 | 0 | { |
1850 | 0 | result = libfdatetime_date_time_values_copy_to_utf32_string_with_index( |
1851 | 0 | &date_time_values, |
1852 | 0 | utf32_string, |
1853 | 0 | utf32_string_size, |
1854 | 0 | utf32_string_index, |
1855 | 0 | string_format_flags, |
1856 | 0 | error ); |
1857 | |
|
1858 | 0 | if( result == -1 ) |
1859 | 0 | { |
1860 | 0 | libcerror_error_set( |
1861 | 0 | error, |
1862 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1863 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1864 | 0 | "%s: unable to set UTF-32 string.", |
1865 | 0 | function ); |
1866 | |
|
1867 | 0 | return( -1 ); |
1868 | 0 | } |
1869 | 0 | } |
1870 | 0 | if( result != 1 ) |
1871 | 0 | { |
1872 | 0 | if( utf32_string == NULL ) |
1873 | 0 | { |
1874 | 0 | libcerror_error_set( |
1875 | 0 | error, |
1876 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1877 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1878 | 0 | "%s: invalid UTF-32 string.", |
1879 | 0 | function ); |
1880 | |
|
1881 | 0 | return( -1 ); |
1882 | 0 | } |
1883 | 0 | if( utf32_string_size > (size_t) SSIZE_MAX ) |
1884 | 0 | { |
1885 | 0 | libcerror_error_set( |
1886 | 0 | error, |
1887 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1888 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1889 | 0 | "%s: unable to copy date time values to UTF-32 string.", |
1890 | 0 | function ); |
1891 | |
|
1892 | 0 | return( -1 ); |
1893 | 0 | } |
1894 | 0 | } |
1895 | 0 | if( result != 1 ) |
1896 | 0 | { |
1897 | 0 | result = libfdatetime_internal_posix_time_copy_to_utf32_string_in_hexadecimal( |
1898 | 0 | internal_posix_time, |
1899 | 0 | utf32_string, |
1900 | 0 | utf32_string_size, |
1901 | 0 | utf32_string_index, |
1902 | 0 | error ); |
1903 | |
|
1904 | 0 | if( result == -1 ) |
1905 | 0 | { |
1906 | 0 | libcerror_error_set( |
1907 | 0 | error, |
1908 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1909 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1910 | 0 | "%s: unable to POSIX time to hexadecimal UTF-32 string.", |
1911 | 0 | function ); |
1912 | |
|
1913 | 0 | return( -1 ); |
1914 | 0 | } |
1915 | 0 | } |
1916 | 0 | return( 1 ); |
1917 | 0 | } |
1918 | | |