2 * $Id: util.h,v 1.21 2010-02-28 22:29:16 didg Exp $
7 * Netatalk utility functions
9 * Utility functions for these areas: \n
12 * * misc UNIX function wrappers, eg for getcwd
16 #define _ATALK_UTIL_H 1
18 #include <sys/cdefs.h>
19 #include <sys/types.h>
22 #endif /* HAVE_UNISTD_H */
23 #include <netatalk/at.h>
24 #include <atalk/unicode.h>
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 */
33 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
36 extern const int _diacasemap[], _dialowermap[];
38 extern char **getifacelist(void);
39 extern void freeifacelist(char **);
41 #define diatolower(x) _dialowermap[(unsigned char) (x)]
42 #define diatoupper(x) _diacasemap[(unsigned char) (x)]
43 extern int atalk_aton (char *, struct at_addr *);
44 extern void bprint (char *, int);
45 extern int strdiacasecmp (const char *, const char *);
46 extern int strndiacasecmp (const char *, const char *, size_t);
47 extern pid_t server_lock (char * /*program*/, char * /*file*/,
49 extern void fault_setup (void (*fn)(void *));
50 #define server_unlock(x) (unlink(x))
52 /* strlcpy and strlcat are used by pam modules */
53 #ifndef UAM_MODULE_EXPORT
54 #define UAM_MODULE_EXPORT
58 UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
62 UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
66 extern void *mod_open (const char *);
67 extern void *mod_symbol (void *, const char *);
68 extern void mod_close (void *);
69 #define mod_error() ""
70 #else /* ! HAVE_DLFCN_H */
75 #endif /* ! RTLD_NOW */
77 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
78 * OpenBSD currently does not use the second arg for dlopen(). For
79 * future compatibility we define DL_LAZY */
81 #define mod_open(a) dlopen(a, RTLD_LAZY)
82 #elif defined(__OpenBSD__)
83 #define mod_open(a) dlopen(a, DL_LAZY)
84 #else /* ! __NetBSD__ && ! __OpenBSD__ */
85 #define mod_open(a) dlopen(a, RTLD_NOW)
86 #endif /* __NetBSD__ */
88 #ifndef DLSYM_PREPEND_UNDERSCORE
89 #define mod_symbol(a, b) dlsym(a, b)
90 #else /* ! DLSYM_PREPEND_UNDERSCORE */
91 extern void *mod_symbol (void *, const char *);
92 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
93 #define mod_error() dlerror()
94 #define mod_close(a) dlclose(a)
95 #endif /* ! HAVE_DLFCN_H */
97 /******************************************************************
99 ******************************************************************/
101 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
102 #define read_lock(fd, offset, whence, len) \
103 lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
104 #define write_lock(fd, offset, whence, len) \
105 lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
106 #define unlock(fd, offset, whence, len) \
107 lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))
109 /******************************************************************
111 ******************************************************************/
113 extern int setnonblock(int fd, int cmd);
114 extern const char *getip_string(const struct sockaddr *sa);
115 extern unsigned int getip_port(const struct sockaddr *sa);
116 extern void apply_ip_mask(struct sockaddr *ai, int maskbits);
117 extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
119 /******************************************************************
121 *****************************************************************/
123 extern const char *getcwdpath(void);
124 extern int lchdir(const char *dir);
126 #endif /* _ATALK_UTIL_H */