3 * Netatalk utility functions
5 * Utility functions for these areas: \n
8 * * misc UNIX function wrappers, eg for getcwd
12 #define _ATALK_UTIL_H 1
14 #include <sys/cdefs.h>
15 #include <sys/types.h>
18 #endif /* HAVE_UNISTD_H */
20 #include <netatalk/at.h>
21 #include <atalk/unicode.h>
23 /* exit error codes */
24 #define EXITERR_CLNT 1 /* client related error */
25 #define EXITERR_CONF 2 /* error in config files/cmd line parameters */
26 #define EXITERR_SYS 3 /* local system error */
28 /* Print a SBT and exit */
29 #define AFP_PANIC(why) \
31 netatalk_panic(why); \
35 /* LOG assert errors */
37 #define AFP_ASSERT(b) \
47 #define STRCMP(a,b,c) (strcmp(a,c) b 0)
50 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
53 extern const int _diacasemap[], _dialowermap[];
55 extern char **getifacelist(void);
56 extern void freeifacelist(char **);
58 #define diatolower(x) _dialowermap[(unsigned char) (x)]
59 #define diatoupper(x) _diacasemap[(unsigned char) (x)]
60 extern int atalk_aton (char *, struct at_addr *);
61 extern void bprint (char *, int);
62 extern int strdiacasecmp (const char *, const char *);
63 extern int strndiacasecmp (const char *, const char *, size_t);
64 extern pid_t server_lock (char * /*program*/, char * /*file*/, int /*debug*/);
65 extern void fault_setup (void (*fn)(void *));
66 extern void netatalk_panic(const char *why);
67 #define server_unlock(x) (unlink(x))
69 /* strlcpy and strlcat are used by pam modules */
70 #ifndef UAM_MODULE_EXPORT
71 #define UAM_MODULE_EXPORT
75 UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
79 UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
83 extern void *mod_open (const char *);
84 extern void *mod_symbol (void *, const char *);
85 extern void mod_close (void *);
86 #define mod_error() ""
87 #else /* ! HAVE_DLFCN_H */
92 #endif /* ! RTLD_NOW */
94 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
95 * OpenBSD currently does not use the second arg for dlopen(). For
96 * future compatibility we define DL_LAZY */
98 #define mod_open(a) dlopen(a, RTLD_LAZY)
99 #elif defined(__OpenBSD__)
100 #define mod_open(a) dlopen(a, DL_LAZY)
101 #else /* ! __NetBSD__ && ! __OpenBSD__ */
102 #define mod_open(a) dlopen(a, RTLD_NOW)
103 #endif /* __NetBSD__ */
105 #ifndef DLSYM_PREPEND_UNDERSCORE
106 #define mod_symbol(a, b) dlsym(a, b)
107 #else /* ! DLSYM_PREPEND_UNDERSCORE */
108 extern void *mod_symbol (void *, const char *);
109 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
110 #define mod_error() dlerror()
111 #define mod_close(a) dlclose(a)
112 #endif /* ! HAVE_DLFCN_H */
114 /******************************************************************
116 ******************************************************************/
118 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
119 #define read_lock(fd, offset, whence, len) \
120 lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
121 #define write_lock(fd, offset, whence, len) \
122 lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
123 #define unlock(fd, offset, whence, len) \
124 lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))
126 /******************************************************************
128 ******************************************************************/
130 extern int setnonblock(int fd, int cmd);
131 extern ssize_t readt(int socket, void *data, const size_t length, int setnonblocking, int timeout);
132 extern ssize_t writet(int socket, void *data, const size_t length, int setnonblocking, int timeout);
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 /* Structures and functions dealing with dynamic pollfd arrays */
139 enum fdtype {IPC_FD, LISTEN_FD};
141 enum fdtype fdtype; /* IPC fd or listening socket fd */
142 void *data; /* pointer to AFPconfig for listening socket and *
143 * pointer to afp_child_t for IPC fd */
146 extern void fdset_add_fd(struct pollfd **fdsetp,
147 struct polldata **polldatap,
153 extern void fdset_del_fd(struct pollfd **fdsetp,
154 struct polldata **polldatap,
158 extern int send_fd(int socket, int fd);
159 extern int recv_fd(int fd, int nonblocking);
161 /******************************************************************
163 *****************************************************************/
165 extern const char *getcwdpath(void);
166 extern char *stripped_slashes_basename(char *p);
167 extern int lchdir(const char *dir);
168 extern void randombytes(void *buf, int n);
169 #endif /* _ATALK_UTIL_H */