38 lines
1.3 KiB
C
38 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* utils/filebuffer.c |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2017/02/19 22:35:20 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include <libg1m/internals.h>
|
|
#ifndef G1M_DISABLED_FILE
|
|
|
|
/**
|
|
* g1m_filebuffer_read:
|
|
* Read from a filebuffer.
|
|
*
|
|
* @arg vcookie the FILE* (uncasted)
|
|
* @arg buf the buffer to fill.
|
|
* @arg size the size to read.
|
|
* @return the error (if any).
|
|
*/
|
|
|
|
int g1m_filebuffer_read(void *vcookie, unsigned char *buf, size_t size)
|
|
{
|
|
FILE *file = (void*)vcookie;
|
|
size_t read = fread(buf, 1, size, file);
|
|
if (!read) {
|
|
log_error("READING failed: read %" PRIuSIZE "/%" PRIuSIZE
|
|
" bytes, %" PRIuSIZE " missing.", read, size, size - read);
|
|
return (g1m_error_eof);
|
|
}
|
|
|
|
/* no error */
|
|
return (0);
|
|
}
|
|
|
|
#endif
|