sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libast / common / tm / tmxduration.c
blob64483c4f0c542ccf66b33a00f35ec7e34cab72f9
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 #include <tmx.h>
25 #include <ctype.h>
28 * parse duration expression in s and return Time_t value
29 * if non-null, e points to the first unused char in s
30 * returns 0 with *e==s on error
33 Time_t
34 tmxduration(const char* s, char** e)
36 Time_t ns;
37 Time_t ts;
38 Time_t now;
39 char* last;
40 char* t;
41 char* x;
42 Sfio_t* f;
43 int i;
45 now = TMX_NOW;
46 while (isspace(*s))
47 s++;
48 if (*s == 'P' || *s == 'p')
49 ns = tmxdate(s, &last, now) - now;
50 else
52 ns = strtod(s, &last) * TMX_RESOLUTION;
53 if (*last && (f = sfstropen()))
55 sfprintf(f, "exact %s", s);
56 t = sfstruse(f);
57 ts = tmxdate(t, &x, now);
58 if ((i = x - t - 6) > (last - s))
60 last = (char*)s + i;
61 ns = ts - now;
63 else
65 sfprintf(f, "p%s", s);
66 t = sfstruse(f);
67 ts = tmxdate(t, &x, now);
68 if ((i = x - t - 1) > (last - s))
70 last = (char*)s + i;
71 ns = ts - now;
74 sfstrclose(f);
77 if (e)
78 *e = last;
79 return ns;