Git init
[pkgs/e/elektra.git] / src / include / kdbos.h
1 /***************************************************************************
2              kdbos.h  -  operating system specific workarounds
3                              -------------------
4     begin                : Mon Dec 29 2003
5     copyright            : (C) 2003 by Avi Alkalay
6     email                : avi@unix.sh
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the BSD License (revised).                      *
13  *                                                                         *
14  ***************************************************************************/
15
16 /* This header purpose is that afterwards following types are defined:
17  * .. means don't care, just enough for your system
18  * For more information on that types read POSIX documentation.
19  *
20  * Type     Purpose                 Limits
21  * size_t   size of array or string 0, SIZE_MAX
22  * ssize_t  size with error cond.   -1, SSIZE_MAX(<SIZE_MAX)
23  * time_t   Seconds since 1970      0,.. recommended: 64 bit
24  *
25  * Integer Types must be at least 32bit:
26  *
27  * int      Integral Fast Type      INT_MIN, INT_MAX
28  * uid_t    User identification     0,..
29  * gid_t    Group identification    0,..
30  * type_t   Typing information      -1,..
31  * keyswitch_t For keyNew
32  * option_t    For kdbGet, kdbSet and ksLookup*
33  *
34  *
35  * Following elektra specific types are defined:
36  *
37  * Type     Purpose
38  * cursor_t stores information to find a position in a keyset
39  *
40  * Following constants must be defined:
41  *
42  * KEY_SEPARATOR   how to delimit keynames
43  * PATH_SEPARATOR  how to delimit pathnames
44  * KEY_DEF_MODE    the standard mode for keys
45  * KEY_DIR_MODE    the mode to add (|=) for key directories
46  *
47  * Following limits must be defined (in addition to limits mentioned
48  * above for types):
49  *
50  * MAX_UCHAR       the maximum for unsigned char
51  * MAX_KEY_LENGTH  the maximum length for a keyname
52  * MAX_PATH_LENGTH the maximum length for a pathname
53  *
54  * In addition to the types the ... or va_list must be supported,
55  * this is ISO C and should happen by including <stdarg.h>.
56  *
57  * Go ahead and write a #ifdef block for your operating system
58  * when the POSIX defaults are not ok.
59  */
60
61
62 #ifndef KDBOS_H
63 #define KDBOS_H
64
65
66 /* Include essential headers used in kdb.h */
67 #include <stdarg.h>
68
69 #ifndef WIN32
70
71 /***************************************************
72  *               Posix Compatible
73  ***************************************************/
74
75 #ifndef __USE_POSIX
76 #define __USE_POSIX
77 #endif
78 #include <limits.h>
79
80 /* Conforming C++ programs are not allowed to
81  * include inttypes.h*/
82 #include <inttypes.h>
83 #include <sys/types.h>
84
85 /**Separator for Path names*/
86 #define PATH_SEPARATOR '/'
87
88
89 /**MAX_PATH_LENGTH will be the value for longest
90  * possible filenames on the system.*/
91
92 /*Some systems have even longer pathnames*/
93 #ifdef PATH_MAX
94 #define MAX_PATH_LENGTH PATH_MAX
95 /*This value is garanteed on any Posixsystem*/
96 #elif defined __USE_POSIX
97 #define MAX_PATH_LENGTH _POSIX_PATH_MAX
98 #else
99 #define MAX_PATH_LENGTH 4096
100 #endif
101
102 /*Type to point to every position within the keyset*/
103 typedef ssize_t cursor_t;
104
105 /*Integer types*/
106 typedef int type_t;
107 typedef int keyswitch_t;
108 typedef int option_t;
109
110 /**Separator for key names.
111  * This character will be used to separate key names*/
112 #define KEY_SEPARATOR '/'
113 /**Default Mode.
114  * This mode will be used for fresh keys*/
115 #define KEY_DEF_MODE 0664
116 /**Default directory mode.
117  * This mode will be ORed to have a directory key*/
118 #define KEY_DEF_DIR 0111
119
120 /**Lets assume that the namespace + relative path is shorter then the absolute path.
121  * So the maximum length of key is what the system allows for the path.*/
122 #define MAX_KEY_LENGTH MAX_PATH_LENGTH
123
124
125
126
127 #else /* WIN32 */
128
129 /***************************************************
130  *                 Windows
131  ***************************************************/
132 # include <windows.h>
133 # include <limits.h>
134
135 # define usleep(x) Sleep(x)
136
137 # define ssize_t int
138 # define snprintf _snprintf
139
140 /**Separator for Path names*/
141 #define PATH_SEPARATOR '\\'
142
143 #define MAX_PATH_LENGTH 4096
144
145 /*Type to point to every position within the keyset*/
146 typedef ssize_t cursor_t;
147
148 /*Integer types*/
149 typedef int type_t;
150 typedef int keyswitch_t;
151 typedef int option_t;
152
153 /**Separator for key names.
154  * This character will be used to separate key names*/
155 #define KEY_SEPARATOR '/'
156 /**Default Mode.
157  * This mode will be used for fresh keys*/
158 #define KEY_DEF_MODE 0664
159 /**Default directory mode.
160  * This mode will be ORed to have a directory key*/
161 #define KEY_DEF_DIR 0111
162
163 /**Lets assume that the namespace + relative path is shorter then the absolute path.
164  * So the maximum length of key is what the system allows for the path.*/
165 #define MAX_KEY_LENGTH MAX_PATH_LENGTH
166
167
168
169
170 #endif /* WIN32 */
171
172 #endif /* KDBOS_H */
173