1 /*
2  *      cook - file construction tool
3  *      Copyright (C) 2007 Peter Miller;
4  *      All rights reserved.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 3 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program. If not, see
18  *      <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <common/ac/stdlib.h>
22 
23 #include <cook/id.h>
24 #include <cook/id/variable.h>
25 #include <cook/opcode/context.h>
26 #include <common/trace.h>
27 #include <common/ac/time.h>
28 #include <common/ts.h>
29 
30 /*
31  * NAME
32  *      ts_granularity
33  *
34  * SYNOPSIS
35  *      ts_granularity(int *granularity)
36  *
37  * DESCRIPTION
38  *      The ts_granularity function is used to get the filesystem
39  *      modtime granularity. For most operating systems, this is 1 second
40  *      but can vary.
41  *
42  *      Defaulting and clean-up are done here, also.
43  *      If absent, defaults to 1.
44  *
45  */
46 
47 time_t
ts_granularity(void)48 ts_granularity(void)
49 {
50     string_ty         *key;
51     id_ty             *idp;
52     string_list_ty    wl;
53     int               granularity;
54     opcode_context_ty *ocp;
55 
56     /*
57      * make sure the variable exists
58      */
59     trace(("ts_granularity()\n{\n"));
60 
61     key = str_from_c("timestamp_granularity");
62     ocp = opcode_context_new(0, 0);
63     idp = opcode_context_id_search(ocp, key);
64 
65     granularity = 1;
66 
67     if (idp)
68     {
69         id_variable_query(idp, &wl);
70         if (wl.nstrings == 1)
71         {
72             granularity = atoi(wl.string[0]->str_text);
73             if (granularity < 1)
74                 granularity = 1;
75         }
76         string_list_destructor(&wl);
77     }
78 
79     trace(("}\n"));
80 
81     return (time_t)granularity;
82 }
83