cake
/
p7utils
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
p7utils/src/p7os/prepare.c

70 lines
2.6 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* p7os/prepare.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/01/16 23:56:41 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
/* ************************************************************************** */
/* Error messages */
/* ************************************************************************** */
/* Unable to open the embedded thingy */
static const char error_fmemopen[] =
"Unable to open the embedded update.exe.\n";
/* ************************************************************************** */
/* Embedded update.exe */
/* ************************************************************************** */
#define cake_exe_str (_binary_cake_exe_bin_start)
#define cake_exe_end (_binary_cake_exe_bin_end)
extern char _binary_cake_exe_bin_start[];
extern char _binary_cake_exe_bin_end[];
/* ************************************************************************** */
/* Main function */
/* ************************************************************************** */
/**
* prepare_ops:
* Prepare the operation, by uploading the update.exe.
*
* @arg handle the libp7 handle.
* @arg uexe the update.exe to use (NULL if use the embedded one).
* @return the error (-1 if not a libp7 error, 0 if ok)
*/
int prepare_ops(p7_handle_t *handle, FILE *uexe, void (*disp)())
{
int err; size_t usize;
/* prepare the update.exe */
if (uexe) {
/* calculate the size */
fseek(uexe, 0, SEEK_END);
usize = ftell(uexe);
fseek(uexe, 0, SEEK_SET);
} else {
/* take the default uexe */
usize = (size_t)&cake_exe_end - (size_t)&cake_exe_str;
uexe = fmemopen(cake_exe_str, usize, "r");
if (!uexe) {
fprintf(stderr, error_fmemopen);
return (-1);
}
}
/* send the thing */
if ((err = p7_sendexe_stream(handle, uexe, (p7uint_t)usize,
0x88030000, 0x88030000, disp))) {
fclose(uexe);
return (err);
}
/* no error! */
fclose(uexe);
return (0);
}