Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / libopts / time.c
bloba877fd9368a24f36c4f0e82676899d884df2ce56
1 /* $NetBSD$ */
4 /*
5 * Id: 63d3312044fd7854ad0995faea41c96f5185cb93
6 * Time-stamp: "2008-11-16 14:51:48 bkorb"
8 * This file is part of AutoOpts, a companion to AutoGen.
9 * AutoOpts is free software.
10 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
12 * AutoOpts is available under any one of two licenses. The license
13 * in use must be one of these two and the choice is under the control
14 * of the user of the license.
16 * The GNU Lesser General Public License, version 3 or later
17 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
19 * The Modified Berkeley Software Distribution License
20 * See the file "COPYING.mbsd"
22 * These files have the following md5sums:
24 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
25 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
26 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
29 #ifndef HAVE_PARSE_DURATION
30 #include <time.h>
32 static inline char *
33 ao_xstrdup(char const * pz)
35 char * str;
36 AGDUPSTR(str, pz, "time val str");
37 return str;
40 #define xstrdup(_s) ao_xstrdup(_s)
42 #include "parse-duration.c"
44 #undef xstrdup
45 #endif
47 /*=export_func optionTimeVal
48 * private:
50 * what: process an option with a time value.
51 * arg: + tOptions* + pOpts + program options descriptor +
52 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
54 * doc:
55 * Decipher a time duration value.
56 =*/
57 void
58 optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
60 long val;
62 if ((pOD->fOptState & OPTST_RESET) != 0)
63 return;
65 val = parse_duration(pOD->optArg.argString);
66 if (errno != 0)
67 goto bad_time;
69 if (pOD->fOptState & OPTST_ALLOC_ARG) {
70 AGFREE(pOD->optArg.argString);
71 pOD->fOptState &= ~OPTST_ALLOC_ARG;
74 pOD->optArg.argInt = val;
75 return;
77 bad_time:
78 fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
79 if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
80 (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
82 pOD->optArg.argInt = ~0;
85 * Local Variables:
86 * mode: C
87 * c-file-style: "stroustrup"
88 * indent-tabs-mode: nil
89 * End:
90 * end of autoopts/numeric.c */