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