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 */
31 /* Print a SBT and exit */
32 #define AFP_PANIC(why) \
34 netatalk_panic(why); \
38 /* LOG assert errors */
40 #define AFP_ASSERT(b) \
52 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
55 extern const int _diacasemap[], _dialowermap[];
57 extern char **getifacelist(void);
58 extern void freeifacelist(char **);
60 #define diatolower(x) _dialowermap[(unsigned char) (x)]
61 #define diatoupper(x) _diacasemap[(unsigned char) (x)]
62 extern int atalk_aton (char *, struct at_addr *);
63 extern void bprint (char *, int);
64 extern int strdiacasecmp (const char *, const char *);
65 extern int strndiacasecmp (const char *, const char *, size_t);
66 extern pid_t server_lock (char * /*program*/, char * /*file*/, int /*debug*/);
67 extern void fault_setup (void (*fn)(void *));
68 extern void netatalk_panic(const char *why);
69 #define server_unlock(x) (unlink(x))
71 /* strlcpy and strlcat are used by pam modules */
72 #ifndef UAM_MODULE_EXPORT
73 #define UAM_MODULE_EXPORT
77 UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
81 UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
85 extern void *mod_open (const char *);
86 extern void *mod_symbol (void *, const char *);
87 extern void mod_close (void *);
88 #define mod_error() ""
89 #else /* ! HAVE_DLFCN_H */
94 #endif /* ! RTLD_NOW */
96 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
97 * OpenBSD currently does not use the second arg for dlopen(). For
98 * future compatibility we define DL_LAZY */
100 #define mod_open(a) dlopen(a, RTLD_LAZY)
101 #elif defined(__OpenBSD__)
102 #define mod_open(a) dlopen(a, DL_LAZY)
103 #else /* ! __NetBSD__ && ! __OpenBSD__ */
104 #define mod_open(a) dlopen(a, RTLD_NOW)
105 #endif /* __NetBSD__ */
107 #ifndef DLSYM_PREPEND_UNDERSCORE
108 #define mod_symbol(a, b) dlsym(a, b)
109 #else /* ! DLSYM_PREPEND_UNDERSCORE */
110 extern void *mod_symbol (void *, const char *);
111 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
112 #define mod_error() dlerror()
113 #define mod_close(a) dlclose(a)
114 #endif /* ! HAVE_DLFCN_H */
116 /******************************************************************
118 ******************************************************************/
120 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
121 #define read_lock(fd, offset, whence, len) \
122 lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
123 #define write_lock(fd, offset, whence, len) \
124 lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
125 #define unlock(fd, offset, whence, len) \
126 lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))
128 /******************************************************************
130 ******************************************************************/
132 extern int setnonblock(int fd, int cmd);
133 extern const char *getip_string(const struct sockaddr *sa);
134 extern unsigned int getip_port(const struct sockaddr *sa);
135 extern void apply_ip_mask(struct sockaddr *ai, int maskbits);
136 extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
138 /******************************************************************
140 *****************************************************************/
142 extern const char *getcwdpath(void);
143 extern char *stripped_slashes_basename(char *p);
144 extern int lchdir(const char *dir);
146 #endif /* _ATALK_UTIL_H */