dup.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2015 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. /* check devdup Nctl format */
  21. void
  22. main(void)
  23. {
  24. char buf[256];
  25. int fd, r;
  26. fd = open("/fd/0ctl", OREAD|OCEXEC);
  27. if(fd < 0)
  28. goto Fail;
  29. r = read(fd, buf, sizeof(buf));
  30. if(r < 0)
  31. goto Fail;
  32. close(fd);
  33. print("Got 0ctl: %s\n", buf);
  34. fd = open("/fd/1ctl", OREAD|OCEXEC);
  35. if(fd < 0)
  36. goto Fail;
  37. r = read(fd, buf, sizeof(buf));
  38. if(r < 0)
  39. goto Fail;
  40. close(fd);
  41. print("Got 1ctl: %s\n", buf);
  42. fd = open("/fd/2ctl", OREAD|OCEXEC);
  43. if(fd < 0)
  44. goto Fail;
  45. r = read(fd, buf, sizeof(buf));
  46. if(r < 0)
  47. goto Fail;
  48. print("Got 2ctl: %s\n", buf);
  49. snprint(buf, sizeof(buf), "/fd/%dctl", fd);
  50. fd = open(buf, OREAD);
  51. if(fd < 0)
  52. goto Fail;
  53. r = read(fd, buf, sizeof(buf));
  54. if(r < 0)
  55. goto Fail;
  56. print("Got: %s\n", buf);
  57. close(fd);
  58. exits(nil);
  59. Fail:
  60. print("FAIL\n");
  61. exits("FAIL");
  62. }