#include #include #include #include "definitions.h" #include "rs232.h" int rs232_getline(int file_descriptor, char *buffer, size_t max_bytes_to_read, size_t *bytes_read) { unsigned char c; int i=0; while (max_bytes_to_read > 0) { if (read(file_descriptor, &(c), 1) == -1) { fprintf(stderr, "*ERROR* Failed to read character from file_descriptor %d!\n", file_descriptor); fflush(stderr); return FAILURE; } if (c == TERMINATOR) { break; /* found the final terminator. Now exit the loop */ } else { buffer[i] = (char) c; } buffer[i+1] = '\0'; i++; max_bytes_to_read--; } *bytes_read = (size_t) (i-1); buffer[i-1] = '\0'; return SUCCESS; }