1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/dist/tools/riotboot_gen_hdr/common.c
Francisco Acosta a638f31bce dist/tools: add genhdr tool to generate RIOT image headers
In order to use the RIOT bootloader (riotboot) a header needs to
be created and placed before the firmware. This tool generates
such a header with the expected information by the bootloader.

Co-authored-by: Kaspar Schleiser <kaspar@schleiser.de>
2018-12-18 19:31:34 +01:00

40 lines
810 B
C

/*
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU General Public
* License v2. See the file LICENSE for more details.
*/
/**
* @file
* @brief Common tools for RIOT images header generation
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
int to_file(const char *filename, void *buf, size_t len)
{
int fd;
if (strcmp("-", filename)) {
fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
}
else {
fd = STDOUT_FILENO;
}
if (fd > 0) {
ssize_t res = write(fd, buf, len);
close(fd);
return res == (ssize_t)len;
}
else {
return fd;
}
}