2 * transsip - the telephony network
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
18 #include <sys/types.h>
20 #include <sys/types.h>
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
28 int open_or_die(const char *file
, int flags
)
30 int ret
= open(file
, flags
);
32 panic("Open error!!\n");
36 int open_or_die_m(const char *file
, int flags
, mode_t mode
)
38 int ret
= open(file
, flags
, mode
);
40 panic("Open error!!\n");
44 ssize_t
read_or_die(int fd
, void *buf
, size_t len
)
46 ssize_t ret
= read(fd
, buf
, len
);
50 panic("Read error!!\n");
56 ssize_t
write_or_die(int fd
, const void *buf
, size_t len
)
58 ssize_t ret
= write(fd
, buf
, len
);
62 panic("Write error!!\n");
68 size_t strlcpy(char *dest
, const char *src
, size_t size
)
70 size_t ret
= strlen(src
);
72 size_t len
= (ret
>= size
) ? size
- 1 : ret
;
73 memcpy(dest
, src
, len
);
79 int slprintf(char *dst
, size_t size
, const char *fmt
, ...)
84 ret
= vsnprintf(dst
, size
, fmt
, ap
);
90 char **strntoargv(char *str
, size_t len
, int *argc
)
96 panic("argc is null!\n");
98 if (len
<= 1) /* '\0' */
101 while (len
> 0 && *str
== ' ') {
105 if (len
> 0 && *str
!= '\0') {
107 argv
= xrealloc(argv
, 1, sizeof(char *) * (*argc
));
108 argv
[(*argc
) - 1] = str
;
109 while (len
> 0 && *str
!= ' ') {
113 if (len
> 0 && *str
== ' ') {