GCOV Execution Analysis for sahpi_time_utils.c
The left column is the number of times the code was executed
during the unit test suites.
Exec | Code | Line # | |
---|---|---|---|
Source:sahpi_time_utils.c | 1 | ||
Graph:.libs/sahpi_time_utils.gcno | 2 | ||
Data:.libs/sahpi_time_utils.gcda | 3 | ||
Runs:378 | 4 | ||
Programs:378 | 5 | ||
/* -*- linux-c -*- | 6 | ||
* | 7 | ||
* (C) Copyright IBM Corp. 2004 | 8 | ||
* | 9 | ||
* This program is distributed in the hope that it will be useful, | 10 | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This | 12 | ||
* file and program are licensed under a BSD style license. See | 13 | ||
* the Copying file included with the OpenHPI distribution for | 14 | ||
* full licensing terms. | 15 | ||
* | 16 | ||
* Author(s): | 17 | ||
* Steve Sherman < address removed > | 18 | ||
*/ | 19 | ||
20 | |||
#include <stdlib.h> | 21 | ||
#include <stdio.h> | 22 | ||
#include <string.h> | 23 | ||
#include <time.h> | 24 | ||
#include <sys/time.h> | 25 | ||
26 | |||
#include <SaHpi.h> | 27 | ||
#include <oh_utils.h> | 28 | ||
29 | |||
/** | 30 | ||
* oh_decode_time: | 31 | ||
* @time: SaHpiTimeT time to be converted. | 32 | ||
* @buffer: Location to store the converted string. | 33 | ||
* | 34 | ||
* Converts an SaHpiTimeT time value to the preferred date/time string | 35 | ||
* representation defined for the current locale. | 36 | ||
* String is stored in an SaHpiTextBufferT data structure. | 37 | ||
* | 38 | ||
* Returns: | 39 | ||
* SA_OK - normal operation. | 40 | ||
* SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL. | 41 | ||
* SA_ERR_HPI_INTERNAL_ERROR - @buffer not big enough to accomodate | 42 | ||
* date/time representation string. | 43 | ||
**/ | 44 | ||
SaErrorT oh_decode_time(SaHpiTimeT time, SaHpiTextBufferT *buffer) | 45 | ||
0 | { | 46 | |
0 | int count; | 47 | |
0 | struct tm t; | 48 | |
0 | time_t tt; | 49 | |
0 | SaErrorT err; | 50 | |
0 | SaHpiTextBufferT working; | 51 | |
52 | |||
0 | if (!buffer) { | 53 | |
0 | return(SA_ERR_HPI_INVALID_PARAMS); | 54 | |
} | 55 | ||
56 | |||
0 | err = oh_init_textbuffer(&working); | 57 | |
0 | if (err != SA_OK) { return(err); } | 58 | |
59 | |||
0 | if (time > SAHPI_TIME_MAX_RELATIVE) { /*absolute time*/ | 60 | |
0 | tt = time / 1000000000; | 61 | |
0 | count = strftime(working.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH, "%F %T", localtime(&tt)); | 62 | |
0 | } else if (time == SAHPI_TIME_UNSPECIFIED) { | 63 | |
0 | strcpy(working.Data,"SAHPI_TIME_UNSPECIFIED "); | 64 | |
0 | count = sizeof("SAHPI_TIME_UNSPECIFIED "); | 65 | |
0 | } else if (time > SAHPI_TIME_UNSPECIFIED) { /*invalid time*/ | 66 | |
0 | strcpy(working.Data,"invalid time "); | 67 | |
0 | count = sizeof("Invalid time "); | 68 | |
} else { /*relative time*/ | 69 | ||
0 | tt = time / 1000000000; | 70 | |
0 | localtime_r(&tt, &t); | 71 | |
/* count = strftime(str, size, "%b %d, %Y - %H:%M:%S", &t); */ | 72 | ||
0 | count = strftime(working.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH, "%c", &t); | 73 | |
} | 74 | ||
75 | |||
0 | if (count == 0) { return(SA_ERR_HPI_INTERNAL_ERROR); } | 76 | |
77 | |||
0 | err = oh_copy_textbuffer(buffer, &working); | 78 | |
0 | if (err != SA_OK) { return(err); } | 79 | |
80 | |||
0 | return(SA_OK); | 81 | |
} | 82 | ||
83 | |||
/** | 84 | ||
* oh_gettimeofday: | 85 | ||
* @time: Location to store Time of Day value | 86 | ||
* | 87 | ||
* Find the time of day and converts it into an HPI time. | 88 | ||
* | 89 | ||
* Returns: | 90 | ||
* SA_OK - normal operation. | 91 | ||
* SA_ERR_HPI_INVALID_PARAMS - @time is NULL. | 92 | ||
**/ | 93 | ||
SaErrorT oh_gettimeofday(SaHpiTimeT *time) | 94 | ||
12 | { | 95 | |
12 | int err; | 96 | |
12 | struct timeval now; | 97 | |
98 | |||
12 | if (!time) { | 99 | |
0 | return(SA_ERR_HPI_INVALID_PARAMS); | 100 | |
} | 101 | ||
102 | |||
12 | err = gettimeofday(&now, NULL); | 103 | |
12 | if (err) { | 104 | |
0 | dbg("gettimeofday failed"); | 105 | |
0 | return(SA_ERR_HPI_INTERNAL_ERROR); | 106 | |
} | 107 | ||
108 | |||
12 | *time = (SaHpiTimeT)now.tv_sec * 1000000000 + now.tv_usec * 1000; | 109 | |
110 | |||
12 | return(SA_OK); | 111 | |
} | 112 | ||
113 |