00001 #ifndef _CP_UTIL_H
00002 #define _CP_UTIL_H
00003
00004 #include "common.h"
00005 #include "config.h"
00006
00007 #ifdef CP_HAS_SYS_TIME_H
00008 #include <sys/time.h>
00009 #else
00010 #include <time.h>
00011 #endif
00012 __BEGIN_DECLS
00013
00018 #ifndef CP_HAS_STRLCAT
00019 #define strlcat strncat
00020 #endif
00021
00022 #ifndef CP_HAS_STRLCPY
00023 #define strlcpy strncpy
00024 #endif
00025
00026 #ifndef CP_HAS_SNPRINTF
00027 #ifdef _WINDOWS
00028 #define snprintf _snprintf
00029 #define CP_HAS_SNPRINTF
00030 #endif
00031 #endif
00032
00033 #ifndef CP_HAS_STRDUP
00034
00040 CPROPS_DLL
00041 char *strdup(char *src);
00042 #endif
00043
00044 #ifndef CP_HAS_STRNDUP
00045
00051 CPROPS_DLL
00052 char *strndup(char *src, int maxlen);
00053 #endif
00054
00055 #ifndef CP_HAS_STRCASECMP
00056 #ifdef _WINDOWS
00057 #define strcasecmp _stricmp
00058 #else
00059 int strcasecmp(const char *a, const char *b);
00060 #endif
00061 #endif
00062
00063 #ifndef CP_HAS_STRNCASECMP
00064 #ifdef _WINDOWS
00065 #define strncasecmp _strnicmp
00066 #else
00067 int strncasecmp(const char *a, const char *b, size_t len);
00068 #endif
00069 #endif
00070
00071 #ifndef CP_HAS_GETTIMEOFDAY
00072 #ifdef _WINDOWS
00073 CPROPS_DLL
00074 int gettimeofday(struct timeval *res, struct timezone *tz);
00075 #endif
00076 #endif
00077
00078
00079 CPROPS_DLL
00080 int cp_sleep(int sec);
00081
00085 CPROPS_DLL
00086 char *str_trim_cpy(char *dst, char *src);
00087
00088
00094 CPROPS_DLL
00095 char *strnchr(char *str, char ch, int len);
00096
00097
00101 CPROPS_DLL
00102 int parse_boolean(char *value);
00103
00107 #define format_boolean(val) ((val) ? "t" : "f")
00108
00109
00113 CPROPS_DLL
00114 long get_timestamp();
00115
00119 CPROPS_DLL
00120 char *dbfmt(char *str);
00121
00122
00126 CPROPS_DLL
00127 unsigned long get_current_ip();
00128
00132 CPROPS_DLL
00133 unsigned long get_host_ip(char *hostname);
00134
00138 CPROPS_DLL
00139 char *ip_to_string(unsigned long ip, char *buf, size_t len);
00140
00145 CPROPS_DLL
00146 char *hex_url_encode(char *hex);
00147
00152 CPROPS_DLL
00153 char *regex_compilation_error(int rc);
00154
00161 CPROPS_DLL
00162 char *stat_error_fmt(int err);
00163
00167 CPROPS_DLL
00168 int checkdir(char *path);
00169
00174 CPROPS_DLL
00175 void gen_id_str(char *buf);
00176
00181 CPROPS_DLL
00182 void gen_tm_id_str(char *buf, struct timeval *tm);
00183
00187 CPROPS_DLL
00188 time_t last_change_time(char *path);
00189
00191 CPROPS_DLL
00192 int *intdup(int *src);
00193
00195 CPROPS_DLL
00196 long *longdup(long *src);
00197
00199 CPROPS_DLL
00200 float *floatdup(float *src);
00201
00203 CPROPS_DLL
00204 double *doubledup(double *src);
00205
00207 CPROPS_DLL
00208 void *memdup(void *src, int len);
00209
00211 CPROPS_DLL
00212 int xtoi(char *p);
00213
00215 CPROPS_DLL
00216 int xtol(char *p);
00217
00219 CPROPS_DLL
00220 char *reverse_string(char *str);
00221
00223 CPROPS_DLL
00224 char *reverse_string_in_place(char *str);
00225
00227 CPROPS_DLL
00228 char *filter_string(char *str, char *letters);
00229
00231 CPROPS_DLL
00232 char *to_lowercase(char *str);
00233
00235 CPROPS_DLL
00236 char *to_uppercase(char *str);
00237
00238 #ifndef CP_HAS_GETOPT
00239 extern CPROPS_DLL char *optarg;
00240
00241 CPROPS_DLL
00242 int getopt(int argc, char *argv[], char *fmt);
00243 #endif
00244
00245 #ifndef CP_HAS_INET_NTOP
00246 #ifdef _WINDOWS
00247
00248 CPROPS_DLL
00249 char *inet_ntop(int af, const void *src, char *dst, size_t cnt);
00250 #endif
00251 #endif
00252
00253 #ifndef CP_HAS_DLFCN_H
00254 #ifdef _WINDOWS
00255 CPROPS_DLL
00256 void *dlopen(char *file, int mode);
00257
00258 CPROPS_DLL
00259 int dlclose(void *handle);
00260
00261 CPROPS_DLL
00262 void *dlsym(void *handle, char *name);
00263
00264 CPROPS_DLL
00265 char *dlerror();
00266
00267
00268
00269
00270 #define RTLD_LAZY 0
00271 #define RTLD_NOW 0
00272 #define RTLD_LOCAL 0
00273 #define RTLD_GLOBAL 0
00274
00275 #endif
00276 #endif
00277
00278 #ifndef CP_HAS_GETCWD
00279 #ifdef _WINDOWS
00280 #include "direct.h"
00281 #define getcwd _getcwd
00282 #endif
00283 #endif
00284
00285 #ifdef _WINDOWS
00286
00287 CPROPS_DLL
00288 int create_proc(char *path,
00289 void *child_stdin,
00290 void *child_stdout,
00291 void *child_stderr,
00292 char **envp);
00293 #endif
00294
00295 CPROPS_DLL
00296 void replace_char(char *buf, char from, char to);
00297
00298 CPROPS_DLL
00299 char *ssl_err_inf(int err);
00300
00301
00302
00303 __END_DECLS
00304
00306 #endif
00307