Mirror of CollapseOS
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

39 行
774B

  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 = open(argv[1], O_RDWR|O_NOCTTY|O_SYNC);
  15. if (fd < 0) {
  16. fprintf(stderr, "Could not open %s\n", argv[1]);
  17. return 1;
  18. }
  19. set_interface_attribs(fd, 0, 0);
  20. set_blocking(fd, 0);
  21. int c = getchar();
  22. while (c != EOF) {
  23. if (c == '\n') c = '\r';
  24. write(fd, &c, 1);
  25. while (read(fd, &c, 1) == 1) {
  26. putchar(c);
  27. fflush(stdout);
  28. }
  29. c = getchar();
  30. }
  31. printf("Done!\n");
  32. return 0;
  33. }