Assembler/src/image_saver.c
2023-02-25 19:41:58 +01:00

28 lines
No EOL
611 B
C

/*
This code is part of the EIPA Platform
This code contains the implementations of all functions related to saving EIPA target code to an EIPA image
*/
#include <stdio.h>
#include <errno.h>
int save_img(char *out_path, __uint32_t *target_code){
FILE *out_file = fopen(out_path, "wb");
if(out_file == NULL) return EIO;
// Count instructions
unsigned int count = 0;
while(target_code[count]!=0)
{
count++;
}
if (fwrite(target_code, sizeof(target_code), count, out_file) != count)
{
// Couldn't save the image
return EIO;
}
return 0;
}