Main Page | Modules | Data Structures | File List | Data Fields

misc.h

00001 /* 
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. - All rights reserved.  
00003  */
00004 
00005 #ifndef _U_MISC_H_
00006 #define _U_MISC_H_
00007 
00008 #include <u/libu_conf.h>
00009 
00010 #include <unistd.h>
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include <limits.h>
00014 
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018 
00019 /* define U_PATH_MAX */
00020 #ifndef PATH_MAX
00021 #define U_PATH_MAX 4096
00022 #else
00023 #define U_PATH_MAX PATH_MAX
00024 #endif
00025 
00026 /* define U_NAME_MAX */
00027 #ifdef NAME_MAX
00028 #define U_NAME_MAX NAME_MAX
00029 #else
00030 #ifdef FILENAME_MAX
00031 #define U_NAME_MAX FILENAME_MAX
00032 #else
00033 #define U_NAME_MAX 512
00034 #endif 
00035 #endif
00036 
00037 /* define U_FILENAME_MAX (path + name) */
00038 #define U_FILENAME_MAX (U_PATH_MAX + U_NAME_MAX)
00039 
00040 #define U_ONCE if (({ static int __x = 0; int __y; __y = __x; __x = 1; !__y;}))
00041 #define U_SSTRCPY(to, from) u_sstrncpy((to), (from), sizeof(to) - 1)
00042 #define U_FREE(ptr) do {if (ptr) { u_free(ptr); ptr = NULL; }} while (0)
00043 #define U_CLOSE(fd) do {if (fd != -1) { close(fd); fd = -1; }} while (0)
00044 #define U_FCLOSE(fp) do {if (fp) { fclose(fp); fp = NULL; }} while (0)
00045 #define U_PCLOSE(pp) do {if (pp) { pclose(pp); pp = NULL; }} while (0)
00046 #define U_MIN(a, b) ((a) < (b) ? (a) : (b))
00047 #define U_MAX(a, b) ((a) > (b) ? (a) : (b))
00048 #define u_unused_args(...) u_use_unused_args(NULL, __VA_ARGS__)
00049 
00050 int u_isnl(int c);
00051 void u_trim(char *s);
00052 int u_isblank(int c);
00053 int u_isblank_str(const char *ln);
00054 char *u_strndup(const char *s, size_t len);
00055 char *u_strdup(const char *s);
00056 int u_savepid (const char *pf);
00057 char *u_sstrncpy (char *dst, const char *src, size_t size);
00058 void* u_memdup(const void *src, size_t size);
00059 int u_tokenize (char *wlist, const char *delim, char **tokv, size_t tokv_sz);
00060 int u_snprintf(char *str, size_t size, const char *fmt, ...);
00061 int u_path_snprintf(char *str, size_t size, char sep, const char *fmt, ...);
00062 void u_use_unused_args(char *dummy, ...);
00063 int u_data_is_bin (char *data, size_t sz);
00064 int u_data_dump (char *data, size_t sz, const char *file);
00065 int u_load_file (const char *path, size_t sz_max, char **pbuf, size_t *psz);
00066 
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 
00071 #endif /* !_U_MISC_H_ */

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved