diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/tools.c | 20 | ||||
-rw-r--r-- | mdk-stage1/tools.h | 1 |
2 files changed, 14 insertions, 7 deletions
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index aa9be8f83..58c9203df 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -191,15 +191,21 @@ int charstar_to_int(const char * s) return number; } +off_t file_size(const char * path) +{ + struct stat statr; + if (stat(path, &statr)) + return -1; + else + return statr.st_size; +} + int total_memory(void) { int value; - struct stat statr; - if (stat("/proc/kcore", &statr)) - return 0; /* drakx powered: use /proc/kcore and rounds every 4 Mbytes */ - value = 4 * ((int)((float)statr.st_size / 1024 / 1024 / 4 + 0.5)); + value = 4 * ((int)((float)file_size("/proc/kcore") / 1024 / 1024 / 4 + 0.5)); log_message("Total Memory: %d Mbytes", value); return value; @@ -346,7 +352,7 @@ char * get_ramdisk_realname(void) enum return_type load_ramdisk(void) { int st2_fd; - struct stat statr; + off_t size; char img_name[500]; strcpy(img_name, IMAGE_LOCATION); @@ -362,10 +368,10 @@ enum return_type load_ramdisk(void) return RETURN_ERROR; } - if (stat(img_name, &statr)) + if ((size = file_size(img_name)) == -1) return RETURN_ERROR; else - return load_ramdisk_fd(st2_fd, statr.st_size); + return load_ramdisk_fd(st2_fd, size); } /* pixel's */ diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 9da8c3445..29bfc5f62 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -29,6 +29,7 @@ int get_param(int i); void set_param(int i); void unset_param(int i); int charstar_to_int(const char * s); +off_t file_size(const char * path); int total_memory(void); int ramdisk_possible(void); char * get_ramdisk_realname(void); |