Mirror of CollapseOS
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.

27 lines
559B

  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. void sendcmd(int fd, char *cmd)
  4. {
  5. char junk[2];
  6. while (*cmd) {
  7. write(fd, cmd, 1);
  8. read(fd, &junk, 1);
  9. cmd++;
  10. // The other side is sometimes much slower than us and if we don't let
  11. // it breathe, it can choke.
  12. usleep(1000);
  13. }
  14. write(fd, "\n", 1);
  15. read(fd, &junk, 2); // sends back \r\n
  16. usleep(1000);
  17. }
  18. // Send a cmd and also read the "> " prompt
  19. void sendcmdp(int fd, char *cmd)
  20. {
  21. char junk[2];
  22. sendcmd(fd, cmd);
  23. read(fd, &junk, 2);
  24. }