source: mainline/uspace/app/date/date.c@ f1abd6e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1abd6e was f1abd6e, checked in by Maurizio Lombardi <m.lombardi85@…>, 13 years ago

date: fix includes

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[cca5c8d]1/*
2 * Copyright (c) 2012 Maurizio Lombardi
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30#include <stdio.h>
[cf00f2e4]31#include <device/clock_dev.h>
32#include <errno.h>
33#include <loc.h>
[9f1328cd]34#include <time.h>
[f1abd6e]35#include <malloc.h>
[cf00f2e4]36
37#define NAME "date"
[cca5c8d]38
39int
40main(int argc, char **argv)
41{
[cf00f2e4]42 int rc;
43 category_id_t cat_id;
44 size_t svc_cnt;
45 service_id_t *svc_ids = NULL;
[8354ca6]46 service_id_t svc_id;
[cf00f2e4]47 char *svc_name = NULL;
[9f1328cd]48 struct tm t;
[cf00f2e4]49
50 /* Get the id of the clock category */
51 rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
52 if (rc != EOK) {
53 printf(NAME ": Cannot get clock category id\n");
54 goto exit;
55 }
56
57 /* Get the list of available services in the clock category */
58 rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
59 if (rc != EOK) {
60 printf(NAME ": Cannot get the list of services in category \
61 clock\n");
62 goto exit;
63 }
64
65 /* Check if the are available services in the clock category */
66 if (svc_cnt == 0) {
67 printf(NAME ": No available service found in \
68 the clock category\n");
69 goto exit;
70 }
71
72 /* Get the name of the clock service */
73 rc = loc_service_get_name(svc_ids[0], &svc_name);
74 if (rc != EOK) {
75 printf(NAME ": Cannot get the name of the service\n");
76 goto exit;
77 }
78
[8354ca6]79 /* Get the service id for the device */
80 rc = loc_service_get_id(svc_name, &svc_id, 0);
[9f1328cd]81 if (rc != EOK) {
[8354ca6]82 printf(NAME ": Cannot get the service id for device %s",
83 svc_name);
[9f1328cd]84 goto exit;
85 }
86
[8354ca6]87 /* Connect to the device */
88 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
89 svc_id, 0);
[9f1328cd]90 if (!sess) {
91 printf(NAME ": Cannot connect to the device\n");
92 goto exit;
93 }
94
[8354ca6]95 /* Read the current date/time */
[9f1328cd]96 rc = clock_dev_time_get(sess, &t);
97 if (rc != EOK) {
98 printf(NAME ": Cannot read the current time\n");
99 goto exit;
100 }
101
[aa04e81]102 printf("%02d/%02d/%d ", t.tm_mday, t.tm_mon + 1, 1900 + t.tm_year);
103 printf("%02d:%02d:%02d\n", t.tm_hour, t.tm_min, t.tm_sec);
[d73a56d]104
[cf00f2e4]105exit:
106 free(svc_name);
107 free(svc_ids);
108 return rc;
[cca5c8d]109}
110
Note: See TracBrowser for help on using the repository browser.