Skip to content

Instantly share code, notes, and snippets.

@rmccullagh
Last active December 11, 2015 21:56
Show Gist options
  • Select an option

  • Save rmccullagh/adf36bd63a32e5156c59 to your computer and use it in GitHub Desktop.

Select an option

Save rmccullagh/adf36bd63a32e5156c59 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2015 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "io.h"
int write_bytes_to_stream(FILE* fp, const void* data, size_t size)
{
const unsigned char* bytes;
size_t nwritten;
int retval;
bytes = (const unsigned char*)data;
nwritten = fwrite(bytes, size, 1, fp);
if(nwritten != 1) {
retval = -1;
} else {
retval = 0;
}
return retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment