2 * $Id: util.h,v 1.11 2009-10-13 22:55:37 didg Exp $
6 #define _ATALK_UTIL_H 1
12 #endif /* HAVE_UNISTD_H */
13 #include <netatalk/at.h>
14 #include <atalk/unicode.h>
16 /* exit error codes */
17 #define EXITERR_CLNT 1 /* client related error */
18 #define EXITERR_CONF 2 /* error in config files/cmd line parameters */
19 #define EXITERR_SYS 3 /* local system error */
22 extern int sys_ftruncate (int fd, off_t length);
25 extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
28 extern const int _diacasemap[], _dialowermap[];
30 extern char **getifacelist(void);
31 extern void freeifacelist(char **);
33 #define diatolower(x) _dialowermap[(unsigned char) (x)]
34 #define diatoupper(x) _diacasemap[(unsigned char) (x)]
35 extern int atalk_aton (char *, struct at_addr *);
36 extern void bprint (char *, int);
37 extern int strdiacasecmp (const char *, const char *);
38 extern int strndiacasecmp (const char *, const char *, size_t);
39 extern pid_t server_lock (char * /*program*/, char * /*file*/,
41 extern void fault_setup (void (*fn)(void *));
42 #define server_unlock(x) (unlink(x))
45 size_t strlcpy (char *, const char *, size_t);
49 size_t strlcat (char *, const char *, size_t);
53 extern void *mod_open (const char *);
54 extern void *mod_symbol (void *, const char *);
55 extern void mod_close (void *);
56 #define mod_error() ""
57 #else /* ! HAVE_DLFCN_H */
62 #endif /* ! RTLD_NOW */
64 /* NetBSD doesn't like RTLD_NOW for dlopen (it fails). Use RTLD_LAZY.
65 * OpenBSD currently does not use the second arg for dlopen(). For
66 * future compatibility we define DL_LAZY */
68 #define mod_open(a) dlopen(a, RTLD_LAZY)
69 #elif defined(__OpenBSD__)
70 #define mod_open(a) dlopen(a, DL_LAZY)
71 #else /* ! __NetBSD__ && ! __OpenBSD__ */
72 #define mod_open(a) dlopen(a, RTLD_NOW)
73 #endif /* __NetBSD__ */
75 #ifndef DLSYM_PREPEND_UNDERSCORE
76 #define mod_symbol(a, b) dlsym(a, b)
77 #else /* ! DLSYM_PREPEND_UNDERSCORE */
78 extern void *mod_symbol (void *, const char *);
79 #endif /* ! DLSYM_PREPEND_UNDERSCORE */
80 #define mod_error() dlerror()
81 #define mod_close(a) dlclose(a)
82 #endif /* ! HAVE_DLFCN_H */
85 /* volinfo for shell utilities */
86 #define VOLINFOFILE ".volinfo"
96 charset_t v_volcharset;
98 charset_t v_maccharset;
99 int v_adouble; /* default adouble format */
100 char *(*ad_path)(const char *, int);
105 extern int loadvolinfo (char *path, struct volinfo *vol);
106 extern int vol_load_charsets ( struct volinfo *vol);
112 * Purpose: lock a file with fctnl
116 * fd (r) File descriptor
117 * cmd (r) cmd to fcntl, only F_SETLK is usable here
118 * type (r) F_RDLCK, F_WRLCK, F_UNLCK
119 * offset (r) byte offset relative to l_whence
120 * whence (r) SEEK_SET, SEEK_CUR, SEEK_END
121 * len (r) no. of bytes (0 means to EOF)
123 * Returns: 0 on success, -1 on failure
124 * fcntl return value and errno
128 * Function called by macros to ease locking.
130 extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t len);
133 * Macros: read_lock, write_lock, un_lock
135 * Purpose: lock and unlock files
139 * fd (r) File descriptor
140 * offset (r) byte offset relative to l_whence
141 * whence (r) SEEK_SET, SEEK_CUR, SEEK_END
142 * len (r) no. of bytes (0 means to EOF)
144 * Returns: 0 on success, -1 on failure
145 * fcntl return value and errno
149 * Nice locking macros.
152 #define read_lock(fd, offset, whence, len) \
153 lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
154 #define write_lock(fd, offset, whence, len) \
155 lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
156 #define unlock(fd, offset, whence, len) \
157 lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))