Convert file size to 32-bit type before writing.

This commit is contained in:
rick-masters 2023-05-21 00:11:37 +00:00
parent 1603b81602
commit ef08891401
2 changed files with 7 additions and 3 deletions

View File

@ -62,7 +62,7 @@ d85cff8f9ff76533287891ec2019416fa585815e514743e5b76efd9f17f5ef5c grep-3.7_0.tar
b38422d646590600444f0ff12fee6fd738baaf471338aa67899db950d3521127 guile-3.0.9_0.tar.bz2
8d2015b87337abbf287f7a39ee4cf53514120b5d3e90a93fe7d533dcc43f14fa help2man-1.36.4_0.tar.bz2
3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2
6cb8bd6df0472665cd82ef4f4eae8368543a4d04eb90ec5f6cf4f224d1e16e51 kexec-linux-1.0.0_0.tar.bz2
d23886557310f7ff2c98898eac24b4fe8704b22e88d094e96ff996cf0d2635a4 kexec-linux-1.0.0_0.tar.bz2
2a661da13801028f5af98e5d9f6de417c21c90df1bcef4809caf0c2094fdd8f4 kexec-tools-2.0.22_0.tar.bz2
e89e4fc8ba4f917f4f609ba781fc13e43d31479d47a9da2ba3bc7ce5fcbbe6b3 libarchive-3.5.2_0.tar.bz2
36550df491767bb24d2ccab304ce70a3b4956e7c0c0e0c343d922fd57cdafbdd libatomic_ops-7.6.10_0.tar.bz2

View File

@ -2,6 +2,7 @@
/* SPDX-License-Identifier: MIT */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <sys/stat.h>
@ -14,6 +15,7 @@ int main(int argc, char **argv) {
char *ramdrive_file_name, *kernel_file_name, *initramfs_file_name;
FILE *ramdrive_file;
struct stat stats;
uint32_t size;
if (argc < 3) {
puts("Usage: fiwix-kexec-linux <ram-drive-name> <kernel-file-name> <initramfs-file-name>");
@ -29,7 +31,8 @@ int main(int argc, char **argv) {
/* Write length of kernel */
if (stat(kernel_file_name, &stats) == 0) {
fwrite(&stats.st_size, 4, 1, ramdrive_file);
size = (uint32_t) stats.st_size;
fwrite(&size, sizeof(size), 1, ramdrive_file);
} else {
fprintf(stderr, "Cannot stat kernel file '%s'\n", kernel_file_name);
exit(1);
@ -37,7 +40,8 @@ int main(int argc, char **argv) {
/* Write length of initramfs */
if (stat(initramfs_file_name, &stats) == 0) {
fwrite(&stats.st_size, 4, 1, ramdrive_file);
size = (uint32_t) stats.st_size;
fwrite(&size, sizeof(size), 1, ramdrive_file);
} else {
fprintf(stderr, "Cannot stat initramfs file '%s'\n", initramfs_file_name);
exit(1);