]> arthur.barton.de Git - netatalk.git/blob - include/atalk/util.h
0106db2fa48d5e9712af71f77d9135d74c20fe73
[netatalk.git] / include / atalk / util.h
1 /*
2  * $Id: util.h,v 1.20 2010-02-28 17:02:49 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 #include <atalk/volume.h>
26
27 /* exit error codes */
28 #define EXITERR_CLNT 1  /* client related error */
29 #define EXITERR_CONF 2  /* error in config files/cmd line parameters */
30 #define EXITERR_SYS  3  /* local system error */
31
32
33 #ifdef WITH_SENDFILE
34 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
35 #endif
36
37 extern const int _diacasemap[], _dialowermap[];
38
39 extern char **getifacelist(void);
40 extern void freeifacelist(char **);
41
42 #define diatolower(x)     _dialowermap[(unsigned char) (x)]
43 #define diatoupper(x)     _diacasemap[(unsigned char) (x)]
44 extern int atalk_aton     (char *, struct at_addr *);
45 extern void bprint        (char *, int);
46 extern int strdiacasecmp  (const char *, const char *);
47 extern int strndiacasecmp (const char *, const char *, size_t);
48 extern pid_t server_lock  (char * /*program*/, char * /*file*/, 
49                                int /*debug*/);
50 extern void fault_setup   (void (*fn)(void *));
51 #define server_unlock(x)  (unlink(x))
52
53 /* strlcpy and strlcat are used by pam modules */
54 #ifndef UAM_MODULE_EXPORT
55 #define UAM_MODULE_EXPORT 
56 #endif
57
58 #ifndef HAVE_STRLCPY
59 UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
60 #endif
61  
62 #ifndef HAVE_STRLCAT
63 UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
64 #endif
65
66 #ifndef HAVE_DLFCN_H
67 extern void *mod_open    (const char *);
68 extern void *mod_symbol  (void *, const char *);
69 extern void mod_close    (void *);
70 #define mod_error()      ""
71 #else /* ! HAVE_DLFCN_H */
72 #include <dlfcn.h>
73
74 #ifndef RTLD_NOW
75 #define RTLD_NOW 1
76 #endif /* ! RTLD_NOW */
77
78 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
79  * OpenBSD currently does not use the second arg for dlopen(). For
80  * future compatibility we define DL_LAZY */
81 #ifdef __NetBSD__
82 #define mod_open(a)      dlopen(a, RTLD_LAZY)
83 #elif defined(__OpenBSD__)
84 #define mod_open(a)      dlopen(a, DL_LAZY)
85 #else /* ! __NetBSD__ && ! __OpenBSD__ */
86 #define mod_open(a)      dlopen(a, RTLD_NOW)
87 #endif /* __NetBSD__ */
88
89 #ifndef DLSYM_PREPEND_UNDERSCORE
90 #define mod_symbol(a, b) dlsym(a, b)
91 #else /* ! DLSYM_PREPEND_UNDERSCORE */
92 extern void *mod_symbol  (void *, const char *);
93 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
94 #define mod_error()      dlerror()
95 #define mod_close(a)     dlclose(a)
96 #endif /* ! HAVE_DLFCN_H */
97
98 /******************************************************************
99  * locking.c
100  ******************************************************************/
101
102 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
103 #define read_lock(fd, offset, whence, len) \
104     lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
105 #define write_lock(fd, offset, whence, len) \
106     lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
107 #define unlock(fd, offset, whence, len) \
108     lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))
109
110 /******************************************************************
111  * socket.c
112  ******************************************************************/
113
114 extern int setnonblock(int fd, int cmd);
115 extern const char *getip_string(const struct sockaddr *sa);
116 extern unsigned int getip_port(const struct sockaddr *sa);
117 extern void apply_ip_mask(struct sockaddr *ai, int maskbits);
118 extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
119
120 /******************************************************************
121  * unix.c
122  *****************************************************************/
123
124 extern const char *getcwdpath(void);
125 extern int lchdir(struct vol *vol, const char *dir);
126
127 #endif  /* _ATALK_UTIL_H */