mirror of
https://github.com/DigitalDevices/dddvb.git
synced 2023-10-10 13:37:43 +02:00
add sendlen/sendstring
This commit is contained in:
parent
f2ca278710
commit
1064f47fd9
@ -1,4 +1,37 @@
|
||||
#include "time.h"
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user