change the send_string function, to accept null pointers and send them

as empty strings.
pull/16/head v1.1
John Tsiombikas 2022-04-26 17:19:43 +03:00
rodzic 92481ccbe6
commit 1716ccf15f
1 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -10,16 +10,18 @@ int spnav_send_str(int fd, int req, const char *str)
int len;
struct reqresp rr = {0};
if(fd == -1 || !str) {
if(fd == -1) {
return -1;
}
len = strlen(str);
len = str ? strlen(str) : 0;
rr.type = req;
rr.data[6] = len;
do {
memcpy(rr.data, str, len > REQSTR_CHUNK_SIZE ? REQSTR_CHUNK_SIZE : len);
if(str) {
memcpy(rr.data, str, len > REQSTR_CHUNK_SIZE ? REQSTR_CHUNK_SIZE : len);
}
write(fd, &rr, sizeof rr);
str += REQSTR_CHUNK_SIZE;
len -= REQSTR_CHUNK_SIZE;