• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/libcprops/util.h

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  * assorted goodies
00021  */
00022 
00023 #ifndef HAVE_STRLCAT
00024 #define strlcat strncat
00025 #endif /* HAVE_STRLCAT */
00026 
00027 #ifndef HAVE_STRLCPY
00028 #define strlcpy strncpy
00029 #endif /* HAVE_STRLCPY */
00030 
00031 #ifndef HAVE_SNPRINTF
00032 #ifdef _WINDOWS
00033 #define snprintf _snprintf
00034 #define HAVE_SNPRINTF
00035 #endif /* _WINDOWS */
00036 #endif /* HAVE_SNPRINTF */
00037 
00038 #ifndef HAVE_STRDUP
00039 /**
00040  * Copies cp_string into newly allocated memory.
00041  *
00042  * @retval pointer to copied cp_string
00043  * @retval NULL if src was NULL
00044  */
00045 CPROPS_DLL
00046 char *strdup(char *src);
00047 #endif /* missing strdup */
00048 
00049 #ifndef HAVE_STRNDUP
00050 /**
00051  * Copies up to maxlen characters of src cp_string into newly allocated memory.
00052  *
00053  * @retval pointer to copied cp_string
00054  * @retval NULL if src was NULL
00055  */
00056 CPROPS_DLL
00057 char *strndup(char *src, int maxlen);
00058 #endif /* missing strndup */
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 /* HAVE_STRNCASECMP */
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 /* HAVE_STRNCASECMP */
00075 
00076 #ifndef HAVE_GETTIMEOFDAY
00077 #ifdef _WINDOWS
00078 CPROPS_DLL
00079 int gettimeofday(struct timeval *res, struct timezone *tz);
00080 #endif
00081 #endif /* missing gettimeofday */
00082 
00083 /* cp_sleep - a platform independent function to sleep n seconds */
00084 CPROPS_DLL
00085 int cp_sleep(int sec);
00086 
00087 /**
00088  * @todo check for buffer overflow
00089  */
00090 CPROPS_DLL
00091 char *str_trim_cpy(char *dst, char *src);
00092 
00093 
00094 /**
00095  * scans a cp_string for the first occurence of ch within the first len bytes at
00096  * most. searching for the null character will return a pointer to the 
00097  * terminating null. 
00098  */
00099 CPROPS_DLL
00100 char *strnchr(char *str, char ch, int len);
00101 
00102 
00103 /**
00104  * Map character 't', 'T' to true.
00105  */
00106 CPROPS_DLL
00107 int parse_boolean(char *value);
00108 
00109 /**
00110  * Map integer value to characters 't', 'f'.
00111  */
00112 #define format_boolean(val) ((val) ? "t" : "f")
00113 
00114 
00115 /**
00116  * Get the current time as long value (UNIX).
00117  */
00118 CPROPS_DLL
00119 long get_timestamp();
00120 
00121 /**
00122  * Return the cp_string or if NULL an empty cp_string.
00123  */
00124 CPROPS_DLL
00125 char *dbfmt(char *str);
00126 
00127 
00128 /**
00129  * Retrieves the ip-adress of the system where it is running on.
00130  */
00131 CPROPS_DLL
00132 unsigned long get_current_ip();
00133 
00134 /**
00135  * Retrieve the ip-address of the system with the 'hostname'.
00136  */
00137 CPROPS_DLL
00138 unsigned long get_host_ip(char *hostname);
00139 
00140 /**
00141  * Formats an ip-address (IPv4) with dot notation.
00142  */
00143 CPROPS_DLL
00144 char *ip_to_string(unsigned long ip, char *buf, size_t len);
00145 
00146 /** 
00147  * converts hex to url encoded binary (eg ABCD => %AB%CD) and returns a newly
00148  * allocated cp_string
00149  */
00150 CPROPS_DLL
00151 char *hex_url_encode(char *hex);
00152 
00153 /** 
00154  * return a static string coresponding to the posix regcomp error code given
00155  * as a parameter. the error descriptions come from the gnu man page. 
00156  */
00157 CPROPS_DLL
00158 char *regex_compilation_error(int rc);
00159 
00160 /**
00161  * return a static string describing the stat return code given as a parameter.
00162  * the resulting error string contains 2 '%s' sequences - the first one could 
00163  * be used for the program name, function description etc, the second one 
00164  * for the stat()ed path.
00165  */
00166 CPROPS_DLL
00167 char *stat_error_fmt(int err);
00168 
00169 /**
00170  * check if the directory specified by path exists
00171  */
00172 CPROPS_DLL
00173 int checkdir(char *path);
00174 
00175 /**
00176  * generates a 16 character id based on the current time. The generated id 
00177  * followed by a terminating null character are written into buf.
00178  */
00179 CPROPS_DLL
00180 void gen_id_str(char *buf);
00181 
00182 /**
00183  * generates a 16 character id based on the given time. The generated id 
00184  * followed by a terminating null character are written into buf.
00185  */
00186 CPROPS_DLL
00187 void gen_tm_id_str(char *buf, struct timeval *tm);
00188 
00189 /**
00190  * get a timestamp for the last modification to the file designated by path
00191  */
00192 CPROPS_DLL
00193 time_t last_change_time(char *path);
00194 
00195 /** duplicate an integer */
00196 CPROPS_DLL
00197 int *intdup(int *src);
00198 
00199 /** duplicate a long integer */
00200 CPROPS_DLL
00201 long *longdup(long *src);
00202 
00203 /** duplicate a floating point value */
00204 CPROPS_DLL
00205 float *floatdup(float *src);
00206 
00207 /** duplicate a double precision floating point value */
00208 CPROPS_DLL
00209 double *doubledup(double *src);
00210 
00211 /** duplicate an array */
00212 CPROPS_DLL
00213 void *memdup(void *src, int len);
00214 
00215 /** convert a hex string to an integer value */
00216 CPROPS_DLL
00217 int xtoi(char *p);
00218 
00219 /** convert a hex string to a long value */
00220 CPROPS_DLL
00221 int xtol(char *p);
00222 
00223 /** return flipped string in a newly allocated buffer */
00224 CPROPS_DLL
00225 char *reverse_string(char *str);
00226 
00227 /** flip a string in place */
00228 CPROPS_DLL
00229 char *reverse_string_in_place(char *str);
00230 
00231 /** remove all occurrences of letters from str */
00232 CPROPS_DLL
00233 char *filter_string(char *str, char *letters);
00234 
00235 /** convert string to lower case characters */
00236 CPROPS_DLL
00237 char *to_lowercase(char *str);
00238 
00239 /** convert string to upper case characters */
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 /* no getopt */
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 /* _WINDOWS */
00256 #endif /* HAVE_INET_NTOP */
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 /* none if this is actually supported by the win32 api, just define the symbols
00273  * so the build doesn't break. 
00274  */
00275 #define RTLD_LAZY   0
00276 #define RTLD_NOW    0
00277 #define RTLD_LOCAL  0
00278 #define RTLD_GLOBAL 0
00279 
00280 #endif /* WINDOWS */
00281 #endif /* HAVE_DLFCN_H */
00282 
00283 #ifndef HAVE_GETCWD
00284 #ifdef _WINDOWS
00285 #include "direct.h"
00286 #define getcwd _getcwd
00287 #endif /* _WINDOWS */
00288 #endif /* HAVE_GETCWD */
00289 
00290 #ifdef _WINDOWS
00291 /* convenience function to create a process under windows */
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 /* _WINDOWS */
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 

Generated on Fri Oct 22 2010 11:02:14 for SST by  doxygen 1.7.1