Debian Codegraph @

src/cronoutils.h

raw symbols SCIP
1 /* ====================================================================
2 * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the Apache Group
19 * for use in the Apache HTTP server project (http://www.apache.org/)."
20 *
21 * 4. The names "Apache Server" and "Apache Group" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * [email protected].
25 *
26 * 5. Products derived from this software may not be called "Apache"
27 * nor may "Apache" appear in their names without prior written
28 * permission of the Apache Group.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the Apache Group
33 * for use in the Apache HTTP server project (http://www.apache.org/)."
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Group and was originally based
51 * on public domain software written at the National Center for
52 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
53 * For more information on the Apache Group and the Apache HTTP server
54 * project, please see <http://www.apache.org/>.
55 *
56 */
57 /*
58 * cronoutils -- utilities for the cronolog program
59 *
60 * Copyright (c) 1996-1999 by Ford & Mason Ltd
61 *
62 * This software was submitted by Ford & Mason Ltd to the Apache
63 * Software Foundation in December 1999. Future revisions and
64 * derivatives of this source code must acknowledge Ford & Mason Ltd
65 * as the original contributor of this module. All other licensing
66 * and usage conditions are those of the Apache Software Foundation.
67 *
68 * Originally written by Andrew Ford <[email protected]>
69 *
70 * For platforms that don't declare getopt() in header files the symbol
71 * NEED_GETOPT_DEFS can be defined and declarations are provided here.
72 */
73
74 #if !defined(_CRONOUTILS_H_)
75
76 /* Header files */
77
78 #include <ctype.h>
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <stdarg.h>
82 #include <errno.h>
83 #include <fcntl.h>
84 #include <limits.h>
85 #ifndef _WIN32
86 #include <unistd.h>
87 #else
88 #include <io.h>
89 #include <direct.h>
90 #endif
91 #include <string.h>
92 #include <sys/types.h>
93 #include <sys/stat.h>
94
95
96 #if TIME_WITH_SYS_TIME
97 # include <sys/time.h>
98 # include <time.h>
99 #else
100 # if HAVE_SYS_TIME_H
101 # include <sys/time.h>
102 # else
103 # include <time.h>
104 # endif
105 #endif
106
107 #include "config.h"
108
109 #ifdef _WIN32
110 #define mode_t int
111
112 #define open _open
113 #define close _close
114 #define read _read
115 #define write _write
116 #define mkdir _mkdir
117 #endif
118
119 #if !HAVE_LOCALIME_R
120 struct tm *localtime_r(const time_t *, struct tm *);
121 #endif
122
123 /* Some operating systems don't declare getopt() */
124
125 #ifdef NEED_GETOPT_DEFS
126 int getopt(int argc, char * const argv[], const char *optstring);
127 extern char *optarg;
128 extern int optind, opterr, optopt;
129 #endif
130
131
132 /* Constants for seconds per minute, hour, day and week */
133
134 #define SECS_PER_MIN 60
135 #define SECS_PER_HOUR (60 * SECS_PER_MIN)
136 #define SECS_PER_DAY (24 * SECS_PER_HOUR)
137 #define SECS_PER_WEEK (7 * SECS_PER_DAY)
138
139
140 /* Allowances for daylight saving time changes and leap second.
141 * Used for calculating the start of the next period.
142 * (does Unix actually know about leap seconds?)
143 */
144
145 #define LEAP_SECOND_ALLOWANCE 2
146 #define DST_ALLOWANCE (3 * SECS_PER_HOUR + LEAP_SECOND_ALLOWANCE)
147
148
149 /* If log files are not rotated then this is when the first file
150 * should be closed. */
151
152 #define FAR_DISTANT_FUTURE LONG_MAX
153
154
155 /* How often the log is rotated */
156
157 typedef enum
158 {
159 PER_SECOND, PER_MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY, ONCE_ONLY, UNKNOWN, INVALID_PERIOD
160 }
161 PERIODICITY;
162
163
164 /* Function prototypes */
165
166 void create_subdirs(char *);
167 void create_link(char *, const char *, mode_t, const char *);
168 PERIODICITY determine_periodicity(char *);
169 PERIODICITY parse_timespec(char *optarg, int *p_period_multiple);
170 time_t start_of_next_period(time_t, PERIODICITY, int);
171 time_t start_of_this_period(time_t, PERIODICITY, int);
172 void print_debug_msg(char *msg, ...);
173 time_t parse_time(char *time_str, int);
174 char *timestamp(time_t thetime);
175
176
177 /* Global variables */
178
179 extern FILE *debug_file;
180 extern char *periods[];
181 extern int period_seconds[];
182
183
184 /* Usage message and DEBUG macro.
185 */
186
187 #ifdef DEBUG
188 #undef DEBUG
189 #endif
190
191 #define DEBUG(msg_n_args) do { if (debug_file) print_debug_msg msg_n_args; } while (0)
192
193 #endif