You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
870 B

  1. /*
  2. * Serial I/O helper routines
  3. *
  4. * Jim Paris <jim@jtan.com>
  5. * $Id$
  6. */
  7. #ifndef UTIL_H
  8. #define UTIL_H
  9. #include <unistd.h>
  10. /* Open serial port in raw mode, with custom baudrate if necessary */
  11. int serial_open(const char *device, int rate);
  12. /* Like read(), but restarts after EINTR, and reads until count bytes
  13. are received or a timeout occurs. */
  14. int saferead_timeout(int fd, void *buf, size_t count, int timeout_ms);
  15. /* Like write(), but restarts after EINTR */
  16. ssize_t safewrite(int fd, const void *buf, size_t count);
  17. /* Read bytes until no more are available for 0.1 sec */
  18. int drain(int fd);
  19. /* Like fprintf, but to a fd, using safewrite */
  20. int fdprintf(int fd, const char *fmt, ...);
  21. /* Like fgets, but from a fd, using saferead_timeout. */
  22. char *fdgets(char *s, int size, int fd, int timeout_ms);
  23. /* Like perl chomp. */
  24. void chomp(char *s);
  25. #endif