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