2929#define DEBUG (f , args ...)
3030#endif
3131
32+ static time_t epoch_seconds_1996 () {
33+ struct tm tm_1996 = {
34+ .tm_year = 96 ,
35+ .tm_mon = 0 ,
36+ .tm_mday = 1
37+ };
38+ // The argument to mktime is zoneless
39+ return mktime (& tm_1996 );
40+ }
41+
42+
3243/**
3344 * Strip trailing spaces
3445 */
@@ -434,13 +445,7 @@ fru_info_area_t *fru_create_info_area(fru_area_type_t atype, ///< [in] Area t
434445
435446 if (FRU_AREA_HAS_DATE (atype )) {
436447 uint32_t fru_time ;
437- struct tm tm_1996 = {
438- .tm_year = 96 ,
439- .tm_mon = 0 ,
440- .tm_mday = 1
441- };
442448 const struct timeval tv_unspecified = { 0 };
443- struct timeval tv_1996 = { 0 };
444449
445450 if (!tv ) {
446451 errno = EFAULT ;
@@ -455,10 +460,8 @@ fru_info_area_t *fru_create_info_area(fru_area_type_t atype, ///< [in] Area t
455460 printf ("Using FRU_DATE_UNSPECIFIED\n" );
456461 fru_time = FRU_DATE_UNSPECIFIED ;
457462 } else {
458- // The argument to mktime is zoneless
459- tv_1996 .tv_sec = mktime (& tm_1996 );
460463 // FRU time is in minutes and we don't care about microseconds
461- fru_time = (tv -> tv_sec - tv_1996 . tv_sec ) / 60 ;
464+ fru_time = (tv -> tv_sec - epoch_seconds_1996 () ) / 60 ;
462465 }
463466 header .mfgdate [0 ] = fru_time & 0xFF ;
464467 header .mfgdate [1 ] = (fru_time >> 8 ) & 0xFF ;
@@ -534,7 +537,7 @@ static bool fru_decode_custom_fields(const uint8_t *data, fru_reclist_t **reclis
534537
535538 fru_reclist_t * custom_field = add_reclist (reclist );
536539 if (custom_field == NULL )
537- return false;
540+ return false;
538541
539542 // Create a NUL terminated version of the data for encoding
540543 // TODO pass the length into fru_encode_data instead
@@ -548,7 +551,7 @@ static bool fru_decode_custom_fields(const uint8_t *data, fru_reclist_t **reclis
548551 data += FRU_FIELDSIZE (field -> typelen );
549552 }
550553
551- return true;
554+ return true;
552555}
553556
554557/**
@@ -673,53 +676,53 @@ bool fru_decode_board_info(
673676 fru_exploded_board_t * board_out //< [out]
674677)
675678{
676- fru_field_t * field ;
679+ fru_field_t * field ;
677680 const uint8_t * data = area -> data ;
678681
679- board_out -> lang = area -> langtype ;
682+ board_out -> lang = area -> langtype ;
680683
681- uint32_t * min_since_1996 = (uint32_t * )& (area -> mfgdate );
682- struct tm tm_1996 = {
684+ uint32_t * min_since_1996 = (uint32_t * )& (area -> mfgdate );
685+ struct tm tm_1996 = {
683686 .tm_year = 96 ,
684687 .tm_mon = 0 ,
685688 .tm_mday = 1
686- };
687- // The argument to mktime is zoneless
688- board_out -> tv .tv_sec = mktime (& tm_1996 ) + 60 * (* min_since_1996 );
689+ };
690+ // The argument to mktime is zoneless
691+ board_out -> tv .tv_sec = mktime (& tm_1996 ) + 60 * (* min_since_1996 );
689692
690693 field = (fru_field_t * )data ;
691- if (!fru_decode_data (field , board_out -> mfg ,
694+ if (!fru_decode_data (field , board_out -> mfg ,
692695 sizeof (board_out -> mfg )))
693- return false;
696+ return false;
694697 data += FRU_FIELDSIZE (field -> typelen );
695698
696699 field = (fru_field_t * )data ;
697- if (!fru_decode_data (field , board_out -> pname ,
700+ if (!fru_decode_data (field , board_out -> pname ,
698701 sizeof (board_out -> pname )))
699- return false;
702+ return false;
700703 data += FRU_FIELDSIZE (field -> typelen );
701704
702705 field = (fru_field_t * )data ;
703- if (!fru_decode_data (field , board_out -> serial ,
706+ if (!fru_decode_data (field , board_out -> serial ,
704707 sizeof (board_out -> serial )))
705- return false;
708+ return false;
706709 data += FRU_FIELDSIZE (field -> typelen );
707710
708711 field = (fru_field_t * )data ;
709- if (!fru_decode_data (field , board_out -> pn ,
712+ if (!fru_decode_data (field , board_out -> pn ,
710713 sizeof (board_out -> pn )))
711- return false;
714+ return false;
712715 data += FRU_FIELDSIZE (field -> typelen );
713716
714717 field = (fru_field_t * )data ;
715- if (!fru_decode_data (field , board_out -> file ,
718+ if (!fru_decode_data (field , board_out -> file ,
716719 sizeof (board_out -> file )))
717- return false;
720+ return false;
718721 data += FRU_FIELDSIZE (field -> typelen );
719722
720- fru_decode_custom_fields (data , & board_out -> cust );
723+ fru_decode_custom_fields (data , & board_out -> cust );
721724
722- return true;
725+ return true;
723726}
724727
725728/**
0 commit comments