Loading...
Searching...
No Matches
libopenmpt_stream_callbacks_file_posix_lfs64.h
Go to the documentation of this file.
/*
* libopenmpt_stream_callbacks_file_posix_lfs64.h
* ----------------------------------------------
* Purpose: libopenmpt public c interface
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#ifndef LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX_LFS64_H
#define LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX_LFS64_H
#include "libopenmpt.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
static size_t openmpt_stream_file_posix_lfs64_read_func( void * stream, void * dst, size_t bytes ) {
FILE * f = 0;
size_t retval = 0;
f = (FILE*)stream;
if ( !f ) {
return 0;
}
retval = fread( dst, 1, bytes, f );
if ( retval <= 0 ) {
return 0;
}
return retval;
}
static int openmpt_stream_file_posix_lfs64_seek_func( void * stream, int64_t offset, int whence ) {
FILE * f = 0;
int fwhence = 0;
f = (FILE*)stream;
if ( !f ) {
return -1;
}
switch ( whence ) {
case OPENMPT_STREAM_SEEK_SET:
fwhence = SEEK_SET;
break;
case OPENMPT_STREAM_SEEK_CUR:
fwhence = SEEK_CUR;
break;
case OPENMPT_STREAM_SEEK_END:
fwhence = SEEK_END;
break;
default:
return -1;
break;
}
if ( (off64_t)offset != offset ) {
return -1;
}
return fseeko64( f, (off64_t)offset, fwhence ) ? -1 : 0;
}
static int64_t openmpt_stream_file_posix_lfs64_tell_func( void * stream ) {
FILE * f = 0;
off64_t result = 0;
int64_t retval = 0;
f = (FILE*)stream;
if ( !f ) {
return -1;
}
result = ftello64( f );
if ( (int64_t)result != result ) {
return -1;
}
retval = (int64_t)result;
if ( retval < 0 ) {
return -1;
}
return retval;
}
static openmpt_stream_callbacks openmpt_stream_get_file_posix_lfs64_callbacks(void) {
openmpt_stream_callbacks retval;
memset( &retval, 0, sizeof( openmpt_stream_callbacks ) );
retval.read = openmpt_stream_file_posix_lfs64_read_func;
retval.seek = openmpt_stream_file_posix_lfs64_seek_func;
retval.tell = openmpt_stream_file_posix_lfs64_tell_func;
return retval;
}
#ifdef __cplusplus
}
#endif
#endif /* LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX_LFS64_H */
OPENMPT_STREAM_SEEK_SET
#define OPENMPT_STREAM_SEEK_SET
Definition libopenmpt.h:253
OPENMPT_STREAM_SEEK_CUR
#define OPENMPT_STREAM_SEEK_CUR
Definition libopenmpt.h:255
openmpt_stream_file_posix_lfs64_read_func
static size_t openmpt_stream_file_posix_lfs64_read_func(void *stream, void *dst, size_t bytes)
Definition libopenmpt_stream_callbacks_file_posix_lfs64.h:27
openmpt_stream_file_posix_lfs64_tell_func
static int64_t openmpt_stream_file_posix_lfs64_tell_func(void *stream)
Definition libopenmpt_stream_callbacks_file_posix_lfs64.h:68
openmpt_stream_get_file_posix_lfs64_callbacks
static openmpt_stream_callbacks openmpt_stream_get_file_posix_lfs64_callbacks(void)
Provide openmpt_stream_callbacks for standard C FILE objects.
Definition libopenmpt_stream_callbacks_file_posix_lfs64.h:98
OPENMPT_STREAM_SEEK_END
#define OPENMPT_STREAM_SEEK_END
Definition libopenmpt.h:257
openmpt_stream_file_posix_lfs64_seek_func
static int openmpt_stream_file_posix_lfs64_seek_func(void *stream, int64_t offset, int whence)
Definition libopenmpt_stream_callbacks_file_posix_lfs64.h:41
libopenmpt.h
openmpt_stream_callbacks
Stream callbacks.
Definition libopenmpt.h:300
openmpt_stream_callbacks::read
openmpt_stream_read_func read
Read callback.
Definition libopenmpt.h:306
openmpt_stream_callbacks::seek
openmpt_stream_seek_func seek
Seek callback.
Definition libopenmpt.h:313
openmpt_stream_callbacks::tell
openmpt_stream_tell_func tell
Tell callback.
Definition libopenmpt.h:320