473abd4fd1b2f0ffa3471fdaf2255cfeb0277279
[openafs.git] / src / util / afsutil.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef _AFSUTIL_H_
11 #define _AFSUTIL_H_
12
13 #include <time.h>
14 /* Include afs installation dir retrieval routines */
15 #include <afs/dirpath.h>
16
17 /* These macros are return values from extractAddr. They do not represent
18  * any valid IP address and so can indicate a failure.
19  */
20 #define AFS_IPINVALID           0xffffffff      /* invalid IP address */
21 #define AFS_IPINVALIDIGNORE     0xfffffffe      /* no input given to extractAddr */
22
23 /* logging defines
24  */
25 #ifndef AFS_NT40_ENV
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h> /* for inet_ntoa() */
30 #endif
31
32 #include <stdio.h>
33 #include <stdarg.h>
34
35 extern int LogLevel;
36 extern int mrafsStyleLogs;
37 #ifndef AFS_NT40_ENV
38 extern int serverLogSyslog;
39 extern int serverLogSyslogFacility;
40 extern char *serverLogSyslogTag;
41 #endif
42 extern void vFSLog(const char *format, va_list args);
43 extern void SetLogThreadNumProgram(int (*func) (void) );
44
45 /*@printflike@*/ extern void FSLog(const char *format, ...);
46 #define ViceLog(level, str)  do { if ((level) <= LogLevel) (FSLog str); } while (0)
47 #define vViceLog(level, str) do { if ((level) <= LogLevel) (vFSLog str); } while (0)
48
49 extern int OpenLog(const char *filename);
50 extern int ReOpenLog(const char *fileName);
51 extern void SetupLogSignals(void);
52
53 extern int
54 afs_vsnprintf( /*@out@ */ char *p, size_t avail, const char *fmt,
55               va_list ap)
56     /*@requires maxSet(p) >= (avail-1)@ */
57     /*@modifies p@ */ ;
58
59      extern /*@printflike@ */ int
60        afs_snprintf( /*@out@ */ char *p, size_t avail,
61                     const char *fmt, ...)
62     /*@requires maxSet(p) >= (avail-1)@ */
63     /*@modifies p@ */ ;
64
65
66 /* special version of ctime that clobbers a *different static variable, so
67  * that ViceLog can call ctime and not cause buffer confusion.
68  */
69      extern char *vctime(const time_t * atime);
70
71 /* Need a thead safe ctime for pthread builds. Use std ctime for LWP */
72 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
73 #if defined(AFS_SUN5_ENV) && !defined(_POSIX_PTHREAD_SEMANTICS) && (_POSIX_C_SOURCE - 0 < 199506L)
74 #define afs_ctime(C, B, L) ctime_r(C, B, L)
75 #else
76 /* Cast is for platforms which do not prototype ctime_r */
77 #define afs_ctime(C, B, L) (char*)ctime_r(C, B)
78 #endif /* AFS_SUN5_ENV */
79 #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
80 #define afs_ctime(C, B, S) \
81         ((void)strncpy(B, ctime(C), (S-1)), (B)[S-1] = '\0', (B))
82 #endif /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
83
84
85 /* abort the current process. */
86 #ifdef AFS_NT40_ENV
87 #define afs_abort() afs_NTAbort()
88 #else
89 #define afs_abort() abort()
90 #endif
91
92
93 #ifdef AFS_NT40_ENV
94 #ifndef _MFC_VER
95 #include <winsock2.h>
96 #endif /* _MFC_VER */
97
98 /* Initialize the windows sockets before calling networking routines. */
99      extern int afs_winsockInit(void);
100      extern void afs_winsockCleanup(void);
101
102      struct timezone {
103          int tz_minuteswest;    /* of Greenwich */
104          int tz_dsttime;        /* type of dst correction to apply */
105      };
106 #define gettimeofday afs_gettimeofday
107      int afs_gettimeofday(struct timeval *tv, struct timezone *tz);
108
109 /* Unbuffer output when Un*x would do line buffering. */
110 #define setlinebuf(S) setvbuf(S, NULL, _IONBF, 0)
111
112 /* regular expression parser for NT */
113      extern char *re_comp(char *sp);
114      extern int rc_exec(char *p);
115
116 /* Abort on error, possibly trapping to debugger or dumping a trace. */
117      void afs_NTAbort(void);
118 #endif /* AFS_NT40_ENV */
119
120      typedef char b32_string_t[8];
121 /* b64_string_t is 8 bytes, in stds.h */
122      typedef char lb64_string_t[12];
123
124 #ifndef HAVE_STRLCAT
125 extern size_t strlcat(char *dst, const char *src, size_t siz);
126 #endif
127
128 #ifndef HAVE_STRLCPY
129 extern size_t strlcpy(char *dst, const char *src, size_t siz);
130 #endif
131
132 #ifndef UKERNEL
133 #include "afs/ktime.h"
134 #endif
135 #include "afsutil_prototypes.h"
136
137 #endif /* _AFSUTIL_H_ */