diff --git a/lib/src/tools.c b/lib/src/tools.c index bcf533a..4bacb8a 100644 --- a/lib/src/tools.c +++ b/lib/src/tools.c @@ -1,4 +1,37 @@ #include "time.h" +#include +#include +#include +#include +#include + + +int sendlen(int sock, char *buf, int len) +{ + int done, todo; + + for (todo = len; todo; todo -= done, buf += done) + if ((done = send(sock, buf, todo, 0)) < 0) { + printf("sendlen error\n"); + return done; + } + return len; +} + +int sendstring(int sock, char *fmt, ...) +{ + int len; + uint8_t buf[2048]; + va_list args; + + va_start(args, fmt); + len = vsnprintf(buf, sizeof(buf), fmt, args); + if (len <= 0 || len >= sizeof(buf)) + return 0; + sendlen(sock, buf, len); + va_end(args); + return len; +} time_t mtime(time_t *t) { diff --git a/lib/src/tools.h b/lib/src/tools.h index fe4d637..06c8593 100644 --- a/lib/src/tools.h +++ b/lib/src/tools.h @@ -2,5 +2,7 @@ #define _DDDVB_TOOLS_H_ time_t mtime(time_t *t); +int sendlen(int sock, char *buf, int len); +int sendstring(int sock, char *fmt, ...); #endif /* _DDDVB_TOOLS_H_ */