Changeset 3a58347 in mainline
- Timestamp:
- 2012-08-13T14:15:57Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 45cbcaf4
- Parents:
- 43e660c
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/time.c
r43e660c r3a58347 50 50 #include <assert.h> 51 51 #include <unistd.h> 52 #include <loc.h> 53 #include <device/clock_dev.h> 54 #include <malloc.h> 52 55 53 56 #define ASCTIME_BUF_LEN 26 … … 480 483 */ 481 484 int gettimeofday(struct timeval *tv, struct timezone *tz) 485 { 486 int rc; 487 struct tm t; 488 category_id_t cat_id; 489 size_t svc_cnt; 490 service_id_t *svc_ids = NULL; 491 service_id_t svc_id; 492 char *svc_name = NULL; 493 494 static async_sess_t *clock_conn = NULL; 495 496 if (tz) { 497 tz->tz_minuteswest = 0; 498 tz->tz_dsttime = DST_NONE; 499 } 500 501 if (clock_conn == NULL) { 502 rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING); 503 if (rc != EOK) 504 goto ret_uptime; 505 506 rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt); 507 if (rc != EOK) 508 goto ret_uptime; 509 510 if (svc_cnt == 0) 511 goto ret_uptime; 512 513 rc = loc_service_get_name(svc_ids[0], &svc_name); 514 if (rc != EOK) 515 goto ret_uptime; 516 517 rc = loc_service_get_id(svc_name, &svc_id, 0); 518 if (rc != EOK) 519 goto ret_uptime; 520 521 clock_conn = loc_service_connect(EXCHANGE_SERIALIZE, 522 svc_id, IPC_FLAG_BLOCKING); 523 if (!clock_conn) 524 goto ret_uptime; 525 } 526 527 rc = clock_dev_time_get(clock_conn, &t); 528 if (rc != EOK) 529 goto ret_uptime; 530 531 tv->tv_usec = 0; 532 tv->tv_sec = mktime(&t); 533 534 free(svc_name); 535 free(svc_ids); 536 537 return EOK; 538 539 ret_uptime: 540 541 free(svc_name); 542 free(svc_ids); 543 544 return getuptime(tv); 545 } 546 547 int getuptime(struct timeval *tv) 482 548 { 483 549 if (ktime == NULL) { … … 501 567 } 502 568 503 if (tz) {504 tz->tz_minuteswest = 0;505 tz->tz_dsttime = DST_NONE;506 }507 508 569 sysarg_t s2 = ktime->seconds2; 509 570 … … 519 580 } else 520 581 tv->tv_sec = s1; 521 582 522 583 return 0; 523 584 } -
uspace/lib/c/include/sys/time.h
r43e660c r3a58347 76 76 extern int tv_gteq(struct timeval *tv1, struct timeval *tv2); 77 77 extern int gettimeofday(struct timeval *tv, struct timezone *tz); 78 extern int getuptime(struct timeval *tv); 78 79 79 80 extern void udelay(useconds_t);
Note:
See TracChangeset
for help on using the changeset viewer.