add sendline util + fix bugs
Signed-off-by: AGentooCat <agentoocat@mail.i2p>
This commit is contained in:
@ -21,7 +21,7 @@ PROJ_LD =
|
||||
|
||||
# set the source files to be built for the program/library
|
||||
# dont prefix src/ or src/lib/
|
||||
PROG_SRCS=main.c args.c config.c mail.c sam.c
|
||||
PROG_SRCS=main.c args.c config.c util.c mail.c sam.c
|
||||
LIB_SRCS=
|
||||
|
||||
# what the program depends on (-l<ib>)
|
||||
|
15
src/util.c
15
src/util.c
@ -1,9 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void strip_crlf(const char *text) {
|
||||
const *cur = strchr(text, 0);
|
||||
char *cur = strchr(text, 0);
|
||||
// sanely assuming that text has a NUL char
|
||||
cur -= 1;
|
||||
while (*cur == '\r' || *cur == '\n') {
|
||||
@ -11,3 +13,14 @@ void strip_crlf(const char *text) {
|
||||
cur -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
int sendline(int fd, const char *line) {
|
||||
long len = strlen(line) + 3;
|
||||
char *text = malloc(len);
|
||||
if (!text) return -1;
|
||||
strcpy(text, line);
|
||||
strcat(text, "\r\n");
|
||||
text[len - 1] = 0;
|
||||
|
||||
return write(fd, line, len - 1);
|
||||
}
|
||||
|
@ -10,5 +10,6 @@
|
||||
}
|
||||
|
||||
void strip_crlf(const char *text);
|
||||
int sendline(int fd, const char *line);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user