2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
17 #include <sys/types.h>
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
27 int open_or_die(const char *file
, int flags
)
29 int ret
= open(file
, flags
);
31 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");
45 ssize_t
read_or_die(int fd
, void *buf
, size_t len
)
47 ssize_t ret
= read(fd
, buf
, len
);
51 panic("Read error!!\n");
57 ssize_t
write_or_die(int fd
, const void *buf
, size_t len
)
59 ssize_t ret
= write(fd
, buf
, len
);
63 panic("Write error!!\n");
69 size_t strlcpy(char *dest
, const char *src
, size_t size
)
71 size_t ret
= strlen(src
);
73 size_t len
= (ret
>= size
) ? size
- 1 : ret
;
75 memcpy(dest
, src
, len
);
82 int slprintf(char *dst
, size_t size
, const char *fmt
, ...)
88 ret
= vsnprintf(dst
, size
, fmt
, ap
);
95 char **strntoargv(char *str
, size_t len
, int *argc
)
101 panic("argc is null!\n");
103 if (len
<= 1) /* '\0' */
106 while (len
> 0 && *str
== ' ') {
110 if (len
> 0 && *str
!= '\0') {
112 argv
= xrealloc(argv
, 1, sizeof(char *) * (*argc
));
113 argv
[(*argc
) - 1] = str
;
114 while (len
> 0 && *str
!= ' ') {
118 if (len
> 0 && *str
== ' ') {