]> arthur.barton.de Git - netatalk.git/blob - include/atalk/util.h
Merge branch-2-1
[netatalk.git] / include / atalk / util.h
1 /*
2  * $Id: util.h,v 1.21 2010/02/28 22:29:16 didg Exp $
3  */
4
5 /*!
6  * @file
7  * Netatalk utility functions
8  *
9  * Utility functions for these areas: \n
10  * * sockets \n
11  * * locking \n
12  * * misc UNIX function wrappers, eg for getcwd
13  */
14
15 #ifndef _ATALK_UTIL_H
16 #define _ATALK_UTIL_H 1
17
18 #include <sys/cdefs.h>
19 #include <sys/types.h>
20 #ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif /* HAVE_UNISTD_H */
23 #include <netatalk/at.h>
24 #include <atalk/unicode.h>
25
26 /* exit error codes */
27 #define EXITERR_CLNT 1  /* client related error */
28 #define EXITERR_CONF 2  /* error in config files/cmd line parameters */
29 #define EXITERR_SYS  3  /* local system error */
30
31 /* LOG assert errors */
32 #ifndef NDEBUG
33 #define AFP_ASSERT(b) \
34     do {                                                                \
35         if (!(b)) {                                                     \
36             LOG(log_error, logtype_default, "PANIC, assert failed: %s", #b); \
37             abort();                                                    \
38         } \
39     } while(0);
40 #else
41 #define AFP_ASSERT(b)
42 #endif /* NDEBUG */
43
44 #ifdef WITH_SENDFILE
45 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
46 #endif
47
48 extern const int _diacasemap[], _dialowermap[];
49
50 extern char **getifacelist(void);
51 extern void freeifacelist(char **);
52
53 #define diatolower(x)     _dialowermap[(unsigned char) (x)]
54 #define diatoupper(x)     _diacasemap[(unsigned char) (x)]
55 extern int atalk_aton     (char *, struct at_addr *);
56 extern void bprint        (char *, int);
57 extern int strdiacasecmp  (const char *, const char *);
58 extern int strndiacasecmp (const char *, const char *, size_t);
59 extern pid_t server_lock  (char * /*program*/, char * /*file*/, 
60                                int /*debug*/);
61 extern void fault_setup   (void (*fn)(void *));
62 #define server_unlock(x)  (unlink(x))
63
64 /* strlcpy and strlcat are used by pam modules */
65 #ifndef UAM_MODULE_EXPORT
66 #define UAM_MODULE_EXPORT 
67 #endif
68
69 #ifndef HAVE_STRLCPY
70 UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
71 #endif
72  
73 #ifndef HAVE_STRLCAT
74 UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
75 #endif
76
77 #ifndef HAVE_DLFCN_H
78 extern void *mod_open    (const char *);
79 extern void *mod_symbol  (void *, const char *);
80 extern void mod_close    (void *);
81 #define mod_error()      ""
82 #else /* ! HAVE_DLFCN_H */
83 #include <dlfcn.h>
84
85 #ifndef RTLD_NOW
86 #define RTLD_NOW 1
87 #endif /* ! RTLD_NOW */
88
89 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
90  * OpenBSD currently does not use the second arg for dlopen(). For
91  * future compatibility we define DL_LAZY */
92 #ifdef __NetBSD__
93 #define mod_open(a)      dlopen(a, RTLD_LAZY)
94 #elif defined(__OpenBSD__)
95 #define mod_open(a)      dlopen(a, DL_LAZY)
96 #else /* ! __NetBSD__ && ! __OpenBSD__ */
97 #define mod_open(a)      dlopen(a, RTLD_NOW)
98 #endif /* __NetBSD__ */
99
100 #ifndef DLSYM_PREPEND_UNDERSCORE
101 #define mod_symbol(a, b) dlsym(a, b)
102 #else /* ! DLSYM_PREPEND_UNDERSCORE */
103 extern void *mod_symbol  (void *, const char *);
104 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
105 #define mod_error()      dlerror()
106 #define mod_close(a)     dlclose(a)
107 #endif /* ! HAVE_DLFCN_H */
108
109 /******************************************************************
110  * locking.c
111  ******************************************************************/
112
113 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
114 #define read_lock(fd, offset, whence, len) \
115     lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
116 #define write_lock(fd, offset, whence, len) \
117     lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
118 #define unlock(fd, offset, whence, len) \
119     lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))
120
121 /******************************************************************
122  * socket.c
123  ******************************************************************/
124
125 extern int setnonblock(int fd, int cmd);
126 extern const char *getip_string(const struct sockaddr *sa);
127 extern unsigned int getip_port(const struct sockaddr *sa);
128 extern void apply_ip_mask(struct sockaddr *ai, int maskbits);
129 extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
130
131 /******************************************************************
132  * unix.c
133  *****************************************************************/
134
135 extern const char *getcwdpath(void);
136 extern int lchdir(const char *dir);
137
138 #endif  /* _ATALK_UTIL_H */