Mercurial > hg > toybox
comparison toys/pending/last.c @ 1296:314b1486d502 draft
Make last use common llist free function, minor cleanups.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 21 May 2014 07:01:16 -0500 |
parents | 29603c5a3317 |
children | b0a92be71368 |
comparison
equal
deleted
inserted
replaced
1295:114ec0ab161c | 1296:314b1486d502 |
---|---|
31 char *file; | 31 char *file; |
32 | 32 |
33 struct arg_list *list; | 33 struct arg_list *list; |
34 ) | 34 ) |
35 | 35 |
36 static void free_node(void *data) | |
37 { | |
38 void *arg = ((struct arg_list*)data)->arg; | |
39 | |
40 if (arg) free(arg); | |
41 free(data); | |
42 } | |
43 | |
44 static void free_list() | 36 static void free_list() |
45 { | 37 { |
46 if (TT.list) { | 38 if (TT.list) { |
47 llist_traverse(TT.list, free_node); | 39 llist_traverse(TT.list, free_arg_list); |
48 TT.list = NULL; | 40 TT.list = NULL; |
49 } | 41 } |
50 } | 42 } |
51 | 43 |
52 static void llist_add_node(struct arg_list **old, void *data) | 44 static void llist_add_node(struct arg_list **old, void *data) |
111 for (;;) { | 103 for (;;) { |
112 loc -= sizeof(ut); | 104 loc -= sizeof(ut); |
113 if(loc < 0) break; | 105 if(loc < 0) break; |
114 xlseek(fd, loc, SEEK_SET); | 106 xlseek(fd, loc, SEEK_SET); |
115 | 107 |
108 // Read next structure, determine type | |
116 xreadall(fd, &ut, sizeof(ut)); | 109 xreadall(fd, &ut, sizeof(ut)); |
117 *tm = ut.ut_tv.tv_sec; | 110 *tm = ut.ut_tv.tv_sec; |
118 if (*ut.ut_line == '~') { | 111 if (*ut.ut_line == '~') { |
119 if (!strcmp(ut.ut_user, "runlevel")) ut.ut_type = RUN_LVL; | 112 if (!strcmp(ut.ut_user, "runlevel")) ut.ut_type = RUN_LVL; |
120 else if (!strcmp(ut.ut_user, "reboot")) ut.ut_type = BOOT_TIME; | 113 else if (!strcmp(ut.ut_user, "reboot")) ut.ut_type = BOOT_TIME; |
192 loc -= sizeof(ut); | 185 loc -= sizeof(ut); |
193 if(loc < 0) break; | 186 if(loc < 0) break; |
194 xlseek(fd, loc, SEEK_SET); | 187 xlseek(fd, loc, SEEK_SET); |
195 } | 188 } |
196 | 189 |
197 xclose(fd); | 190 if (CFG_TOYBOX_FREE) { |
198 | 191 xclose(fd); |
199 if (CFG_TOYBOX_FREE) free_list(); | 192 free_list(); |
193 } | |
200 | 194 |
201 xprintf("\n%s begins %-24.24s\n", basename(file), ctime(tm)); | 195 xprintf("\n%s begins %-24.24s\n", basename(file), ctime(tm)); |
202 } | 196 } |