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