loadfile.c 622 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * File functions - The peTI-NESulator Project
  3. * os/macos/load.c
  4. *
  5. * Copyright (c) 2002-2019 986-Studio.
  6. *
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <signal.h>
  12. #include <sys/mman.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <unistd.h>
  16. #include <fcntl.h>
  17. #include <os_dependent.h>
  18. /* Map a file in memory */
  19. void *LoadFilePtr(char * filename)
  20. {
  21. int fd;
  22. void *RetPtr;
  23. struct stat FileStat;
  24. fd = open(filename, O_RDONLY);
  25. fstat(fd, &FileStat);
  26. RetPtr = mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
  27. close(fd);
  28. return RetPtr;
  29. }