IDENTIFIER_LENGTH is modified to have 64 bytes. and Binary datatype input string...
[csql.git] / include / os.h
blob9a90f8cdf8fb82414c9c2cbd3417b517c9e8a80b
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef OS_H
17 #define OS_H
18 #include<build.h>
20 #if defined(solaris) || defined(LINUX)
22 #include <stdio.h>
23 #include <sys/mman.h>
24 #include <sys/shm.h>
25 #include <sys/errno.h>
26 #include <crypt.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <pthread.h>
34 //#include <math.h>
35 #include <signal.h>
36 #include <ctype.h>
37 #include <sys/socket.h>
38 #if defined(solaris)
39 #include <sys/varargs.h>
40 #endif
41 #if defined(LINUX)
42 #include <sys/time.h>
43 #include <stdarg.h>
44 #endif
45 typedef void (*sighandler_t)(int);
47 enum FileOpenMode
49 fileOpenReadOnly = O_RDONLY,
50 fileOpenWriteOnly = O_WRONLY,
51 fileOpenReadWrite = O_RDWR,
52 fileOpenAppend = O_APPEND |O_RDWR,
53 fileOpenCreat = O_CREAT |O_RDWR,
54 // If set and fileOpenExcl is set, the
55 // open will fail if the file already exists.
56 fileOpenExcl = O_EXCL,
57 fileOpenTrunc = O_TRUNC
60 enum MapProtMode
62 mapProtRead = PROT_READ,
63 mapProtWrite = PROT_WRITE,
64 mapProcExec = PROT_EXEC,
65 mapProcNone = PROT_NONE
68 enum MapMode
70 mapShared = MAP_SHARED,
71 mapPrivate = MAP_PRIVATE,
72 mapFixed = MAP_FIXED,
73 // Interpret address exactly.
74 mapNoReserve = MAP_NORESERVE,
75 // Don't reserver swap space.
77 //mapAlign = MAP_ALIGN,
78 //for msync system call
79 mapSync = MS_SYNC ,
80 mapASync = MS_ASYNC
84 #define MAX_FILE_LEN 1024
85 #define IDENTIFIER_LENGTH 64
86 #define ERROR_STRING_LENGTH 128
87 #define DEFAULT_VALUE_BUF_LENGTH 32
88 #define SYSTEMDB "SYSTEMDB"
89 #define DBAUSER "root"
90 #define DBAPASS "manager"
91 #define LOCK_BUCKET_SIZE 2048
92 #define MAX_CHUNKS 20
93 #define PAGE_SIZE Conf::config.getPageSize()
94 #define MAX_MUTEX_PER_THREAD 3
95 #define MAX_THREADS_PER_PROCESS 30
96 #define MAX_FILE_PATH_LEN 1024
97 #define CHUNK_NAME_LEN 64
99 #define BIT(x) (1 << (x))
100 #define SETBITS(x,y) ((x) |= (y))
101 #define CLEARBITS(x,y) ((x) &= (~(y)))
102 #define SETBIT(x,y) SETBITS((x), (BIT((y))))
103 #define CLEARBIT(x,y) CLEARBITS((x), (BIT((y))))
104 #define BITSET(x,y) ((x) & (BIT(y)))
107 typedef key_t shared_memory_key;
108 typedef int shared_memory_id;
110 #endif
113 class os
115 public:
116 static caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off);
117 static int munmap(caddr_t addr, size_t len);
118 static int openFile(const char *name, FileOpenMode flags, size_t size);
119 static int closeFile(int fd);
120 static off_t lseek(int fildes, off_t offset, int whence);
121 static size_t write(int fildes, char *buf, size_t size);
122 static int msync(caddr_t addr, size_t len, int flags);
123 static int fsync(int fildes);
124 static size_t alignLong(size_t size);
125 static size_t align(size_t size);
126 static char* encrypt(const char * key, const char *salt);
127 static void* memset(void *src, int c, size_t size);
128 static void* memcpy(void *src, const void *dest, size_t size);
129 static int memcmp(const void *s1, const void *s2, size_t size);
130 static int select(int nfds, fd_set *readfds, fd_set *writefds,
131 fd_set *exceptfds, struct timeval * timeout);
133 static int usleep(int microsecs);
134 static int sleep(int secs);
135 static shared_memory_id shm_create(shared_memory_key key, size_t size, int flag);
136 static shared_memory_id shm_open(shared_memory_key key, size_t size, int flag);
137 static void* shm_attach(shared_memory_id id, const void *ptr, int flag);
138 static int shm_detach (void*);
139 static int shmctl(int shmid, int cmd);
140 static double floor(double val);
141 static sighandler_t signal(int signum, sighandler_t handler);
143 static int gettimeofday(struct timeval *tp);
144 static struct tm* localtime(long *secs);
145 static pid_t getpid();
146 static pthread_t getthrid();
147 static char* getenv(const char *envVarName);
148 static int setenv(const char *envVarName, const char *value);
150 static int kill(pid_t pid, int sig);
151 static bool atobool(char *value);
152 static pid_t createProcess(const char* cmdName, const char *arg0, ...);
153 static pid_t fork();
154 static size_t send(int fd, const void *buf, size_t len, int flags);
155 static size_t recv(int fd, void *buf, size_t len, int flags);
156 static int gethostname(char *hostname, size_t len);
159 #endif