mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-12-25 02:29:49 +00:00
get file size using stat, which seems to be more reliable
This commit is contained in:
parent
521da856b5
commit
2d14b5fb8b
@ -30,6 +30,7 @@
|
|||||||
#include <mach/vm_prot.h>
|
#include <mach/vm_prot.h>
|
||||||
#include <mach-o/loader.h>
|
#include <mach-o/loader.h>
|
||||||
#include <mach-o/fat.h>
|
#include <mach-o/fat.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
static const char progname[] = "lowmem";
|
static const char progname[] = "lowmem";
|
||||||
static const char *filename;
|
static const char *filename;
|
||||||
@ -134,6 +135,7 @@ main(int argc, const char *argv[])
|
|||||||
struct mach_header_64 *machhead64;
|
struct mach_header_64 *machhead64;
|
||||||
#endif
|
#endif
|
||||||
struct fat_header *fathead;
|
struct fat_header *fathead;
|
||||||
|
struct stat f;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
(void)fprintf(stderr, "Usage: %s executable\n", progname);
|
(void)fprintf(stderr, "Usage: %s executable\n", progname);
|
||||||
@ -142,6 +144,13 @@ main(int argc, const char *argv[])
|
|||||||
|
|
||||||
filename = argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
|
if (stat(filename, &f)) {
|
||||||
|
(void)fprintf(stderr, "%s: could not stat %s: %s\n",
|
||||||
|
progname, filename, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
file_size = f.st_size;
|
||||||
|
|
||||||
fd = open(filename, O_RDWR, 0);
|
fd = open(filename, O_RDWR, 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
(void)fprintf(stderr, "%s: could not open %s: %s\n",
|
(void)fprintf(stderr, "%s: could not open %s: %s\n",
|
||||||
@ -149,17 +158,6 @@ main(int argc, const char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size = lseek(fd, 0, SEEK_END);
|
|
||||||
if (file_size == -1) {
|
|
||||||
// for some mysterious reason, this sometimes fails...
|
|
||||||
file_size = 0x1000;
|
|
||||||
#if 0
|
|
||||||
(void)fprintf(stderr, "%s: could not get size of %s: %s\n",
|
|
||||||
progname, filename, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Size does not really matter, it will be rounded-up to a multiple
|
* Size does not really matter, it will be rounded-up to a multiple
|
||||||
* of the page size automatically.
|
* of the page size automatically.
|
||||||
|
Loading…
Reference in New Issue
Block a user