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.

38 lines
716B

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include "common.h"
  6. /* Execute code from stdin on the target machine.
  7. */
  8. int main(int argc, char **argv)
  9. {
  10. if (argc != 2) {
  11. fprintf(stderr, "Usage: ./exec device\n");
  12. return 1;
  13. }
  14. int fd = ttyopen(argv[1]);
  15. if (fd < 0) {
  16. fprintf(stderr, "Could not open %s\n", argv[1]);
  17. return 1;
  18. }
  19. set_blocking(fd, 0);
  20. int c = getchar();
  21. while (c != EOF) {
  22. if (c == '\n') c = '\r';
  23. write(fd, &c, 1);
  24. while (read(fd, &c, 1) == 1) {
  25. putchar(c);
  26. fflush(stdout);
  27. }
  28. c = getchar();
  29. }
  30. printf("Done!\n");
  31. return 0;
  32. }