1156230Smux/*- 2156230Smux * Copyright (c) 2003-2006, Maxime Henrion <mux@FreeBSD.org> 3156230Smux * All rights reserved. 4156230Smux * 5156230Smux * Redistribution and use in source and binary forms, with or without 6156230Smux * modification, are permitted provided that the following conditions 7156230Smux * are met: 8156230Smux * 1. Redistributions of source code must retain the above copyright 9156230Smux * notice, this list of conditions and the following disclaimer. 10156230Smux * 2. Redistributions in binary form must reproduce the above copyright 11156230Smux * notice, this list of conditions and the following disclaimer in the 12156230Smux * documentation and/or other materials provided with the distribution. 13156230Smux * 14156230Smux * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15156230Smux * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16156230Smux * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17156230Smux * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18156230Smux * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19156230Smux * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20156230Smux * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21156230Smux * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22156230Smux * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23156230Smux * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24156230Smux * SUCH DAMAGE. 25156230Smux * 26156230Smux * $FreeBSD$ 27156230Smux */ 28156230Smux#ifndef _MISC_H_ 29156230Smux#define _MISC_H_ 30156230Smux 31228857Smarius#include <sys/types.h> 32228857Smarius 33228857Smarius#ifdef __FreeBSD__ 34228857Smarius#include <md5.h> 35228857Smarius#define MD5_DIGEST_LENGTH 16 36228857Smarius#define MD5_Init MD5Init 37228857Smarius#define MD5_Final MD5Final 38228857Smarius#define MD5_Update MD5Update 39228857Smarius#else 40156230Smux#include <openssl/md5.h> 41228857Smarius#endif 42156230Smux 43156230Smux/* If we're not compiling in a C99 environment, define the C99 types. */ 44156230Smux#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 45156230Smux 46156230Smux#ifdef uint32_t 47156230Smux#undef uint32_t 48156230Smux#endif 49156230Smux#define uint32_t u_int32_t 50156230Smux 51156230Smux#ifdef uint16_t 52156230Smux#undef uint16_t 53156230Smux#endif 54156230Smux#define uint16_t u_int16_t 55156230Smux 56156230Smux#ifdef uint8_t 57156230Smux#undef uint8_t 58156230Smux#endif 59156230Smux#define uint8_t u_int8_t 60156230Smux 61156230Smux#else 62156230Smux#include <stdint.h> 63156230Smux#endif 64156230Smux 65156230Smux/* This is a GCC-specific keyword but some other compilers (namely icc) 66156230Smux understand it, and the code won't work if we can't disable padding 67156230Smux anyways. */ 68156230Smux#undef __packed 69156230Smux#define __packed __attribute__((__packed__)) 70156230Smux 71156230Smux/* We explicitely don't define this with icc because it defines __GNUC__ 72156230Smux but doesn't support it. */ 73156230Smux#undef __printflike 74156230Smux#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ 75156230Smux (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC__MINOR__ >= 7) 76156230Smux#define __printflike(fmtarg, firstvararg) \ 77156230Smux __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 78156230Smux#else 79156230Smux#define __printflike(fmtarg, firstvararg) 80156230Smux#endif 81156230Smux 82156230Smux/* Exit codes. */ 83156230Smux#define STATUS_SUCCESS 0 84156230Smux#define STATUS_FAILURE 1 85156230Smux#define STATUS_TRANSIENTFAILURE 2 86156230Smux#define STATUS_INTERRUPTED 3 87156230Smux 88156230Smuxstruct config; 89156230Smuxstruct stream; 90156230Smux 91156230Smux/* Thread parameters. */ 92156230Smuxstruct thread_args { 93156230Smux struct config *config; 94156230Smux struct stream *rd; 95156230Smux struct stream *wr; 96156230Smux int status; 97156230Smux char *errmsg; 98156230Smux}; 99156230Smux 100156230Smux/* Minimum size for MD5_File() and MD5_End() buffers. */ 101156230Smux#define MD5_DIGEST_SIZE 33 102156230Smux 103156230Smux#define min(a, b) ((a) > (b) ? (b) : (a)) 104156230Smux#define max(a, b) ((a) < (b) ? (b) : (a)) 105156230Smux 106156230Smuxstruct backoff_timer; 107156230Smuxstruct pattlist; 108156230Smuxstruct tm; 109156230Smux 110186781Slulfint asciitoint(const char *, int *, int); 111186781Slulfint lprintf(int, const char *, ...) __printflike(2, 3); 112186781Slulfint MD5_File(char *, char *); 113186781Slulfvoid MD5_End(char *, MD5_CTX *); 114186781Slulfint rcsdatetotm(const char *, struct tm *); 115186781Slulftime_t rcsdatetotime(const char *); 116186781Slulfint pathcmp(const char *, const char *); 117186781Slulfsize_t commonpathlength(const char *, size_t, const char *, size_t); 118186781Slulfconst char *pathlast(const char *); 119186781Slulfint isrcs(const char *, size_t *); 120186781Slulfchar *checkoutpath(const char *, const char *); 121186781Slulfchar *cvspath(const char *, const char *, int); 122186781Slulfchar *atticpath(const char *, const char *); 123186781Slulfchar *path_prefix(char *); 124186781Slulfchar *path_first(char *); 125186781Slulfint mkdirhier(char *, mode_t); 126186781Slulfchar *tempname(const char *); 127186781Slulfvoid *xmalloc(size_t); 128186781Slulfvoid *xrealloc(void *, size_t); 129186781Slulfchar *xstrdup(const char *); 130186781Slulfint xasprintf(char **, const char *, ...) __printflike(2, 3); 131186781Slulfint rcsnum_cmp(char *, char *); 132186781Slulfint rcsrev_istrunk(char *); 133186781Slulfchar *rcsrev_prefix(char *); 134156230Smux 135156230Smuxstruct pattlist *pattlist_new(void); 136156230Smuxvoid pattlist_add(struct pattlist *, const char *); 137156230Smuxchar *pattlist_get(struct pattlist *, size_t); 138156230Smuxsize_t pattlist_size(struct pattlist *); 139156230Smuxvoid pattlist_free(struct pattlist *); 140156230Smux 141156230Smuxstruct backoff_timer *bt_new(time_t, time_t, float, float); 142156230Smuxtime_t bt_get(struct backoff_timer *); 143156230Smuxvoid bt_pause(struct backoff_timer *); 144156230Smuxvoid bt_free(struct backoff_timer *); 145156701Smux 146156230Smux#endif /* !_MISC_H_ */ 147