ScrapExplorer - write.c
Home / lab / c / writing_raw Lines: 1 | Size: 1053 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* SPDX-License-Identifier: GPL-3.0 2 * writing_raw 3 * 4 * write.c 5 * 6 * COPYRIGHT NOTICE 7 * Copyright (C) 2024-2025 0x4248 and contributors 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the license is not changed. 10 * 11 * This software is free and open source. Licensed under the GNU general 12 * public license version 3.0 as published by the Free Software Foundation. 13*/ 14 15#include <stdio.h> 16#include <stdint.h> 17 18#include "write.h" 19 20/** 21 * Write data - Writes raw chars to a file. 22 * 23 * @param data - The data to write. 24 * @param filename - The filename to write to. 25 * @param buffer_size - The size of the buffer. 26 */ 27int write_data(const uint8_t data[], 28 const char *filename, 29 const int buffer_size) { 30 FILE *file = fopen(filename, "wb"); 31 if (file == NULL) { 32 perror("fopen"); 33 return -1; 34 } 35 36 size_t written = fwrite(data, sizeof(uint8_t), buffer_size, file); 37 if (written != buffer_size) { 38 perror("fwrite"); 39 fclose(file); 40 return -1; 41 } 42 43 fclose(file); 44 return 0; 45}[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.