10 #include <sys/types.h>
12 #include <sys/types.h>
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>
20 int open_or_die(const char *file
, int flags
)
22 int ret
= open(file
, flags
);
24 panic("Open error!!\n");
28 int open_or_die_m(const char *file
, int flags
, mode_t mode
)
30 int ret
= open(file
, flags
, mode
);
32 panic("Open error!!\n");
36 ssize_t
read_or_die(int fd
, void *buf
, size_t len
)
38 ssize_t ret
= read(fd
, buf
, len
);
42 panic("Read error!!\n");
48 ssize_t
write_or_die(int fd
, const void *buf
, size_t len
)
50 ssize_t ret
= write(fd
, buf
, len
);
54 panic("Write error!!\n");
60 size_t strlcpy(char *dest
, const char *src
, size_t size
)
62 size_t ret
= strlen(src
);
64 size_t len
= (ret
>= size
) ? size
- 1 : ret
;
65 memcpy(dest
, src
, len
);
71 int slprintf(char *dst
, size_t size
, const char *fmt
, ...)
76 ret
= vsnprintf(dst
, size
, fmt
, ap
);
82 char **strntoargv(char *str
, size_t len
, int *argc
)
88 panic("argc is null!\n");
90 if (len
<= 1) /* '\0' */
93 while (len
> 0 && *str
== ' ') {
97 if (len
> 0 && *str
!= '\0') {
99 argv
= xrealloc(argv
, 1, sizeof(char *) * (*argc
));
100 argv
[(*argc
) - 1] = str
;
101 while (len
> 0 && *str
!= ' ') {
105 if (len
> 0 && *str
== ' ') {