1/*
2 * Copyright 2001-2004 Brandon Long
3 * All Rights Reserved.
4 *
5 * ClearSilver Templating System
6 *
7 * This code is made available under the terms of the ClearSilver License.
8 * http://www.clearsilver.net/license.hdf
9 *
10 */
11
12#ifndef __NEO_MISC_H_
13#define __NEO_MISC_H_ 1
14
15#include <stdlib.h>
16#include <time.h>
17#include <limits.h>
18
19/* In case they didn't start from ClearSilver.h. */
20#ifndef __CS_CONFIG_H_
21#include "cs_config.h"
22#endif
23
24/* Fix Up for systems that don't define these standard things */
25#ifndef __BEGIN_DECLS
26#ifdef __cplusplus
27#define __BEGIN_DECLS extern "C" {
28#define __END_DECLS }
29#else
30#define __BEGIN_DECLS
31#define __END_DECLS
32#endif
33#endif
34
35#ifndef _POSIX_PATH_MAX
36#define _POSIX_PATH_MAX 255
37#endif
38
39#ifndef S_IXGRP
40#define S_IXGRP S_IXUSR
41#endif
42#ifndef S_IWGRP
43#define S_IWGRP S_IWUSR
44#endif
45#ifndef S_IRGRP
46#define S_IRGRP S_IRUSR
47#endif
48#ifndef S_IXOTH
49#define S_IXOTH S_IXUSR
50#endif
51#ifndef S_IWOTH
52#define S_IWOTH S_IWUSR
53#endif
54#ifndef S_IROTH
55#define S_IROTH S_IRUSR
56#endif
57
58/* Format string checking for compilers that support it (GCC style) */
59
60#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 6
61#define ATTRIBUTE_PRINTF(a1,a2) __attribute__((__format__ (__printf__, a1, a2)))
62#else
63#define ATTRIBUTE_PRINTF(a1,a2)
64#endif
65
66
67__BEGIN_DECLS
68
69#ifndef HAVE_STRTOK_R
70char * strtok_r (char *s,const char * delim, char **save_ptr);
71#endif
72
73#ifndef HAVE_LOCALTIME_R
74struct tm *localtime_r (const time_t *timep, struct tm *ttm);
75#endif
76
77#ifndef HAVE_GMTIME_R
78struct tm *gmtime_r(const time_t *timep, struct tm *ttm);
79#endif
80
81#ifndef HAVE_MKSTEMP
82int mkstemp(char *path);
83#endif
84
85#ifndef HAVE_SNPRINTF
86int snprintf (char *str, size_t count, const char *fmt, ...)
87              ATTRIBUTE_PRINTF(3,4);
88#endif
89
90#ifndef HAVE_VSNPRINTF
91int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
92#endif
93
94#include <stdarg.h>
95#include <sys/types.h>
96
97typedef unsigned int UINT32;
98typedef int INT32;
99typedef unsigned short int UINT16;
100typedef short int INT16;
101typedef unsigned char UINT8;
102typedef char INT8;
103typedef char BOOL;
104
105#ifndef MIN
106#define MIN(x,y)        (((x) < (y)) ? (x) : (y))
107#endif
108
109#ifndef TRUE
110#define TRUE 1
111#endif
112#ifndef FALSE
113#define FALSE 0
114#endif
115
116void ne_vwarn (const char *fmt, va_list ap);
117void ne_warn (const char *fmt, ...)
118              ATTRIBUTE_PRINTF(1,2);
119void ne_set_log (int level);
120void ne_log (int level, const char *fmt, ...)
121             ATTRIBUTE_PRINTF(2,3);
122UINT32 python_string_hash (const char *s);
123UINT8 *ne_stream4 (UINT8  *dest, UINT32 num);
124UINT8 *ne_unstream4 (UINT32 *pnum, UINT8 *src);
125UINT8 *ne_stream2 (UINT8  *dest, UINT16 num);
126UINT8 *ne_unstream2 (UINT16 *pnum, UINT8 *src);
127UINT8 *ne_stream_str (UINT8 *dest, const char *s, int l);
128UINT8 *ne_unstream_str (char *s, int l, UINT8 *src);
129double ne_timef (void);
130UINT32 ne_crc (UINT8 *data, UINT32 bytes);
131
132__END_DECLS
133
134#endif /* __NEO_MISC_H_ */
135