English Language flag
// Log In
// CVSweb
Project: FreeWRT
// Summary // Activity // Search // Tracker // Lists // News // SCM // Wiki

SCM Repository

ViewVC logotype

Diff of /branches/common-nfo/tools/sqlite/dbif.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3455 by tg, Thu Aug 9 11:51:36 2007 UTC revision 3456 by tg, Thu Aug 9 13:18:23 2007 UTC
# Line 1  Line 1 
 /* $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $ */  
   
1  /*-  /*-
2   * Copyright (c) 2007   * $FreeWRT$
3   *      Thorsten Glaser <tg@mirbsd.de>   *-
4   *   * This file is part of the FreeWRT project. FreeWRT is copyrighted
5   * Provided that these terms and disclaimer and all copyright notices   * material, please see the LICENCE file in the top-level directory
6   * are retained or reproduced in an accompanying document, permission   * or at http://www.freewrt.org/licence for details.
  * is granted to deal in this work without restriction, including un-  
  * limited rights to use, publicly perform, distribute, sell, modify,  
  * merge, give away, or sublicence.  
  *  
  * Advertising materials mentioning features or use of this work must  
  * display the following acknowledgement:  
  *      This product includes material provided by Thorsten Glaser.  
  * This acknowledgement does not need to be reprinted if this work is  
  * linked into a bigger work whose licence does not allow such clause  
  * and the author of this work is given due credit in the bigger work  
  * or its accompanying documents, where such information is generally  
  * kept, provided that said credits are retained.  
  *  
  * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to  
  * the utmost extent permitted by applicable law, neither express nor  
  * implied; without malicious intent or gross negligence. In no event  
  * may a licensor, author or contributor be held liable for indirect,  
  * direct, other damage, loss, or other issues arising in any way out  
  * of dealing in the work, even if advised of the possibility of such  
  * damage or existence of a defect, except proven that it results out  
  * of said person's immediate fault when using the work as intended.  
7   */   */
8    
9  #ifndef DBIF_H  #ifndef DBIF_H
10  #define DBIF_H  #define DBIF_H
11    
12  #include "sqlite3.h"  #include "sqlite3.h"
13    #include "nfohelpr.h"
 /* stolen from mksh's sh.h */  
 #ifdef EXTERN  
 # define I__(i) = i  
 #else  
 # define I__(i)  
 # define EXTERN extern  
 # define EXTERN_DEFINED  
 #endif  
   
 /* debugging */  
 #define D(level, fmt, ...) do {                         \  
         if (debug >= (level))                           \  
                 fprintf(stderr, (fmt), ##__VA_ARGS__);  \  
 } while (0)  
14    
15  __BEGIN_DECLS  __BEGIN_DECLS
 EXTERN int debug I__(0);  
16  EXTERN sqlite3 *db I__(NULL);  EXTERN sqlite3 *db I__(NULL);
17    
18  /* dbif.c */  /* dbif.c */
# Line 69  int dbexecv_(const char *, unsigned, con Line 31  int dbexecv_(const char *, unsigned, con
31              (cb), (cbarg), (sqlfmt), __VA_ARGS__))              \              (cb), (cbarg), (sqlfmt), __VA_ARGS__))              \
32                  dberr(1, et ? et : "processing SQL stmt");      \                  dberr(1, et ? et : "processing SQL stmt");      \
33  } while (0)  } while (0)
   
 #ifdef NFOTISER  
 #ifdef __GLIBC__  
 /* fgetln.c */  
 char *fgetln(FILE *, size_t *);  
 /* strlfun.c */  
 size_t strlcat(char *, const char *, size_t);  
 size_t strlcpy(char *, const char *, size_t);  
 #endif  
 #endif  
34  __END_DECLS  __END_DECLS
35    
 /* useful stuff */  
 #define xmalloc(size) ({                                \  
         void *xmalloc_ptr;                              \  
         size_t xmalloc_sz = (size);                     \  
                                                         \  
         if ((xmalloc_ptr = malloc(xmalloc_sz)) == NULL) \  
                 err(255, "cannot allocate %zu bytes",   \  
                     xmalloc_sz);                        \  
         (xmalloc_ptr);                                  \  
 })  
   
 #define xrealloc(ptr, size) ({                          \  
         void *xrealloc_newptr;                          \  
         size_t xrealloc_sz = (size);                    \  
                                                         \  
         xrealloc_newptr = realloc((ptr), xrealloc_sz);  \  
         if (xrealloc_newptr == NULL)                    \  
                 err(255, "cannot realloc to %zu bytes", \  
                     xrealloc_sz);                       \  
         (xrealloc_newptr);                              \  
 })  
   
 #define str_save(s) ({                                  \  
         const char *str_save_s = (s);                   \  
                                                         \  
         (str_nsave(str_save_s, strlen(str_save_s)));    \  
 })  
   
 #define str_nsave(s, n) ({                              \  
         char *str_nsave_ptr;                            \  
         size_t str_nsave_sz = (n);                      \  
                                                         \  
         str_nsave_ptr = xmalloc(str_nsave_sz + 1);      \  
         memcpy(str_nsave_sz, (s), str_nsave_sz);        \  
         str_nsave_ptr[str_nsave_sz] = '\0';             \  
         (str_nsave_ptr);                                \  
 })  
   
 #define str_add(d, s) ({                                \  
         const char *str_add_s = (s);                    \  
                                                         \  
         (str_nadd((d), str_add_s, strlen(str_add_s)));  \  
 })  
   
 #define str_nadd(d, s, n) ({                            \  
         char *str_nadd_ptr = (d), *str_nadd_newptr;     \  
         size_t str_nadd_sz, str_nadd_addsz = (n);       \  
                                                         \  
         str_nadd_sz = str_nadd_ptr ?                    \  
             strlen(str_nadd_ptr) : 0;                   \  
         str_nadd_newptr = str_nadd_ptr ?                \  
             xrealloc(str_nadd_ptr,                      \  
             str_nadd_sz + str_nadd_addsz + 1) :         \  
             xmalloc(str_nadd_addsz + 1);                \  
         str_nadd_ptr = str_nadd_newptr + str_nadd_sz;   \  
         memcpy(str_nadd_ptr, (s), str_nadd_addsz);      \  
         str_nadd_ptr[str_nadd_addsz] = '\0';            \  
         (str_nadd_newptr);                              \  
 })  
   
36  #endif  #endif

Legend:
Removed from v.3455  
changed lines
  Added in v.3456

root@freewrt.org:443
ViewVC Help
Powered by ViewVC 1.1.20