fs.c 608 B

123456789101112131415161718192021222324252627282930
  1. #define _XOPEN_SOURCE 700
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. int main() {
  9. int fd = open("test.open.file", O_CREAT | O_RDWR, S_IRWXU);
  10. int fd2 = open("fs.manifest", O_RDONLY);
  11. char* buf = malloc(4096);
  12. int ret;
  13. while ((ret = read(fd2, buf, 4096)) > 0) {
  14. if (write(1, buf, ret) != ret || write(fd, buf, ret) != ret) {
  15. perror("write error");
  16. return 1;
  17. }
  18. }
  19. if (ret < 0) {
  20. perror("read error");
  21. return 1;
  22. }
  23. close(fd);
  24. return 0;
  25. }