00001 #ifndef _CP_UTIL_H
00002 #define _CP_UTIL_H
00003
00004 #include "common.h"
00005 #include "config.h"
00006
00007 #ifdef TIME_WITH_SYS_TIME
00008 # include <sys/time.h>
00009 # include <time.h>
00010 #else
00011 # ifdef HAVE_SYS_TIME_H
00012 # include <sys/time.h>
00013 # else
00014 # include <time.h>
00015 # endif
00016 #endif
00017 __BEGIN_DECLS
00018
00019
00020
00021
00022
00023 #ifndef HAVE_STRLCAT
00024 #define strlcat strncat
00025 #endif
00026
00027 #ifndef HAVE_STRLCPY
00028 #define strlcpy strncpy
00029 #endif
00030
00031 #ifndef HAVE_SNPRINTF
00032 #ifdef _WINDOWS
00033 #define snprintf _snprintf
00034 #define HAVE_SNPRINTF
00035 #endif
00036 #endif
00037
00038 #ifndef HAVE_STRDUP
00039
00040
00041
00042
00043
00044
00045 CPROPS_DLL
00046 char *strdup(char *src);
00047 #endif
00048
00049 #ifndef HAVE_STRNDUP
00050
00051
00052
00053
00054
00055
00056 CPROPS_DLL
00057 char *strndup(char *src, int maxlen);
00058 #endif
00059
00060 #ifndef HAVE_STRCASECMP
00061 #ifdef _WINDOWS
00062 #define strcasecmp _stricmp
00063 #else
00064 int strcasecmp(const char *a, const char *b);
00065 #endif
00066 #endif
00067
00068 #ifndef HAVE_STRNCASECMP
00069 #ifdef _WINDOWS
00070 #define strncasecmp _strnicmp
00071 #else
00072 int strncasecmp(const char *a, const char *b, size_t len);
00073 #endif
00074 #endif
00075
00076 #ifndef HAVE_GETTIMEOFDAY
00077 #ifdef _WINDOWS
00078 CPROPS_DLL
00079 int gettimeofday(struct timeval *res, struct timezone *tz);
00080 #endif
00081 #endif
00082
00083
00084 CPROPS_DLL
00085 int cp_sleep(int sec);
00086
00087
00088
00089
00090 CPROPS_DLL
00091 char *str_trim_cpy(char *dst, char *src);
00092
00093
00094
00095
00096
00097
00098
00099 CPROPS_DLL
00100 char *strnchr(char *str, char ch, int len);
00101
00102
00103
00104
00105
00106 CPROPS_DLL
00107 int parse_boolean(char *value);
00108
00109
00110
00111
00112 #define format_boolean(val) ((val) ? "t" : "f")
00113
00114
00115
00116
00117
00118 CPROPS_DLL
00119 long get_timestamp();
00120
00121
00122
00123
00124 CPROPS_DLL
00125 char *dbfmt(char *str);
00126
00127
00128
00129
00130
00131 CPROPS_DLL
00132 unsigned long get_current_ip();
00133
00134
00135
00136
00137 CPROPS_DLL
00138 unsigned long get_host_ip(char *hostname);
00139
00140
00141
00142
00143 CPROPS_DLL
00144 char *ip_to_string(unsigned long ip, char *buf, size_t len);
00145
00146
00147
00148
00149
00150 CPROPS_DLL
00151 char *hex_url_encode(char *hex);
00152
00153
00154
00155
00156
00157 CPROPS_DLL
00158 char *regex_compilation_error(int rc);
00159
00160
00161
00162
00163
00164
00165
00166 CPROPS_DLL
00167 char *stat_error_fmt(int err);
00168
00169
00170
00171
00172 CPROPS_DLL
00173 int checkdir(char *path);
00174
00175
00176
00177
00178
00179 CPROPS_DLL
00180 void gen_id_str(char *buf);
00181
00182
00183
00184
00185
00186 CPROPS_DLL
00187 void gen_tm_id_str(char *buf, struct timeval *tm);
00188
00189
00190
00191
00192 CPROPS_DLL
00193 time_t last_change_time(char *path);
00194
00195
00196 CPROPS_DLL
00197 int *intdup(int *src);
00198
00199
00200 CPROPS_DLL
00201 long *longdup(long *src);
00202
00203
00204 CPROPS_DLL
00205 float *floatdup(float *src);
00206
00207
00208 CPROPS_DLL
00209 double *doubledup(double *src);
00210
00211
00212 CPROPS_DLL
00213 void *memdup(void *src, int len);
00214
00215
00216 CPROPS_DLL
00217 int xtoi(char *p);
00218
00219
00220 CPROPS_DLL
00221 int xtol(char *p);
00222
00223
00224 CPROPS_DLL
00225 char *reverse_string(char *str);
00226
00227
00228 CPROPS_DLL
00229 char *reverse_string_in_place(char *str);
00230
00231
00232 CPROPS_DLL
00233 char *filter_string(char *str, char *letters);
00234
00235
00236 CPROPS_DLL
00237 char *to_lowercase(char *str);
00238
00239
00240 CPROPS_DLL
00241 char *to_uppercase(char *str);
00242
00243 #ifndef HAVE_GETOPT
00244 extern CPROPS_DLL char *optarg;
00245
00246 CPROPS_DLL
00247 int getopt(int argc, char *argv[], char *fmt);
00248 #endif
00249
00250 #ifndef HAVE_INET_NTOP
00251 #ifdef _WINDOWS
00252
00253 CPROPS_DLL
00254 char *inet_ntop(int af, const void *src, char *dst, size_t cnt);
00255 #endif
00256 #endif
00257
00258 #ifndef HAVE_DLFCN_H
00259 #ifdef _WINDOWS
00260 CPROPS_DLL
00261 void *dlopen(char *file, int mode);
00262
00263 CPROPS_DLL
00264 int dlclose(void *handle);
00265
00266 CPROPS_DLL
00267 void *dlsym(void *handle, char *name);
00268
00269 CPROPS_DLL
00270 char *dlerror();
00271
00272
00273
00274
00275 #define RTLD_LAZY 0
00276 #define RTLD_NOW 0
00277 #define RTLD_LOCAL 0
00278 #define RTLD_GLOBAL 0
00279
00280 #endif
00281 #endif
00282
00283 #ifndef HAVE_GETCWD
00284 #ifdef _WINDOWS
00285 #include "direct.h"
00286 #define getcwd _getcwd
00287 #endif
00288 #endif
00289
00290 #ifdef _WINDOWS
00291
00292 CPROPS_DLL
00293 int create_proc(char *path,
00294 void *child_stdin,
00295 void *child_stdout,
00296 void *child_stderr,
00297 char **envp);
00298 #endif
00299
00300 CPROPS_DLL
00301 void replace_char(char *buf, char from, char to);
00302
00303 CPROPS_DLL
00304 char *ssl_err_inf(int err);
00305
00306
00307
00308 __END_DECLS
00309
00310
00311 #endif
00312