loadfile.c 714 B

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