Contains time-related functions: mtime(), convert_date_time(), mtimes().
More...
#include "mdb.h"
#include <ctype.h>
#include <time.h>
Go to the source code of this file.
|
char * | mtime (void) |
| Generates a formatted time string.
|
|
char * | mtimes (void) |
| Generates a detailed formatted time string.
|
|
Contains time-related functions: mtime(), convert_date_time(), mtimes().
- Copyright
- (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
- (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
- License
- This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
- Author
- M. Borland, C. Saunders, R. Soliday
Definition in file time.c.
◆ mtime()
Generates a formatted time string.
This function returns a more user-friendly time string compared to ctime()
.
Format Comparison:
ctime
: "wkd mmm dd hh:mm:ss 19yy\n"
mtime
: "dd mmm yy hh:mm"
- Returns
- A pointer to the newly allocated formatted time string.
Definition at line 93 of file time.c.
93 {
94 char *ct, *mt;
95 char *month, *day, *t, *ptr;
96 time_t i;
97 time_t time();
98
99 while ((mt =
tmalloc((
unsigned)30 *
sizeof(*mt))) == NULL)
100 puts("allocation failure in mtime()");
101 time(&i);
102 ct = ctime(&i) + 4;
103 *(ct + strlen(ct) - 1) = 0;
104
105 month = ct;
106 ct = strchr(ct, ' ');
107 while (*ct == ' ')
108 *ct++ = 0;
109
110 day = ct;
111 ct = strchr(ct, ' ');
112 while (*ct == ' ')
113 *ct++ = 0;
114
115 t = ct;
116 ct = strchr(ct, ' ');
117 while (*ct == ' ')
118 *ct++ = 0;
119 ptr = strrchr(t, ':');
120 *ptr = 0;
121
122 sprintf(mt, "%s %s %s %s", day, month, ct + 2, t);
123 return (mt);
124}
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
◆ mtimes()
Generates a detailed formatted time string.
This function returns a more detailed and user-friendly time string compared to ctime()
.
Format Comparison:
ctime
: "wkd mmm dd hh:mm:ss 19yy\n"
mtimes
: "dd mmm yy hh:mm:ss"
- Returns
- A pointer to the newly allocated detailed formatted time string.
Definition at line 137 of file time.c.
137 {
138 char *ct, *mt;
139 char *month, *day, *t;
140 time_t i;
141 time_t time();
142
143 while ((mt =
tmalloc((
unsigned)30 *
sizeof(*mt))) == NULL)
144 puts("allocation failure in mtime()");
145 time(&i);
146 ct = ctime(&i) + 4;
147 *(ct + strlen(ct) - 1) = 0;
148
149 month = ct;
150 ct = strchr(ct, ' ');
151 while (*ct == ' ')
152 *ct++ = 0;
153
154 day = ct;
155 ct = strchr(ct, ' ');
156 while (*ct == ' ')
157 *ct++ = 0;
158
159 t = ct;
160 ct = strchr(ct, ' ');
161 while (*ct == ' ')
162 *ct++ = 0;
163
164 sprintf(mt, "%s %s %s %s", day, month, ct + 2, t);
165 return (mt);
166}