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