aboutsummaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-08-15 10:53:32 +1000
committerEdward O'Callaghan <quasisec@chromium.org>2022-08-25 00:25:41 +0000
commitc9ebfad95fed1dedde2d15d62299adba573f34c7 (patch)
tree2b2cba4ef766529c86ee498c4e6f37a09891018b /flashrom.c
parent3c1aa889d867669ac98a204de7b7dbe2778f814a (diff)
downloadflashrom-c9ebfad95fed1dedde2d15d62299adba573f34c7.tar.gz
flashrom-c9ebfad95fed1dedde2d15d62299adba573f34c7.tar.bz2
flashrom-c9ebfad95fed1dedde2d15d62299adba573f34c7.zip
flashrom.c: Move write_buf_to_file() to helpers_fileio.c
Constructing a written file from a buffer is auxiliary functionality to the core flashrom algorithms. Move aside to decrease the overall complexity of flashrom.c BUG=b:242246291 TEST=builds Change-Id: Ib613e74597d4bdd689043ba93aeb6a87ec80cc14 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66646 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Evan Benn <evanbenn@google.com> Reviewed-by: Sam McNally <sammc@google.com> Reviewed-by: Thomas Heijligen <src@posteo.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/flashrom.c b/flashrom.c
index 3888bca5..b66ad892 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -21,10 +21,6 @@
#include <stdio.h>
#include <sys/types.h>
-#ifndef __LIBPAYLOAD__
-#include <fcntl.h>
-#include <sys/stat.h>
-#endif
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
@@ -910,66 +906,6 @@ int read_buf_from_include_args(const struct flashrom_layout *const layout, unsig
}
/**
- * @brief Writes passed data buffer into a file
- *
- * @param buf Buffer with data to write
- * @param size Size of buffer
- * @param filename File path to write to
- * @return 0 on success
- */
-int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename)
-{
-#ifdef __LIBPAYLOAD__
- msg_gerr("Error: No file I/O support in libpayload\n");
- return 1;
-#else
- FILE *image;
- int ret = 0;
-
- if (!filename) {
- msg_gerr("No filename specified.\n");
- return 1;
- }
- if ((image = fopen(filename, "wb")) == NULL) {
- msg_gerr("Error: opening file \"%s\" failed: %s\n", filename, strerror(errno));
- return 1;
- }
-
- unsigned long numbytes = fwrite(buf, 1, size, image);
- if (numbytes != size) {
- msg_gerr("Error: file %s could not be written completely.\n", filename);
- ret = 1;
- goto out;
- }
- if (fflush(image)) {
- msg_gerr("Error: flushing file \"%s\" failed: %s\n", filename, strerror(errno));
- ret = 1;
- }
- // Try to fsync() only regular files and if that function is available at all (e.g. not on MinGW).
-#if defined(_POSIX_FSYNC) && (_POSIX_FSYNC != -1)
- struct stat image_stat;
- if (fstat(fileno(image), &image_stat) != 0) {
- msg_gerr("Error: getting metadata of file \"%s\" failed: %s\n", filename, strerror(errno));
- ret = 1;
- goto out;
- }
- if (S_ISREG(image_stat.st_mode)) {
- if (fsync(fileno(image))) {
- msg_gerr("Error: fsyncing file \"%s\" failed: %s\n", filename, strerror(errno));
- ret = 1;
- }
- }
-#endif
-out:
- if (fclose(image)) {
- msg_gerr("Error: closing file \"%s\" failed: %s\n", filename, strerror(errno));
- ret = 1;
- }
- return ret;
-#endif
-}
-
-/**
* @brief Writes content from buffer to one or more files.
*
* Writes content from supplied buffer to files. If a filename is specified for