X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=include%2Fatalk%2Futil.h;h=9ce71584a8d0ed46b9041e85054a2848d871d1a8;hp=080b13408a216f153d18120bf3f3a075f7d7c9f3;hb=b362b6f7b22b6e4e9e74760989f389149677917b;hpb=70e8818ea52f3ff5bca42e6c3cbf5765f959f322 diff --git a/include/atalk/util.h b/include/atalk/util.h index 080b1340..9ce71584 100644 --- a/include/atalk/util.h +++ b/include/atalk/util.h @@ -1,7 +1,3 @@ -/* - * $Id: util.h,v 1.21 2010/02/28 22:29:16 didg Exp $ - */ - /*! * @file * Netatalk utility functions @@ -20,27 +16,56 @@ #ifdef HAVE_UNISTD_H #include #endif /* HAVE_UNISTD_H */ +#include +#include +#include + #include + #include +#include /* exit error codes */ #define EXITERR_CLNT 1 /* client related error */ #define EXITERR_CONF 2 /* error in config files/cmd line parameters */ #define EXITERR_SYS 3 /* local system error */ +/* Print a SBT and exit */ +#define AFP_PANIC(why) \ + do { \ + netatalk_panic(why); \ + abort(); \ + } while(0); + /* LOG assert errors */ #ifndef NDEBUG #define AFP_ASSERT(b) \ do { \ if (!(b)) { \ - LOG(log_error, logtype_default, "PANIC, assert failed: %s", #b); \ - abort(); \ + AFP_PANIC(#b); \ } \ } while(0); #else #define AFP_ASSERT(b) #endif /* NDEBUG */ +#define STRCMP(a,b,c) (strcmp(a,c) b 0) +#ifndef MAX +#define MAX(a,b) ((a) > (b) ? a : b) +#endif +#ifndef MIN +#define MIN(a,b) ((a) < (b) ? a : b) +#endif + +#if BYTE_ORDER == BIG_ENDIAN +#define hton64(x) (x) +#define ntoh64(x) (x) +#else /* BYTE_ORDER == BIG_ENDIAN */ +#define hton64(x) ((uint64_t) (htonl(((x) >> 32) & 0xffffffffLL)) | \ + (uint64_t) ((htonl(x) & 0xffffffffLL) << 32)) +#define ntoh64(x) (hton64(x)) +#endif /* BYTE_ORDER == BIG_ENDIAN */ + #ifdef WITH_SENDFILE extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count); #endif @@ -52,13 +77,17 @@ extern void freeifacelist(char **); #define diatolower(x) _dialowermap[(unsigned char) (x)] #define diatoupper(x) _diacasemap[(unsigned char) (x)] +#ifndef NO_DDP extern int atalk_aton (char *, struct at_addr *); +#endif extern void bprint (char *, int); extern int strdiacasecmp (const char *, const char *); extern int strndiacasecmp (const char *, const char *, size_t); -extern pid_t server_lock (char * /*program*/, char * /*file*/, - int /*debug*/); +extern pid_t server_lock (char * /*program*/, char * /*file*/, int /*debug*/); +extern int check_lockfile (const char *program, const char *pidfile); +extern int create_lockfile(const char *program, const char *pidfile); extern void fault_setup (void (*fn)(void *)); +extern void netatalk_panic(const char *why); #define server_unlock(x) (unlink(x)) /* strlcpy and strlcat are used by pam modules */ @@ -123,16 +152,57 @@ extern int lock_reg(int fd, int cmd, int type, off_t offest, int whence, off_t l ******************************************************************/ extern int setnonblock(int fd, int cmd); +extern ssize_t readt(int socket, void *data, const size_t length, int setnonblocking, int timeout); +extern ssize_t writet(int socket, void *data, const size_t length, int setnonblocking, int timeout); extern const char *getip_string(const struct sockaddr *sa); extern unsigned int getip_port(const struct sockaddr *sa); extern void apply_ip_mask(struct sockaddr *ai, int maskbits); extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2); +/* Structures and functions dealing with dynamic pollfd arrays */ +enum fdtype {IPC_FD, LISTEN_FD, DISASOCIATED_IPC_FD}; +struct polldata { + enum fdtype fdtype; /* IPC fd or listening socket fd */ + void *data; /* pointer to AFPconfig for listening socket and * + * pointer to afp_child_t for IPC fd */ +}; + +extern void fdset_add_fd(int maxconns, + struct pollfd **fdsetp, + struct polldata **polldatap, + int *fdset_usedp, + int *fdset_sizep, + int fd, + enum fdtype fdtype, + void *data); +extern void fdset_del_fd(struct pollfd **fdsetp, + struct polldata **polldatap, + int *fdset_usedp, + int *fdset_sizep, + int fd); +extern int send_fd(int socket, int fd); +extern int recv_fd(int fd, int nonblocking); + /****************************************************************** * unix.c *****************************************************************/ extern const char *getcwdpath(void); -extern int lchdir(const char *dir); +extern const char *fullpathname(const char *); +extern char *stripped_slashes_basename(char *p); +extern void randombytes(void *buf, int n); +extern int daemonize(int nochdir, int noclose); + +extern int ochdir(const char *dir, int options); +extern int ostat(const char *path, struct stat *buf, int options); +extern int ostatat(int dirfd, const char *path, struct stat *st, int options); +extern int ochown(const char *path, uid_t owner, gid_t group, int options); +extern int ochmod(const char *path, mode_t mode, const struct stat *st, int options); + +/****************************************************************** + * cnid.c + *****************************************************************/ + +extern bstring rel_path_in_vol(const char *path, const char *volpath); #endif /* _ATALK_UTIL_H */