CUBRID Engine  latest
util_func.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * util_func.h : miscellaneous utility functions interface
22  *
23  */
24 
25 #ifndef _UTIL_FUNC_H_
26 #define _UTIL_FUNC_H_
27 
28 #ident "$Id$"
29 
30 #include <sys/types.h>
31 #include <math.h>
32 #include <time.h>
33 
34 #define UTIL_PID_ENVVAR_NAME "UTIL_PID"
35 #define UTIL_infinity() (HUGE_VAL)
36 
37 #if defined(WINDOWS)
38 #define SLEEP_MILISEC(SEC, MSEC) Sleep((SEC) * 1000 + (MSEC))
39 #else
40 #define SLEEP_MILISEC(sec, msec) \
41  do { \
42  struct timeval sleep_time_val; \
43  sleep_time_val.tv_sec = sec; \
44  sleep_time_val.tv_usec = (msec) * 1000; \
45  select(0, 0, 0, 0, &sleep_time_val); \
46  } while(0)
47 #endif
48 
49 #define PRINT_AND_LOG_ERR_MSG(...) \
50  do {\
51  fprintf(stderr, __VA_ARGS__);\
52  util_log_write_errstr(__VA_ARGS__);\
53  }while (0)
54 
55 extern unsigned int hashpjw (const char *);
56 
57 extern int util_compare_filepath (const char *file1, const char *file2);
58 
59 
60 typedef void (*SIG_HANDLER) (void);
61 extern void util_arm_signal_handlers (SIG_HANDLER DB_INT32_handler, SIG_HANDLER quit_handler);
62 extern void util_disarm_signal_handlers (void);
63 extern char **util_split_string (const char *str, const char *delim);
64 extern void util_free_string_array (char **array);
65 extern time_t util_str_to_time_since_epoch (char *str);
66 extern void util_shuffle_string_array (char **array, int count);
67 
68 extern int util_log_write_result (int error);
69 extern int util_log_write_errid (int message_id, ...);
70 extern int util_log_write_errstr (const char *format, ...);
71 extern int util_log_write_warnstr (const char *format, ...);
72 extern int util_log_write_command (int argc, char *argv[]);
73 
74 extern int util_bsearch (const void *key, const void *base, int n_elems, unsigned int sizeof_elem,
75  int (*func_compare) (const void *, const void *), bool * out_found);
76 
77 extern void util_get_second_and_ms_since_epoch (time_t * secs, int *msec);
78 
79 #endif /* _UTIL_FUNC_H_ */
void util_shuffle_string_array(char **array, int count)
Definition: util_func.c:412
int argc
Definition: dynamic_load.c:951
int util_log_write_command(int argc, char *argv[])
Definition: util_func.c:540
void util_free_string_array(char **array)
Definition: util_func.c:292
void util_disarm_signal_handlers(void)
Definition: util_func.c:192
char ** util_split_string(const char *str, const char *delim)
Definition: util_func.c:247
void util_arm_signal_handlers(SIG_HANDLER DB_INT32_handler, SIG_HANDLER quit_handler)
Definition: util_func.c:222
int util_log_write_warnstr(const char *format,...)
Definition: util_func.c:516
void util_get_second_and_ms_since_epoch(time_t *secs, int *msec)
Definition: util_func.c:829
int util_compare_filepath(const char *file1, const char *file2)
Definition: util_func.c:111
int util_log_write_result(int error)
Definition: util_func.c:448
unsigned int hashpjw(const char *)
Definition: util_func.c:83
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
time_t util_str_to_time_since_epoch(char *str)
Definition: util_func.c:310
void(* SIG_HANDLER)(void)
Definition: util_func.h:60
static void error(const char *msg)
Definition: gencat.c:331
const char ** argv
Definition: dynamic_load.c:952
int util_bsearch(const void *key, const void *base, int n_elems, unsigned int sizeof_elem, int(*func_compare)(const void *, const void *), bool *out_found)
Definition: util_func.c:764
int util_log_write_errid(int message_id,...)
Definition: util_func.c:468
int util_log_write_errstr(const char *format,...)
Definition: util_func.c:493