]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/csup/misc.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / csup / misc.h
1 /*-
2  * Copyright (c) 2003-2006, Maxime Henrion <mux@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _MISC_H_
29 #define _MISC_H_
30
31 #include <openssl/md5.h>
32
33 #include <sys/types.h>
34
35 /* If we're not compiling in a C99 environment, define the C99 types. */
36 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
37
38 #ifdef uint32_t
39 #undef uint32_t
40 #endif
41 #define uint32_t        u_int32_t
42
43 #ifdef uint16_t
44 #undef uint16_t
45 #endif
46 #define uint16_t        u_int16_t
47
48 #ifdef uint8_t
49 #undef uint8_t
50 #endif
51 #define uint8_t         u_int8_t
52
53 #else
54 #include <stdint.h>
55 #endif
56
57 /* This is a GCC-specific keyword but some other compilers (namely icc)
58    understand it, and the code won't work if we can't disable padding
59    anyways. */
60 #undef __packed
61 #define __packed                __attribute__((__packed__))
62
63 /* We explicitely don't define this with icc because it defines __GNUC__
64    but doesn't support it. */
65 #undef __printflike
66 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && \
67     (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC__MINOR__ >= 7)
68 #define __printflike(fmtarg, firstvararg) \
69             __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
70 #else
71 #define __printflike(fmtarg, firstvararg)
72 #endif
73
74 /* Exit codes. */
75 #define STATUS_SUCCESS          0
76 #define STATUS_FAILURE          1
77 #define STATUS_TRANSIENTFAILURE 2
78 #define STATUS_INTERRUPTED      3
79
80 struct config;
81 struct stream;
82
83 /* Thread parameters. */
84 struct thread_args {
85         struct config *config;
86         struct stream *rd;
87         struct stream *wr;
88         int status;
89         char *errmsg;
90 };
91
92 /* Minimum size for MD5_File() and MD5_End() buffers. */
93 #define MD5_DIGEST_SIZE         33
94
95 #define min(a, b)               ((a) > (b) ? (b) : (a))
96 #define max(a, b)               ((a) < (b) ? (b) : (a))
97
98 struct backoff_timer;
99 struct pattlist;
100 struct tm;
101
102 int              asciitoint(const char *, int *, int);
103 int              lprintf(int, const char *, ...) __printflike(2, 3);
104 int              MD5_File(char *, char *);
105 void             MD5_End(char *, MD5_CTX *);
106 int              rcsdatetotm(const char *, struct tm *);
107 time_t           rcsdatetotime(const char *);
108 int              pathcmp(const char *, const char *);
109 size_t           commonpathlength(const char *, size_t, const char *, size_t);
110 const char      *pathlast(const char *);
111 int              isrcs(const char *, size_t *);
112 char            *checkoutpath(const char *, const char *);
113 char            *cvspath(const char *, const char *, int);
114 char            *atticpath(const char *, const char *);
115 char            *path_prefix(char *);
116 char            *path_first(char *);
117 int              mkdirhier(char *, mode_t);
118 char            *tempname(const char *);
119 void            *xmalloc(size_t);
120 void            *xrealloc(void *, size_t);
121 char            *xstrdup(const char *);
122 int              xasprintf(char **, const char *, ...) __printflike(2, 3);
123 int              rcsnum_cmp(char *, char *);
124 int              rcsrev_istrunk(char *);
125 char            *rcsrev_prefix(char *);
126
127 struct pattlist         *pattlist_new(void);
128 void                     pattlist_add(struct pattlist *, const char *);
129 char                    *pattlist_get(struct pattlist *, size_t);
130 size_t                   pattlist_size(struct pattlist *);
131 void                     pattlist_free(struct pattlist *);
132
133 struct backoff_timer    *bt_new(time_t, time_t, float, float);
134 time_t                   bt_get(struct backoff_timer *);
135 void                     bt_pause(struct backoff_timer *);
136 void                     bt_free(struct backoff_timer *);
137
138 #endif /* !_MISC_H_ */