1 /* 2 * systemuhr.c 3 * 4 * Autor: H.Drachenfels 5 * Erstellt am: 20.1.2018 6 */
7
8 #include "systemuhr.h"
9 #include "uhr_impl.h"
10
11 #include <stdlib.h>
12 #include <time.h>
13
14 struct systemuhr
15 {
16 uhr interface;
17 };
18
19 static void destruct(uhr * const u);
20 static void ablesen(const uhr * const u, unsigned *s, unsigned *m);
21
22 uhr *new_systemuhr()
23 {
24 struct systemuhr *this_p = (struct systemuhr*) malloc(sizeof (struct systemuhr));
25 if (!this_p) return NULL;
26
27 this_p->interface.destruct = destruct;
28 this_p->interface.ablesen = ablesen;
29 return &this_p->interface;
30 }
31
32 static void destruct(uhr * const u)
33 {
34 free(u);
35 }
36
37 static void ablesen(const uhr * const u, unsigned *s, unsigned *m)
38 {
39 time_t t = time(0);
40 struct tm *lt = localtime(&t);
41
42 *s = lt->tm_hour;
43
44 if (m)
45 {
46 *m = lt->tm_min;
47 }
48 }
49