El mié., nov. 1, 2017 8:48 PM, Eduardo A. Bustamante López < dual...@gmail.com> escribió:
> [...] > /* FIXME: do better validation */ > static int parse_timeval (const char *s, struct timeval *tv) { > char *ds; > timerclear(tv); > tv->tv_sec = strtol(s, &ds, 10); > if (ds && *ds == '.') { > tv->tv_usec = strtol(ds + 1, NULL, 10); > } > return 0; > } > > int timer_builtin (WORD_LIST *list) { [...] parse_timeval (s, &tv2); > timersub (&tv1, &tv2, &tv3); > snprintf (b2, 64, "%ld.%ld", tv3.tv_sec, tv3.tv_usec); > bind_variable (delta, b2, 0); > > update_value: > snprintf (b1, 64, "%ld.%ld", tv1.tv_sec, tv1.tv_usec); > bind_variable (current, b1, 0); > Heh, this is embarassing. Evidently, that is not the right way of parsing a timeval, or of storing it in a string (i.e. the tv_usec member). But at least it still works as a demo of how to approach the problem with loadable builtins. >