Print this page
4378 Clean up %C in *time() functions
438 need documentation for strftime %s flag


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*


  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <stdint.h>
  29 #include <strings.h>
  30 #include <assert.h>
  31 #include <pthread.h>
  32 #include <sys/byteorder.h>
  33 #include <sys/types.h>
  34 #include <sys/nvpair.h>
  35 
  36 #include "libfru.h"
  37 #include "libfrup.h"
  38 #include "fru_tag.h"
  39 #include "libfrureg.h"
  40 #include "nvfru.h"
  41 
  42 #define NUM_ITER_BYTES  4


  56 convert_field(const uint8_t *field, const fru_regdef_t *def, const char *path,
  57     nvlist_t *nv)
  58 {
  59         char timestring[TIMESTRINGLEN];
  60         int i;
  61         uint64_t value;
  62         time_t timefield;
  63 
  64         switch (def->dataType) {
  65         case FDTYPE_Binary:
  66                 assert(def->payloadLen <= sizeof (value));
  67                 switch (def->dispType) {
  68 #if PARSE_TIME == 1
  69                 case FDISP_Time:
  70                         if (def->payloadLen > sizeof (timefield)) {
  71                                 /* too big for formatting */
  72                                 return;
  73                         }
  74                         (void) memcpy(&timefield, field, sizeof (timefield));
  75                         timefield = BE_32(timefield);
  76                         if (strftime(timestring, sizeof (timestring), "%C",
  77                             localtime(&timefield)) == 0) {
  78                                 /* buffer too small */
  79                                 return;
  80                         }
  81                         (void) nvlist_add_string(nv, path, timestring);
  82                         return;
  83 #endif
  84 
  85                 case FDISP_Binary:
  86                 case FDISP_Octal:
  87                 case FDISP_Decimal:
  88                 case FDISP_Hex:
  89                 default:
  90                         value = 0;
  91                         (void) memcpy((((uint8_t *)&value) +
  92                             sizeof (value) - def->payloadLen),
  93                             field, def->payloadLen);
  94                         value = BE_64(value);
  95                         switch (def->payloadLen) {
  96                         case 1:




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2014 Gary Mills
  24  *
  25  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  26  */
  27 
  28 #include <stdio.h>
  29 #include <stdlib.h>
  30 #include <stdint.h>
  31 #include <strings.h>
  32 #include <assert.h>
  33 #include <pthread.h>
  34 #include <sys/byteorder.h>
  35 #include <sys/types.h>
  36 #include <sys/nvpair.h>
  37 
  38 #include "libfru.h"
  39 #include "libfrup.h"
  40 #include "fru_tag.h"
  41 #include "libfrureg.h"
  42 #include "nvfru.h"
  43 
  44 #define NUM_ITER_BYTES  4


  58 convert_field(const uint8_t *field, const fru_regdef_t *def, const char *path,
  59     nvlist_t *nv)
  60 {
  61         char timestring[TIMESTRINGLEN];
  62         int i;
  63         uint64_t value;
  64         time_t timefield;
  65 
  66         switch (def->dataType) {
  67         case FDTYPE_Binary:
  68                 assert(def->payloadLen <= sizeof (value));
  69                 switch (def->dispType) {
  70 #if PARSE_TIME == 1
  71                 case FDISP_Time:
  72                         if (def->payloadLen > sizeof (timefield)) {
  73                                 /* too big for formatting */
  74                                 return;
  75                         }
  76                         (void) memcpy(&timefield, field, sizeof (timefield));
  77                         timefield = BE_32(timefield);
  78                         if (strftime(timestring, sizeof (timestring), "%c",
  79                             localtime(&timefield)) == 0) {
  80                                 /* buffer too small */
  81                                 return;
  82                         }
  83                         (void) nvlist_add_string(nv, path, timestring);
  84                         return;
  85 #endif
  86 
  87                 case FDISP_Binary:
  88                 case FDISP_Octal:
  89                 case FDISP_Decimal:
  90                 case FDISP_Hex:
  91                 default:
  92                         value = 0;
  93                         (void) memcpy((((uint8_t *)&value) +
  94                             sizeof (value) - def->payloadLen),
  95                             field, def->payloadLen);
  96                         value = BE_64(value);
  97                         switch (def->payloadLen) {
  98                         case 1: