This has following fixes.
[csql.git] / include / os.h
blob3f055807e08dfdb52feb42db0100b6a56b02ce40
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 #if defined(solaris)
38 #include <sys/varargs.h>
39 #endif
40 #if defined(LINUX)
41 #include <sys/time.h>
42 #include <stdarg.h>
43 #endif
44 typedef void (*sighandler_t)(int);
46 enum FileOpenMode
48 fileOpenReadOnly = O_RDONLY,
49 fileOpenWriteOnly = O_WRONLY,
50 fileOpenReadWrite = O_RDWR,
51 fileOpenAppend = O_APPEND |O_RDWR,
52 fileOpenCreat = O_CREAT |O_RDWR,
53 // If set and fileOpenExcl is set, the
54 // open will fail if the file already exists.
55 fileOpenExcl = O_EXCL,
56 fileOpenTrunc = O_TRUNC
59 enum MapProtMode
61 mapProtRead = PROT_READ,
62 mapProtWrite = PROT_WRITE,
63 mapProcExec = PROT_EXEC,
64 mapProcNone = PROT_NONE
67 enum MapMode
69 mapShared = MAP_SHARED,
70 mapPrivate = MAP_PRIVATE,
71 mapFixed = MAP_FIXED,
72 // Interpret address exactly.
73 mapNoReserve = MAP_NORESERVE,
74 // Don't reserver swap space.
76 //mapAlign = MAP_ALIGN,
77 //for msync system call
78 mapSync = MS_SYNC ,
79 mapASync = MS_ASYNC
83 #define MAX_FILE_LEN 1024
84 #define IDENTIFIER_LENGTH 128
85 #define DEFAULT_VALUE_BUF_LENGTH 32
86 #define SYSTEMDB "SYSTEMDB"
87 #define DBAUSER "root"
88 #define DBAPASS "manager"
89 #define LOCK_BUCKET_SIZE 2048
90 #define MAX_CHUNKS 20
91 #define PAGE_SIZE Conf::config.getPageSize()
92 #define MAX_MUTEX_PER_THREAD 5
95 #define BIT(x) (1 << (x))
96 #define SETBITS(x,y) ((x) |= (y))
97 #define CLEARBITS(x,y) ((x) &= (~(y)))
98 #define SETBIT(x,y) SETBITS((x), (BIT((y))))
99 #define CLEARBIT(x,y) CLEARBITS((x), (BIT((y))))
100 #define BITSET(x,y) ((x) & (BIT(y)))
103 typedef key_t shared_memory_key;
104 typedef int shared_memory_id;
106 #endif
109 class os
111 public:
112 static caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off);
113 static int munmap(caddr_t addr, size_t len);
114 static int openFile(const char *name, FileOpenMode flags, size_t size);
115 static int closeFile(int fd);
116 static off_t lseek(int fildes, off_t offset, int whence);
117 static size_t write(int fildes, char *buf, size_t size);
118 static int msync(caddr_t addr, size_t len, int flags);
119 static int fsync(int fildes);
120 static size_t alignLong(size_t size);
121 static size_t align(size_t size);
122 static char* encrypt(const char * key, const char *salt);
123 static void* memset(void *src, int c, size_t size);
124 static void* memcpy(void *src, const void *dest, size_t size);
125 static int memcmp(const void *s1, const void *s2, size_t size);
126 static int select(int nfds, fd_set *readfds, fd_set *writefds,
127 fd_set *exceptfds, struct timeval * timeout);
129 static shared_memory_id shm_create(shared_memory_key key, size_t size, int flag);
130 static shared_memory_id shm_open(shared_memory_key key, size_t size, int flag);
131 static void* shm_attach(shared_memory_id id, const void *ptr, int flag);
132 static int shm_detach (void*);
133 static int shmctl(int shmid, int cmd);
134 static double floor(double val);
135 static sighandler_t signal(int signum, sighandler_t handler);
137 static int gettimeofday(struct timeval *tp);
138 static struct tm* localtime(long *secs);
139 static pid_t getpid();
140 static pthread_t getthrid();
141 static char* getenv(const char *envVarName);
142 static int setenv(const char *envVarName, const char *value);
144 static int kill(pid_t pid, int sig);
147 #endif