common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * mbsync - mailbox synchronizer
  3. * Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
  4. * Copyright (C) 2002-2006,2010-2012 Oswald Buddenhagen <ossi@users.sf.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * As a special exception, mbsync may be linked with the OpenSSL library,
  20. * despite that library's more restrictive license.
  21. */
  22. #ifndef COMMON_H
  23. #define COMMON_H
  24. #include <autodefs.h>
  25. #include <sys/types.h>
  26. #include <stdarg.h>
  27. #include <stdio.h>
  28. #define as(ar) (sizeof(ar)/sizeof(ar[0]))
  29. #define __stringify(x) #x
  30. #define stringify(x) __stringify(x)
  31. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
  32. # define ATTR_UNUSED __attribute__((unused))
  33. # define ATTR_NORETURN __attribute__((noreturn))
  34. # define ATTR_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
  35. #else
  36. # define ATTR_UNUSED
  37. # define ATTR_NORETURN
  38. # define ATTR_PRINTFLIKE(fmt,var)
  39. #endif
  40. #ifdef __GNUC__
  41. # define INLINE __inline__
  42. #else
  43. # define INLINE
  44. #endif
  45. #define EXE "mbsync"
  46. /* main.c */
  47. #define DEBUG 1
  48. #define VERBOSE 2
  49. #define XVERBOSE 4
  50. #define QUIET 8
  51. #define VERYQUIET 16
  52. #define KEEPJOURNAL 32
  53. #define ZERODELAY 64
  54. #define CRASHDEBUG 128
  55. extern int DFlags;
  56. extern int UseFSync;
  57. extern int Pid;
  58. extern char Hostname[256];
  59. extern const char *Home;
  60. /* util.c */
  61. void ATTR_PRINTFLIKE(1, 2) debug( const char *, ... );
  62. void ATTR_PRINTFLIKE(1, 2) debugn( const char *, ... );
  63. void ATTR_PRINTFLIKE(1, 2) info( const char *, ... );
  64. void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... );
  65. void ATTR_PRINTFLIKE(1, 2) warn( const char *, ... );
  66. void ATTR_PRINTFLIKE(1, 2) error( const char *, ... );
  67. void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... );
  68. void flushn( void );
  69. typedef struct string_list {
  70. struct string_list *next;
  71. char string[1];
  72. } string_list_t;
  73. void add_string_list_n( string_list_t **list, const char *str, int len );
  74. void add_string_list( string_list_t **list, const char *str );
  75. void free_string_list( string_list_t *list );
  76. #ifndef HAVE_MEMRCHR
  77. void *memrchr( const void *s, int c, size_t n );
  78. #endif
  79. void *nfmalloc( size_t sz );
  80. void *nfcalloc( size_t sz );
  81. void *nfrealloc( void *mem, size_t sz );
  82. char *nfstrdup( const char *str );
  83. int nfvasprintf( char **str, const char *fmt, va_list va );
  84. int ATTR_PRINTFLIKE(2, 3) nfasprintf( char **str, const char *fmt, ... );
  85. int ATTR_PRINTFLIKE(3, 4) nfsnprintf( char *buf, int blen, const char *fmt, ... );
  86. void ATTR_NORETURN oob( void );
  87. char *expand_strdup( const char *s );
  88. int map_name( const char *arg, char **result, int reserve, const char *in, const char *out );
  89. void sort_ints( int *arr, int len );
  90. void arc4_init( void );
  91. unsigned char arc4_getbyte( void );
  92. int bucketsForSize( int size );
  93. #ifdef HAVE_SYS_POLL_H
  94. # include <sys/poll.h>
  95. #else
  96. # define POLLIN 1
  97. # define POLLOUT 4
  98. # define POLLERR 8
  99. #endif
  100. void add_fd( int fd, void (*cb)( int events, void *aux ), void *aux );
  101. void conf_fd( int fd, int and_events, int or_events );
  102. void fake_fd( int fd, int events );
  103. void del_fd( int fd );
  104. void main_loop( void );
  105. #endif