4 * @author Sebastian Hack
6 * Copyright (C) 2005 Universitaet Karlsruhe
7 * Released under the GPL
18 typedef size_t ssize_t;
19 typedef unsigned __int16 uint16_t;
20 typedef unsigned __int32 uint32_t;
22 /* disable warning: 'foo' was declared deprecated, use 'bla' instead */
23 /* of course MS had to make 'bla' incompatible to 'foo', so a simple */
24 /* define will not work :-((( */
25 #pragma warning( disable : 4996 )
32 #include <netinet/in.h>
39 #define LPP_BUFSIZE (1 << 20)
42 #define LPP_CMD(x) LPP_CMD_ ## x,
43 #include "lpp_cmd.def"
48 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
51 if((res = (expr)) op cond) { \
52 fprintf(stderr, "%s(%u): %d = %s(%d): ", \
53 __FILE__, (unsigned) __LINE__, res, #expr, cond); \
55 fprintf(stderr, "\n"); \
60 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
62 int _basic_errno_check_res = (expr); \
63 if(_basic_errno_check_res op cond) { \
64 fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
65 __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
70 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
71 BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
73 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
74 BASIC_ERRNO_CHECK(expr, op, cond, return retval)
76 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
77 BASIC_ERR_CHECK(expr, op, cond, fmt, return)
79 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
80 BASIC_ERRNO_CHECK(expr, op, cond, return)
82 #define ERR_CHECK(expr, op, cond, fmt) \
83 BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
85 #define ERRNO_CHECK(expr, op, cond) \
86 BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
88 typedef struct _lpp_comm_t lpp_comm_t;
90 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
92 int lpp_comm_fileno(const lpp_comm_t *comm);
94 ssize_t lpp_flush(lpp_comm_t *comm);
96 void lpp_comm_free(lpp_comm_t *comm);
98 void lpp_print_err(const char *fmt, ...);
100 void lpp_writel(lpp_comm_t *comm, uint32_t x);
102 void lpp_writed(lpp_comm_t *comm, double dbl);
104 void lpp_writes(lpp_comm_t *comm, const char *str);
106 uint32_t lpp_readl(lpp_comm_t *comm);
108 int lpp_read_cmd(lpp_comm_t *comm);
110 double lpp_readd(lpp_comm_t *comm);
112 char *lpp_reads(lpp_comm_t *comm);
114 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
116 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
118 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
120 void lpp_send_ack(lpp_comm_t *comm);
122 const char *lpp_get_cmd_name(int cmd);
124 #endif /* _LPP_COMM_H */