I think I just implemented patty_kiss_write(); tons o' system calls, but fuggit man!
This commit is contained in:
parent
b5ef56c4a0
commit
facedcebb6
1 changed files with 41 additions and 0 deletions
41
src/kiss.c
41
src/kiss.c
|
@ -75,3 +75,44 @@ ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port) {
|
|||
error_io:
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port) {
|
||||
size_t i;
|
||||
|
||||
unsigned char escape_fend[2] = { PATTY_KISS_FESC, PATTY_KISS_TFEND };
|
||||
unsigned char escape_fesc[2] = { PATTY_KISS_FESC, PATTY_KISS_TFESC };
|
||||
|
||||
unsigned char command = (port & 0x0f) << 4;
|
||||
|
||||
if (write(fd, &command, 1) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
unsigned char c = ((unsigned char *)buf)[i];
|
||||
ssize_t res = 0;
|
||||
|
||||
switch (c) {
|
||||
case PATTY_KISS_FEND: {
|
||||
res = write(fd, escape_fend, sizeof(escape_fend)); break;
|
||||
}
|
||||
|
||||
case PATTY_KISS_FESC: {
|
||||
res = write(fd, escape_fesc, sizeof(escape_fesc)); break;
|
||||
}
|
||||
|
||||
default: {
|
||||
res = write(fd, &c, 1); break;
|
||||
}
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_io:
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue