|
1 /** @file ../include/time.h |
|
2 @internalComponent |
|
3 */ |
|
4 |
|
5 /** @fn asctime(const struct tm *tm) |
|
6 @param tm |
|
7 |
|
8 Refer to ctime() for the documentation |
|
9 @see gettimeofday() |
|
10 @see getenv() |
|
11 @see time() |
|
12 @see tzset() |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 @publishedAll |
|
18 @externallyDefinedApi |
|
19 */ |
|
20 |
|
21 /** @fn clock(void) |
|
22 @return clock is just for build support and hence returns 0. |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 The clock function |
|
28 determines the amount of processor time used since the invocation of the |
|
29 calling process, measured in CLOCKS_PER_SEC s of a second. |
|
30 |
|
31 Note: the clock system call eventually calls Symbian OS call user::GetCpuTime(), |
|
32 which is not supported from version 8.0b, hence this api is included for build |
|
33 support only. |
|
34 |
|
35 |
|
36 |
|
37 @publishedAll |
|
38 @externallyDefinedApi |
|
39 */ |
|
40 |
|
41 /** @fn ctime(const time_t *clock) |
|
42 @param clock |
|
43 |
|
44 Note: This description also covers the following functions - |
|
45 difftime() asctime() localtime() gmtime() mktime() ctime_r() localtime_r() gmtime_r() asctime_r() |
|
46 |
|
47 @return Each of these functions returns the value described, NULL, or -1 in the case of mktime if an error was detected. |
|
48 |
|
49 The functions ctime, gmtime and localtime all take as an argument a time value representing the time |
|
50 in seconds since the Epoch (00:00:00 UTC, January 1, 1970); see time |
|
51 |
|
52 The function localtime converts the time value pointed at by clock and returns a pointer to a " struct tm " (described below) which contains the broken down time information |
|
53 for the value after adjusting for the current time zone (and any other factors |
|
54 such as Daylight Saving Time). Time zone adjustments are performed as specified |
|
55 by the TZ environment variable (see the tzset function). localtime uses tzset to initialize time conversion information |
|
56 if tzset has not already been called by the process. |
|
57 |
|
58 After filling in the tm structure, localtime sets the tm_isdst's Nth element of tzname to a pointer to a ASCII string that is the time zone abbreviation to be |
|
59 used with localtime's (return, value.); |
|
60 |
|
61 The function gmtime similarly converts the time value without any time zone adjustment |
|
62 and returns a pointer to a tm structure (described below). |
|
63 |
|
64 The ctime function adjusts the time value for the current time zone, in |
|
65 the same manner as localtime, and returns a pointer to a 26-character string of the form: Thu Nov 24 18:22:48 1986 |
|
66 \\0 |
|
67 |
|
68 All the fields have constant width. |
|
69 |
|
70 The ctime_r function provides the same functionality as ctime except the caller must provide the output buffer buf to store the result, which must be at least 26 characters long. |
|
71 |
|
72 The localtime_r and gmtime_r functions provide the same functionality as localtime and gmtime respectively, except the caller must provide the output buffer result. |
|
73 |
|
74 The asctime function |
|
75 converts the broken down time in the structure tm pointed at by *tm to the form |
|
76 shown in the example above. |
|
77 |
|
78 The asctime_r function provides the same functionality as asctime except the caller provides the output buffer buf to store the result, which must be at least 26 characters long. |
|
79 |
|
80 The functions mktime converts the broken-down time in the structure pointed to by |
|
81 tm into a time value with the same encoding as that of the values returned by |
|
82 the time function (that is, seconds from the Epoch, UTC). The mktime function interprets the input structure according to the current |
|
83 timezone setting (see tzset ). |
|
84 |
|
85 The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values |
|
86 of the other components are not restricted to their normal ranges and will be |
|
87 normalized if needed. For example, October 40 is changed into November 9, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year. |
|
88 |
|
89 A positive or zero value for tm_isdst causes mktime to presume initially that summer time (for example, Daylight |
|
90 Saving Time) is or is not in effect for the specified time.. A negative value |
|
91 for tm_isdst causes the mktime function to attempt to define whether summer time is in effect |
|
92 for the specified time. The tm_isdst and tm_gmtoff members are forced to zero by timegm. |
|
93 |
|
94 On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately and the other |
|
95 components are set to represent the specified calendar time, but with their |
|
96 values forced to their normal ranges: The final value of tm_mday is not set until tm_mon and tm_year are determined. |
|
97 |
|
98 The mktime function returns the specified calendar time. If the calendar |
|
99 time cannot be represented, it returns -1. |
|
100 |
|
101 The difftime function |
|
102 returns the difference between two calendar times, ( time1 - time0), expressed in seconds. |
|
103 |
|
104 External declarations as well as the tm structure definition are in the |
|
105 @code |
|
106 #include <time.h> include file. The tm structure includes |
|
107 @endcode |
|
108 at least the following fields: |
|
109 |
|
110 @code |
|
111 |
|
112 int tm_sec; // seconds (0 - 60) |
|
113 int tm_min; // minutes (0 - 59) |
|
114 int tm_hour; // hours (0 - 23) |
|
115 int tm_mday; // day of month (1 - 31) |
|
116 int tm_mon; // month of year (0 - 11) |
|
117 int tm_year; // year - 1900 |
|
118 int tm_wday; // day of week (Sunday = 0) |
|
119 int tm_yday; // day of year (0 - 365) |
|
120 int tm_isdst; // is summer time in effect? |
|
121 char *tm_zone; // abbreviation of timezone name |
|
122 long tm_gmtoff; // offset from UTC in seconds |
|
123 |
|
124 @endcode |
|
125 |
|
126 The |
|
127 field tm_isdst is non-zero if summer time is in effect. |
|
128 |
|
129 The field tm_gmtoff is the offset (in seconds) of the time represented from UTC, with positive |
|
130 values indicating east of the Prime Meridian. |
|
131 |
|
132 Examples: |
|
133 @code |
|
134 //Example usage of asctime,localtime and gmtime: |
|
135 #include <time.h> |
|
136 #include <stdio.h> |
|
137 int main(){ |
|
138 time_t t; |
|
139 struct tm *timeptr; |
|
140 char* asc_time; |
|
141 t = time (NULL); //Get current time in seconds from Epoc |
|
142 //Fill tm struct w.r.t localtime using localtime |
|
143 timeptr = localtime (&t;); |
|
144 //Use this to convert it to a string indicating time w.r.t localtime |
|
145 asc_time = asctime (timeptr); |
|
146 printf ("Time from asctime w.r.t localtime : %s", asc_time); |
|
147 //Fill tm struct w.r.t GMT using gmtime |
|
148 timeptr = gmtime (&t;); |
|
149 //Use this to convert it to a string indicating time w.r.t GMT |
|
150 asc_time = asctime (timeptr); |
|
151 printf ("Time from asctime w.r.t gmtime : %s", asc_time); |
|
152 return 0; |
|
153 } |
|
154 |
|
155 @endcode |
|
156 Output |
|
157 @code |
|
158 Time from asctime w.r.t localtime : Thu Jun 22 10:42:27 2006 |
|
159 Time from asctime w.r.t gmtime : Thu Jun 22 05:12:27 2006 |
|
160 |
|
161 @endcode |
|
162 @code |
|
163 //Example usage of ctime,mktime: |
|
164 #include <time.h> |
|
165 #include <stdio.h> |
|
166 int main(){ |
|
167 time_t t; |
|
168 struct tm timeptr; |
|
169 char* c_time; |
|
170 //Fill the tm struct with values |
|
171 timeptr.tm_year = 2001; |
|
172 timeptr.tm_mon = 6; |
|
173 timeptr.tm_mday = 4; |
|
174 timeptr.tm_hour = 0; |
|
175 timeptr.tm_min = 0; |
|
176 timeptr.tm_sec = 1; |
|
177 timeptr.tm_isdst = -1; |
|
178 t = mktime (&timeptr;); //Call mktime to make time in seconds w.r.t epoc |
|
179 //Convert this to a string indicating time using ctime |
|
180 c_time = ctime (&t;); |
|
181 printf ("Time from ctime : %s", c_time); |
|
182 return 0; |
|
183 } |
|
184 |
|
185 @endcode |
|
186 Output |
|
187 @code |
|
188 Time from ctime : Thu Jan 1 05:29:59 1970 |
|
189 |
|
190 @endcode |
|
191 @code |
|
192 //Example usage of difftime: |
|
193 #include <time.h> |
|
194 #include <unistd.h> |
|
195 #include <stdio.h> |
|
196 int main(){ |
|
197 time_t t0,t1,t2; |
|
198 //Set initial and final values |
|
199 t0 = 10; |
|
200 t1 = 20; |
|
201 t2 = difftime (t1, t0); //Find the time difference using difftime |
|
202 printf ("Result of difftime = %d", t2); |
|
203 return 0; |
|
204 } |
|
205 |
|
206 @endcode |
|
207 Output |
|
208 @code |
|
209 Result of difftime = 10 |
|
210 |
|
211 @endcode |
|
212 @see gettimeofday() |
|
213 @see getenv() |
|
214 @see time() |
|
215 @see tzset() |
|
216 |
|
217 |
|
218 Bugs: |
|
219 |
|
220 Except for difftime, mktime, and the _r variants of the other functions, |
|
221 these functions leaves their result in an internal static object and return |
|
222 a pointer to that object. |
|
223 Subsequent calls to these |
|
224 function will modify the same object. |
|
225 |
|
226 The C Standard provides no mechanism for a program to modify its current |
|
227 local timezone setting, and the POSIX -standard method is not reentrant. |
|
228 (However, thread-safe implementations are provided |
|
229 in the POSIX threaded environment.) |
|
230 |
|
231 The tm_zone field of a returned tm |
|
232 structure points to a static array of characters, |
|
233 which will also be overwritten by any subsequent calls (as well as by |
|
234 subsequent call to tzset ) |
|
235 |
|
236 |
|
237 @publishedAll |
|
238 @externallyDefinedApi |
|
239 */ |
|
240 |
|
241 /** @fn difftime(time_t time1, time_t time0) |
|
242 @param time1 |
|
243 @param time0 |
|
244 |
|
245 Refer to ctime() for the documentation |
|
246 @see gettimeofday() |
|
247 @see getenv() |
|
248 @see time() |
|
249 @see tzset() |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 @publishedAll |
|
255 @externallyDefinedApi |
|
256 */ |
|
257 |
|
258 /** @fn gmtime(const time_t *clock) |
|
259 @param clock |
|
260 |
|
261 Refer to ctime() for the documentation |
|
262 @see gettimeofday() |
|
263 @see getenv() |
|
264 @see time() |
|
265 @see tzset() |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 @publishedAll |
|
271 @externallyDefinedApi |
|
272 */ |
|
273 |
|
274 /** @fn localtime(const time_t *clock) |
|
275 @param clock |
|
276 |
|
277 Refer to ctime() for the documentation |
|
278 @see gettimeofday() |
|
279 @see getenv() |
|
280 @see time() |
|
281 @see tzset() |
|
282 |
|
283 |
|
284 The localtime() is not guaranteed to be thread safe. |
|
285 |
|
286 @publishedAll |
|
287 @externallyDefinedApi |
|
288 */ |
|
289 |
|
290 /** @fn mktime(struct tm *tm) |
|
291 @param tm |
|
292 |
|
293 Refer to ctime() for the documentation |
|
294 @see gettimeofday() |
|
295 @see getenv() |
|
296 @see time() |
|
297 @see tzset() |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 @publishedAll |
|
303 @externallyDefinedApi |
|
304 */ |
|
305 |
|
306 /** @fn strftime(char * s, size_t maxsize, const char * format, const struct tm * t) |
|
307 @param s |
|
308 @param maxsize |
|
309 @param format |
|
310 @param t |
|
311 |
|
312 The strftime function formats the information from t into the buffer s according to the string pointed to by format . |
|
313 The format string consists of zero or more conversion specifications and |
|
314 ordinary characters. |
|
315 All ordinary characters are copied directly into the buffer. |
|
316 A conversion specification consists of a percent sign "\%" |
|
317 and one other character. |
|
318 |
|
319 No more than maxsize characters will be placed into the array. If the total number of resulting characters, including the terminating NULL character, is not more |
|
320 than maxsize , strftime returns the number of characters in the array, not counting |
|
321 the terminating NULL. Otherwise, zero is returned and the buffer contents are |
|
322 indeterminate. |
|
323 |
|
324 @code |
|
325 The conversion specifications are copied to the buffer after expansion as follows:- |
|
326 %A is replaced by national representation of the full weekday name. |
|
327 %a is replaced by national representation of the abbreviated weekday name. |
|
328 %B is replaced by national representation of the full month name. |
|
329 %b is replaced by national representation of the abbreviated month name. |
|
330 %C is replaced by (year / 100) as decimal number; single digits are preceded by a zero. |
|
331 %c is replaced by national representation of time and date. |
|
332 %D is equivalent to "%m/%d/%y". |
|
333 %d is replaced by the day of the month as a decimal number (01-31). |
|
334 %E* %O* |
|
335 POSIX locale extensions. The sequences %Ec %EC %Ex %EX %Ey %EY %Od %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow %OW %Oy are supposed to provide alternate representations. |
|
336 Additionally %OB implemented to represent alternative months names (used standalone, without day mentioned). |
|
337 |
|
338 %e is replaced by the day of month as a decimal number (1-31); single digits are preceded by a blank. |
|
339 %F is equivalent to "%Y-%m-%d". |
|
340 %G is replaced by a year as a decimal number with century. This year is the one that contains the greater part of the week (Monday as the first day of the week). |
|
341 %g is replaced by the same year as in "%G", but as a decimal number without century (00-99). |
|
342 %H is replaced by the hour (24-hour clock) as a decimal number (00-23). |
|
343 %h the same as %b. |
|
344 %I is replaced by the hour (12-hour clock) as a decimal number (01-12). |
|
345 %j is replaced by the day of the year as a decimal number (001-366). |
|
346 %k is replaced by the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank. |
|
347 %l is replaced by the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank. |
|
348 %M is replaced by the minute as a decimal number (00-59). |
|
349 %m is replaced by the month as a decimal number (01-12). |
|
350 %n is replaced by a newline. |
|
351 %O* the same as %E*. |
|
352 %p is replaced by national representation of either "ante meridiem" or "post meridiem" as appropriate. |
|
353 %R is equivalent to "%H:%M". |
|
354 %r is equivalent to "%I:%M:%S %p". |
|
355 %S is replaced by the second as a decimal number (00-60). |
|
356 %s is replaced by the number of seconds since the Epoch, UTC (see mktime). |
|
357 %T is equivalent to "%H:%M:%S". |
|
358 %t is replaced by a tab. |
|
359 %U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number (00-53). |
|
360 %u is replaced by the weekday (Monday as the first day of the week) as a decimal number (1-7). |
|
361 %V is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1. |
|
362 %v is equivalent to "%e-%b-%Y". |
|
363 %W is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (00-53). |
|
364 %w is replaced by the weekday (Sunday as the first day of the week) as a decimal number (0-6). |
|
365 %X is replaced by national representation of the time. |
|
366 %x is replaced by national representation of the date. |
|
367 %Y is replaced by the year with century as a decimal number. |
|
368 %y is replaced by the year without century as a decimal number (00-99). |
|
369 %Z is replaced by the time zone name. |
|
370 %z is replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers). |
|
371 %+ is replaced by national representation of the date and time (the format is similar to that produced by 'date( )' function ). |
|
372 %-* GNU libc extension. Do not do any padding when performing numerical outputs. |
|
373 %_* GNU libc extension. Explicitly specify space for padding. |
|
374 %0* GNU libc extension. Explicitly specify zero for padding. |
|
375 %% is replaced by ‘%’. |
|
376 @endcode |
|
377 |
|
378 Examples: |
|
379 @code |
|
380 #include <string.h> |
|
381 #include <stdio.h> |
|
382 #include <time.h> |
|
383 #include <locale.h> |
|
384 int main() |
|
385 { |
|
386 struct tm tm; |
|
387 char buf[255]; |
|
388 char *locale; |
|
389 locale = setlocale(LC_TIME,"en_GB.ISO-8859-1"); |
|
390 if( locale != NULL) |
|
391 { |
|
392 strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;); |
|
393 printf("sec = %d min = %d hours = %d |
|
394 Year = %d Month = %d day = %d |
|
395 ",\ |
|
396 tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday); |
|
397 strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;); |
|
398 puts(buf); |
|
399 strptime("Mon","%a", &tm;); |
|
400 strftime(buf, sizeof(buf), "%a", &tm;); |
|
401 puts(buf); |
|
402 } |
|
403 else |
|
404 printf("Failed to set locale |
|
405 "); |
|
406 } |
|
407 |
|
408 @endcode |
|
409 Output |
|
410 @code |
|
411 sec = 1 min = 31 hours = 18 |
|
412 Year = 101 Month = 10 day = 12 |
|
413 12 November 2001 18:31:01 |
|
414 Mon |
|
415 |
|
416 @endcode |
|
417 @see printf() |
|
418 @see ctime() |
|
419 @see strptime() |
|
420 @see wcsftime() |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 @publishedAll |
|
426 @externallyDefinedApi |
|
427 */ |
|
428 |
|
429 /** @fn time(time_t *p) |
|
430 @param p |
|
431 @return On success the value of time in seconds since the Epoch is returned. On error |
|
432 (time_t)(-1) is returned and errno is set appropriately. |
|
433 |
|
434 The time function returns the value of time in seconds since 0 hours, 0 |
|
435 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time. If an error occurs, time returns the value ( time_t)(-1) . |
|
436 |
|
437 The return value is also stored in * p , |
|
438 provided that p is non-null. |
|
439 |
|
440 Examples: |
|
441 @code |
|
442 /* |
|
443 * Detailed description : sample usage of time system call |
|
444 */ |
|
445 #include <time.h> |
|
446 int main() |
|
447 { |
|
448 time_t Time ; |
|
449 if(time(&Time;) < 0 ) |
|
450 { |
|
451 printf("Time system call failed |
|
452 ") ; |
|
453 return -1 ; |
|
454 } |
|
455 printf("Time value is %u |
|
456 " , Time) ; |
|
457 return 0 ; |
|
458 } |
|
459 |
|
460 @endcode |
|
461 Output |
|
462 @code |
|
463 |
|
464 Time value is 1176916948 |
|
465 |
|
466 @endcode |
|
467 @see gettimeofday() |
|
468 @see ctime() |
|
469 |
|
470 |
|
471 Bugs: |
|
472 |
|
473 Neither -isoC-99 nor -p1003.1-2001 requires time to set errno on failure; thus, it is impossible for an application to distinguish |
|
474 the valid time value -1 (representing the last UTC second of 1969) |
|
475 from the error return value. |
|
476 |
|
477 Systems conforming to earlier versions of the C and POSIX standards (including older versions of ) |
|
478 did not set * p in the error case. |
|
479 |
|
480 |
|
481 @publishedAll |
|
482 @externallyDefinedApi |
|
483 */ |
|
484 |
|
485 /** @fn tzset(void) |
|
486 |
|
487 The tzset function |
|
488 initializes time conversion information used by the library routine localtime . |
|
489 The environment variable TZ specifies how this is done. |
|
490 |
|
491 If TZ does not appear in the environment, the best available approximation |
|
492 to local wall clock time is used. |
|
493 |
|
494 If TZ appears in the environment but its value is a null string, Coordinated |
|
495 Universal Time ( UTC ) |
|
496 is used (without leap second correction). |
|
497 |
|
498 |
|
499 |
|
500 Examples: |
|
501 @code |
|
502 #include <time.h> |
|
503 #include <stdio.h> |
|
504 int main(){ |
|
505 time_t t; |
|
506 char* c_time; |
|
507 tzset(); //Call tzset |
|
508 c_time = ctime (&t;); //Get time-string using ctime for Epoc time |
|
509 printf ("Time from ctime after tzset: %s", c_time); |
|
510 return 0; |
|
511 } |
|
512 |
|
513 @endcode |
|
514 Output |
|
515 @code |
|
516 Time from ctime after tzset: Sun Apr 7 02:24:08 1974 |
|
517 |
|
518 @endcode |
|
519 @see gettimeofday() |
|
520 @see ctime() |
|
521 @see getenv() |
|
522 @see time() |
|
523 |
|
524 |
|
525 @see gettimeofday() |
|
526 @see ctime() |
|
527 @see getenv() |
|
528 @see time() |
|
529 @see gettimeofday() |
|
530 @see ctime() |
|
531 @see getenv() |
|
532 @see time() |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 @publishedAll |
|
538 @externallyDefinedApi |
|
539 */ |
|
540 |
|
541 /** @fn clock_getres(clockid_t clock_id, struct timespec *res) |
|
542 @param clock_id |
|
543 @param res |
|
544 |
|
545 Refer to clock_gettime() for the documentation |
|
546 @see adjtime() |
|
547 @see ctime() |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 @publishedAll |
|
553 @externallyDefinedApi |
|
554 */ |
|
555 |
|
556 /** @fn clock_gettime(clockid_t clock_id, struct timespec *tp) |
|
557 @param clock_id |
|
558 @param tp |
|
559 |
|
560 Note: This description also covers the following functions - |
|
561 clock_settime() clock_getres() clock_getcpuclockid() |
|
562 |
|
563 @return All the above APIs return 0 on success and -1 on failure. |
|
564 |
|
565 @code |
|
566 #include < sys/time.h > as: |
|
567 @endcode |
|
568 The clock_gettime and clock_settime allow the calling process to retrieve or set the value used by a clock |
|
569 which is specified by clock_id. |
|
570 |
|
571 The clock_id argument can be one of four values: CLOCK_REALTIME for time |
|
572 that increments as a wall clock should, CLOCK_MONOTONIC which increments in |
|
573 SI seconds, CLOCK_VIRTUAL for time that increments only when the CPU is running |
|
574 in user mode on behalf of the calling process, or CLOCK_PROF for time that increments |
|
575 when the CPU is running in user or kernel mode. |
|
576 |
|
577 As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME |
|
578 is supported for all the clock-based APIs. |
|
579 |
|
580 The structure pointed to by tp is defined in |
|
581 @code |
|
582 #include <sys/time.h> as: |
|
583 @endcode |
|
584 |
|
585 @code |
|
586 struct timespec { |
|
587 time_ttv_sec;/* seconds */ |
|
588 longtv_nsec;/* and nanoseconds */ |
|
589 }; |
|
590 @endcode |
|
591 |
|
592 The resolution (granularity) of a clock is returned by the clock_getres system call. |
|
593 This value is placed in a (non-NULL) *tp. |
|
594 |
|
595 The clock_getcpuclockid system call returns ( in *clock_id ) the clock ID of the CPU-time clock of the process specified |
|
596 by pid. If pid is zero, the clock ID of the CPU-time clock of the process making |
|
597 the call is returned. |
|
598 |
|
599 Examples: |
|
600 @code |
|
601 #include <time.h> |
|
602 #include <stdio.h> |
|
603 int clock_user() |
|
604 { |
|
605 struct timespec tp; |
|
606 int retval; |
|
607 clockid_t clockid; |
|
608 clock_getres (CLOCK_REALTIME, &tp;); // Call clock_getres |
|
609 printf ("Real time-clock resolution is %d seconds and %d nanoseconds |
|
610 ", tp.tv_sec, tp.tv_nsec); |
|
611 clock_getcpuclockid (0 ,&clockid;); // Call clock_getcpuclockid with pid = 0 |
|
612 printf ("The clock id for the current process is %d |
|
613 ", clockid); |
|
614 tp.tv_sec = 0; |
|
615 tp.tv_nsec = 100; |
|
616 retval = clock_settime (CLOCK_REALTIME, &tp;); // Call clock_settime with 100ns |
|
617 printf ("clock_settime returned %d |
|
618 ", retval); |
|
619 clock_gettime (CLOCK_REALTIME, &tp;); // Call clock_gettime to fill tp |
|
620 printf ("Time from real time-clock is %d seconds and %d nanoseconds |
|
621 ", tp.tv_sec, tp.tv_nsec); |
|
622 return 0; |
|
623 } |
|
624 |
|
625 @endcode |
|
626 Output |
|
627 @code |
|
628 Real time-clock resolution is 0 seconds and 1000000 nanoseconds |
|
629 The clock id for the current process is 0 |
|
630 clock_settime returned 0 |
|
631 Time from real time-clock is 0 seconds and 70663000 nanoseconds |
|
632 |
|
633 @endcode |
|
634 @see adjtime() |
|
635 @see ctime() |
|
636 |
|
637 @publishedAll |
|
638 @externallyDefinedApi |
|
639 */ |
|
640 |
|
641 /** @fn clock_settime(clockid_t clock_id, const struct timespec *tp) |
|
642 @param clock_id |
|
643 @param tp |
|
644 |
|
645 Refer to clock_gettime() for the documentation |
|
646 |
|
647 @see adjtime() |
|
648 @see ctime() |
|
649 |
|
650 @capability Deferred @ref User::SetUTCTime(const TTime &aUTCTime) |
|
651 |
|
652 @publishedAll |
|
653 @externallyDefinedApi |
|
654 */ |
|
655 |
|
656 /** @fn nanosleep(const struct timespec *req, struct timespec *rem) |
|
657 @param req |
|
658 @param rem |
|
659 @return If the nanosleep system call returns because the requested time has elapsed, the value |
|
660 returned will be zero. If rem is non- NULL, the timespec structure it references is updated to contain the |
|
661 unslept amount (the request time minus the time actually slept). |
|
662 |
|
663 The nanosleep system call |
|
664 causes the process to sleep for the specified time. |
|
665 Currently only microsecond sleep resolution can be obtained. |
|
666 |
|
667 |
|
668 |
|
669 Examples: |
|
670 @code |
|
671 /* |
|
672 * Detailed description: Sample usage of nanosleep system call. |
|
673 */ |
|
674 #include <stdio.h> |
|
675 #include <time.h> |
|
676 int main() |
|
677 { |
|
678 struct timespec tim, tim2; |
|
679 tim.tv_sec = 1; |
|
680 tim.tv_nsec = 500; |
|
681 if(nanosleep(&tim; , &tim2;) < 0 ) { |
|
682 printf("Nano sleep system call failed |
|
683 "); |
|
684 return -1; |
|
685 } |
|
686 printf("Nano sleep successfull |
|
687 "); |
|
688 return 0; |
|
689 } |
|
690 |
|
691 @endcode |
|
692 Output |
|
693 @code |
|
694 Nano sleep successfull |
|
695 |
|
696 @endcode |
|
697 @see sleep() |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 @publishedAll |
|
703 @externallyDefinedApi |
|
704 */ |
|
705 |
|
706 /** @fn clock_getcpuclockid(pid_t pid, clockid_t* clock_id) |
|
707 @param pid |
|
708 @param clock_id |
|
709 |
|
710 Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME |
|
711 is supported for all the clock-based APIs. Any value for pid except "0" is considered as invalid |
|
712 and for "0" the supported 'clock_id' i.e, CLOCK_REALTIME is returned. |
|
713 |
|
714 Refer to clock_gettime() for the documentation |
|
715 @see adjtime() |
|
716 @see ctime() |
|
717 |
|
718 @publishedAll |
|
719 @externallyDefinedApi |
|
720 */ |
|
721 |
|
722 /** @fn clock_nanosleep (clockid_t clock_id, int flags, |
|
723 const struct timespec *rqtp, struct timespec *rmtp) |
|
724 @param clock_id |
|
725 @param flags |
|
726 @param rqtp |
|
727 @param rmtp |
|
728 |
|
729 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/clock_nanosleep.html |
|
730 |
|
731 Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME |
|
732 is supported for all the clock-based APIs. |
|
733 |
|
734 @publishedAll |
|
735 @externallyDefinedApi |
|
736 */ |
|
737 |
|
738 /** @fn asctime_r(const struct tm *tm, char *buf) |
|
739 @param tm |
|
740 @param buf |
|
741 |
|
742 Refer to ctime() for the documentation |
|
743 @see gettimeofday() |
|
744 @see getenv() |
|
745 @see time() |
|
746 @see tzset() |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 @publishedAll |
|
752 @externallyDefinedApi |
|
753 */ |
|
754 |
|
755 /** @fn ctime_r(const time_t *clock, char *buf) |
|
756 @param clock |
|
757 @param buf |
|
758 |
|
759 Refer to ctime() for the documentation |
|
760 @see gettimeofday() |
|
761 @see getenv() |
|
762 @see time() |
|
763 @see tzset() |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 @publishedAll |
|
769 @externallyDefinedApi |
|
770 */ |
|
771 |
|
772 /** @fn gmtime_r(const time_t *clock, struct tm *result) |
|
773 @param clock |
|
774 @param result |
|
775 |
|
776 Refer to ctime() for the documentation |
|
777 @see gettimeofday() |
|
778 @see getenv() |
|
779 @see time() |
|
780 @see tzset() |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 @publishedAll |
|
786 @externallyDefinedApi |
|
787 */ |
|
788 |
|
789 |
|
790 /** @fn localtime_r(const time_t *clock, struct tm *result) |
|
791 @param clock |
|
792 @param result |
|
793 |
|
794 Refer to ctime() for the documentation |
|
795 @see gettimeofday() |
|
796 @see getenv() |
|
797 @see time() |
|
798 @see tzset() |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 @publishedAll |
|
804 @externallyDefinedApi |
|
805 */ |
|
806 |
|
807 |
|
808 /** @fn strptime(const char * buf, const char * fmt, struct tm * tm) |
|
809 @param buf |
|
810 @param fmt |
|
811 @param tm |
|
812 @return Upon successful completion, strptime returns the pointer to the first character in buf that has not been required to satisfy the specified conversions in fmt . |
|
813 It returns NULL if one of the conversions failed. |
|
814 |
|
815 The strptime function parses the string in the buffer buf according to the string pointed to by fmt , |
|
816 and fills in the elements of the structure pointed to by tm . |
|
817 The resulting values will be relative to the local time zone. |
|
818 Thus, it can be considered the reverse operation of strftime . |
|
819 |
|
820 The fmt string consists of zero or more conversion specifications and |
|
821 ordinary characters. |
|
822 All ordinary characters are matched exactly with the buffer, where |
|
823 white space in the fmt string will match any amount of white space |
|
824 in the buffer. |
|
825 All conversion specifications are identical to those described in strftime . |
|
826 |
|
827 Two-digit year values, including formats \%y and \%D , |
|
828 are now interpreted as beginning at 1969 per POSIX requirements. |
|
829 Years 69-00 are interpreted in the 20th century (1969-2000), years |
|
830 01-68 in the 21st century (2001-2068). |
|
831 |
|
832 If the fmt string does not contain enough conversion specifications to completely |
|
833 specify the resulting struct tm , |
|
834 the unspecified members of tm are left untouched. |
|
835 For example, if format is "\%H:\%M:\%S", |
|
836 only tm_hour , tm_sec and tm_min will be modified. |
|
837 If time relative to today is desired, initialize the tm structure with today's date before passing it to strptime . |
|
838 |
|
839 Examples: |
|
840 @code |
|
841 #include <string.h> |
|
842 #include <stdio.h> |
|
843 #include <time.h> |
|
844 #include <locale.h> |
|
845 int main() |
|
846 { |
|
847 struct tm tm; |
|
848 char buf[255]; |
|
849 char *locale; |
|
850 locale = setlocale(LC_TIME,"en_GB.ISO-8859-1"); |
|
851 if( locale != NULL) |
|
852 { |
|
853 strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;); |
|
854 printf("sec = %d min = %d hours = %d |
|
855 Year = %d Month = %d day = %d |
|
856 ", |
|
857 tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday); |
|
858 strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;); |
|
859 puts(buf); |
|
860 strptime("Mon","%a", &tm;); |
|
861 strftime(buf, sizeof(buf), "%a", &tm;); |
|
862 puts(buf); |
|
863 } |
|
864 else |
|
865 printf("Failed to set locale"); |
|
866 } |
|
867 |
|
868 @endcode |
|
869 Output |
|
870 @code |
|
871 sec = 1 min = 31 hours = 18 |
|
872 Year = 101 Month = 10 day = 12 |
|
873 12 November 2001 18:31:01 |
|
874 Mon |
|
875 |
|
876 @endcode |
|
877 @see scanf() |
|
878 @see strftime() |
|
879 |
|
880 |
|
881 Bugs: |
|
882 |
|
883 Both the \%e and \%l format specifiers may incorrectly scan one too many digits |
|
884 if the intended values comprise only a single digit |
|
885 and that digit is followed immediately by another digit. |
|
886 Both specifiers accept zero-padded values, |
|
887 even though they are both defined as taking unpadded values. |
|
888 |
|
889 The \%p format specifier has no effect unless it is parsed after hour-related specifiers. |
|
890 Specifying \%l without \%p will produce undefined results. |
|
891 Note that 12AM |
|
892 (ante meridiem) |
|
893 is taken as midnight |
|
894 and 12PM |
|
895 (post meridiem) |
|
896 is taken as noon. |
|
897 |
|
898 The \%U and \%W format specifiers accept any value within the range 00 to 53 |
|
899 without validating against other values supplied (like month |
|
900 or day of the year, for example). |
|
901 |
|
902 The \%Z format specifier only accepts time zone abbreviations of the local time zone, |
|
903 or the value "GMT". |
|
904 This limitation is because of ambiguity due to of the over loading of time |
|
905 zone abbreviations. |
|
906 One such example is EST which is both Eastern Standard Time and Eastern Australia Summer Time. |
|
907 |
|
908 The strptime function does not correctly handle multibyte characters in the fmt argument. |
|
909 |
|
910 |
|
911 @publishedAll |
|
912 @externallyDefinedApi |
|
913 */ |
|
914 |
|
915 /** @fn timer_create (clockid_t __clock_id, |
|
916 struct sigevent *__restrict __evp, |
|
917 timer_t *__restrict __timerid) |
|
918 @param __clock_id |
|
919 @param __evp |
|
920 @param __timerid |
|
921 |
|
922 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_create.html |
|
923 |
|
924 Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME |
|
925 is supported for all the clock-based APIs. |
|
926 |
|
927 @see timer_settime() |
|
928 @see timer_delete() |
|
929 |
|
930 @publishedAll |
|
931 @externallyDefinedApi |
|
932 */ |
|
933 |
|
934 /** @fn timer_delete (timer_t __timerid) |
|
935 @param __timerid |
|
936 |
|
937 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_delete.html |
|
938 |
|
939 @see timer_create() |
|
940 @see timer_settime() |
|
941 |
|
942 @publishedAll |
|
943 @externallyDefinedApi |
|
944 */ |
|
945 |
|
946 /** @fn timer_settime(timer_t __timerid, int __flags, |
|
947 const struct itimerspec *__restrict __value, |
|
948 struct itimerspec *__restrict __ovalue) |
|
949 @param __timerid |
|
950 @param __flags |
|
951 @param __value |
|
952 @param __ovalue |
|
953 |
|
954 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_settime.html |
|
955 |
|
956 Note: This description also covers the timer_gettime() and timer_getoverrun() functions. |
|
957 |
|
958 Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME |
|
959 is supported for all the clock-based APIs. At the user level, Symbian OS supports upto a |
|
960 maximum of 1 ms resolution timer (RTimer::HighRes ()) upon which the timer emulation solution is based. |
|
961 As the re-registrations for a periodic timer happen in the user mode, the timer expirations |
|
962 might show up a possible unspecified latency. |
|
963 |
|
964 Examples: |
|
965 @code |
|
966 /* |
|
967 * Detailed description: |
|
968 */ |
|
969 #include <time.h> |
|
970 #include <stdio.h> |
|
971 #include <signal.h> |
|
972 #include <pthread.h> |
|
973 #include <unistd.h> |
|
974 |
|
975 void sighler (union sigval val) |
|
976 { |
|
977 printf("In the handler with val:%d\n", val.sival_int); |
|
978 } |
|
979 |
|
980 int main() |
|
981 { |
|
982 timer_t timerid; |
|
983 struct sigevent sig; |
|
984 |
|
985 pthread_attr_t attr; |
|
986 pthread_attr_init( &attr ); |
|
987 |
|
988 sig.sigev_notify = SIGEV_THREAD; |
|
989 sig.sigev_notify_function = sighler; |
|
990 sig.sigev_value.sival_int =20; |
|
991 sig.sigev_notify_attributes = &attr; |
|
992 |
|
993 if(0 == timer_create(CLOCK_REALTIME, &sig, &timerid)) |
|
994 { |
|
995 struct itimerspec in, out; |
|
996 |
|
997 in.it_value.tv_sec = 1; |
|
998 in.it_value.tv_nsec = 0; |
|
999 |
|
1000 in.it_interval.tv_sec = 0; |
|
1001 in.it_interval.tv_nsec = 0; |
|
1002 |
|
1003 if(0 == timer_settime(timerid, 0, &in, &out)) |
|
1004 { |
|
1005 sleep(3); //wait for the timer expirations... |
|
1006 } |
|
1007 else |
|
1008 { |
|
1009 printf("timer_settime () failed with err:%d\n", errno); |
|
1010 } |
|
1011 |
|
1012 timer_delete(timerid); |
|
1013 } |
|
1014 else |
|
1015 { |
|
1016 printf("timer_create () failed with err:%d\n", errno); |
|
1017 } |
|
1018 |
|
1019 return 0; |
|
1020 } |
|
1021 |
|
1022 @endcode |
|
1023 Output |
|
1024 @code |
|
1025 In the handler with val:20 |
|
1026 |
|
1027 @endcode |
|
1028 @see timer_create() |
|
1029 @see timer_delete() |
|
1030 @see clock_gettime() |
|
1031 |
|
1032 @publishedAll |
|
1033 @externallyDefinedApi |
|
1034 */ |
|
1035 |
|
1036 /** @fn timer_gettime (timer_t __timerid, struct itimerspec *__value) |
|
1037 @param __timerid |
|
1038 @param __value |
|
1039 |
|
1040 For documentation refer to timer_settime(). |
|
1041 |
|
1042 @see timer_create() |
|
1043 @see timer_delete() |
|
1044 |
|
1045 @publishedAll |
|
1046 @externallyDefinedApi |
|
1047 */ |
|
1048 |
|
1049 /** @fn timer_getoverrun (timer_t __timerid) |
|
1050 @param __timerid |
|
1051 |
|
1052 For documentation refer to timer_settime(). |
|
1053 |
|
1054 @see timer_create() |
|
1055 @see timer_delete() |
|
1056 |
|
1057 @publishedAll |
|
1058 @externallyDefinedApi |
|
1059 */ |
|
1060 |
|
1061 /** @def CLOCK_REALTIME |
|
1062 |
|
1063 This clock represents the realtime clock for the system. |
|
1064 |
|
1065 @publishedAll |
|
1066 @externallyDefinedApi |
|
1067 */ |
|
1068 |
|
1069 /** @def CLOCK_VIRTUAL |
|
1070 |
|
1071 This clock represents the amount of time (in seconds and nanoseconds) that the calling process has spent executing code in the user's context. It is a per-process clock. It cannot be set by the user. |
|
1072 |
|
1073 @publishedAll |
|
1074 @externallyDefinedApi |
|
1075 */ |
|
1076 |
|
1077 /** @def TIMER_ABSTIME |
|
1078 |
|
1079 absolute timer |
|
1080 |
|
1081 @publishedAll |
|
1082 @externallyDefinedApi |
|
1083 */ |
|
1084 |
|
1085 /** @struct tm |
|
1086 |
|
1087 Contains the following members, |
|
1088 |
|
1089 @publishedAll |
|
1090 @externallyDefinedApi |
|
1091 */ |
|
1092 |
|
1093 /** @var tm::tm_sec |
|
1094 seconds after the minute |
|
1095 */ |
|
1096 |
|
1097 /** @var tm::tm_min |
|
1098 minutes after the hour |
|
1099 */ |
|
1100 |
|
1101 /** @var tm::tm_hour |
|
1102 hours since midnight |
|
1103 */ |
|
1104 |
|
1105 /** @var tm::tm_mday |
|
1106 day of the month |
|
1107 */ |
|
1108 |
|
1109 /** @var tm::tm_mon |
|
1110 months since January |
|
1111 */ |
|
1112 |
|
1113 /** @var tm::tm_year |
|
1114 years since 1900 |
|
1115 */ |
|
1116 |
|
1117 /** @var tm::tm_wday |
|
1118 days since Sunday |
|
1119 */ |
|
1120 |
|
1121 /** @var tm::tm_yday |
|
1122 days since January 1 |
|
1123 */ |
|
1124 |
|
1125 /** @var tm::tm_isdst |
|
1126 Daylight Savings Time flag |
|
1127 */ |
|
1128 |
|
1129 /** @var tm::tm_gmtoff |
|
1130 offset from UTC in seconds |
|
1131 */ |
|
1132 |
|
1133 /** @var tm::tm_zone |
|
1134 timezone abbreviation |
|
1135 */ |
|
1136 |
|
1137 |
|
1138 /** @fn time_t timegm(struct tm *tmp) |
|
1139 |
|
1140 @param tmp |
|
1141 |
|
1142 Description: |
|
1143 This function is inverses for gmtime. |
|
1144 Converts struct tm to time_t, assuming the data in tm is UTC rather than local timezone. |
|
1145 |
|
1146 @see gmtime() |
|
1147 @see localtime() |
|
1148 @see mktime() |
|
1149 @see tzset() |
|
1150 |
|
1151 @publishedAll |
|
1152 @externallyDefinedApi |
|
1153 */ |