reindent-20030715
[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 #include <stdio.h>
26 #include <stdarg.h>
27 extern int LogLevel;
28 #ifndef AFS_NT40_ENV
29 extern int serverLogSyslog;
30 extern int serverLogSyslogFacility;
31 extern char *serverLogSyslogTag;
32 #endif
33 extern void vFSLog(const char *format, va_list args);
34 /*@printflike@*/ extern void FSLog(const char *format, ...);
35 #define ViceLog(level, str)  if ((level) <= LogLevel) (FSLog str)
36 #define vViceLog(level, str) if ((level) <= LogLevel) (vFSLog str)
37
38 extern int OpenLog(const char *filename);
39 extern int ReOpenLog(const char *fileName);
40 extern void SetupLogSignals(void);
41
42 extern int
43 afs_vsnprintf( /*@out@ */ char *p, size_t avail, const char *fmt,
44               va_list ap)
45     /*@requires maxSet(p) >= (avail-1)@ */
46     /*@modifies p@ */ ;
47
48      extern /*@printflike@ */ int
49        afs_snprintf( /*@out@ */ char *p, size_t avail,
50                     const char *fmt, ...)
51     /*@requires maxSet(p) >= (avail-1)@ */
52     /*@modifies p@ */ ;
53
54
55 /* special version of ctime that clobbers a *different static variable, so
56  * that ViceLog can call ctime and not cause buffer confusion.
57  */
58      extern char *vctime(const time_t * atime);
59
60 /* Need a thead safe ctime for pthread builds. Use std ctime for LWP */
61 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
62 #ifdef AFS_SUN5_ENV
63 #define afs_ctime(C, B, L) ctime_r(C, B, L)
64 #else
65 /* Cast is for platforms which do not prototype ctime_r */
66 #define afs_ctime(C, B, L) (char*)ctime_r(C, B)
67 #endif /* AFS_SUN5_ENV */
68 #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
69 #define afs_ctime(C, B, S) \
70         ((void)strncpy(B, ctime(C), (S-1)), (B)[S-1] = '\0', (B))
71 #endif /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
72
73
74 /* abort the current process. */
75 #ifdef AFS_NT40_ENV
76 #define afs_abort() afs_NTAbort()
77 #else
78 #define afs_abort() abort()
79 #endif
80
81
82 #ifdef AFS_NT40_ENV
83 #ifndef _MFC_VER
84 #include <winsock2.h>
85 #endif /* _MFC_VER */
86
87 /* Initialize the windows sockets before calling networking routines. */
88      extern int afs_winsockInit(void);
89
90      struct timezone {
91          int tz_minuteswest;    /* of Greenwich */
92          int tz_dsttime;        /* type of dst correction to apply */
93      };
94 #define gettimeofday afs_gettimeofday
95      int afs_gettimeofday(struct timeval *tv, struct timezone *tz);
96
97 /* Unbuffer output when Un*x would do line buffering. */
98 #define setlinebuf(S) setvbuf(S, NULL, _IONBF, 0)
99
100 /* regular expression parser for NT */
101      extern char *re_comp(char *sp);
102      extern int rc_exec(char *p);
103
104 /* Abort on error, possibly trapping to debugger or dumping a trace. */
105      void afs_NTAbort(void);
106 #endif /* NT40 */
107
108      typedef char b32_string_t[8];
109 /* b64_string_t is 8 bytes, in stds.h */
110      typedef char lb64_string_t[12];
111
112 #ifndef UKERNEL
113 #include "afs/ktime.h"
114 #endif
115 #include "afsutil_prototypes.h"
116
117 #endif /* _AFSUTIL_H_ */