xref: /netbsd-src/external/bsd/ntp/dist/sntp/libopts/time.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: time.c,v 1.1.1.1 2009/12/13 16:57:22 kardel Exp $	*/
2 
3 
4 /*
5  *  Id: 63d3312044fd7854ad0995faea41c96f5185cb93
6  *  Time-stamp:      "2008-11-16 14:51:48 bkorb"
7  *
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
11  *
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.
15  *
16  *   The GNU Lesser General Public License, version 3 or later
17  *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
18  *
19  *   The Modified Berkeley Software Distribution License
20  *      See the file "COPYING.mbsd"
21  *
22  *  These files have the following md5sums:
23  *
24  *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
25  *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
26  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
27  */
28 
29 #ifndef HAVE_PARSE_DURATION
30 #include <time.h>
31 
32 static inline char *
33 ao_xstrdup(char const * pz)
34 {
35     char * str;
36     AGDUPSTR(str, pz, "time val str");
37     return str;
38 }
39 
40 #define xstrdup(_s) ao_xstrdup(_s)
41 
42 #include "parse-duration.c"
43 
44 #undef xstrdup
45 #endif
46 
47 /*=export_func  optionTimeVal
48  * private:
49  *
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 +
53  *
54  * doc:
55  *  Decipher a time duration value.
56 =*/
57 void
58 optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
59 {
60     long  val;
61 
62     if ((pOD->fOptState & OPTST_RESET) != 0)
63         return;
64 
65     val = parse_duration(pOD->optArg.argString);
66     if (errno != 0)
67         goto bad_time;
68 
69     if (pOD->fOptState & OPTST_ALLOC_ARG) {
70         AGFREE(pOD->optArg.argString);
71         pOD->fOptState &= ~OPTST_ALLOC_ARG;
72     }
73 
74     pOD->optArg.argInt = val;
75     return;
76 
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);
81 
82     pOD->optArg.argInt = ~0;
83 }
84 /*
85  * Local Variables:
86  * mode: C
87  * c-file-style: "stroustrup"
88  * indent-tabs-mode: nil
89  * End:
90  * end of autoopts/numeric.c */
91