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

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