ReactOS 0.4.16-dev-122-g325d74c
lfs_wrap.c File Reference
#include "mpg123lib_intern.h"
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "compat.h"
#include "debug.h"
Include dependency graph for lfs_wrap.c:

Go to the source code of this file.

Classes

struct  wrap_data
 

Macros

#define IO_FD   1 /* Wrapping over callbacks operation on integer file descriptor. */
 
#define IO_HANDLE   2 /* Wrapping over custom handle callbacks. */
 
#define O_BINARY   0
 

Functions

static void wrap_io_cleanup (void *handle)
 
static void wrap_destroy (void *handle)
 
static struct wrap_datawrap_get (mpg123_handle *mh)
 
int attribute_align_arg mpg123_decode_frame (mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
 
int attribute_align_arg mpg123_framebyframe_decode (mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
 
long attribute_align_arg mpg123_framepos (mpg123_handle *mh)
 
long attribute_align_arg mpg123_tell (mpg123_handle *mh)
 
long attribute_align_arg mpg123_tellframe (mpg123_handle *mh)
 
long attribute_align_arg mpg123_tell_stream (mpg123_handle *mh)
 
long attribute_align_arg mpg123_seek (mpg123_handle *mh, long sampleoff, int whence)
 
long attribute_align_arg mpg123_feedseek (mpg123_handle *mh, long sampleoff, int whence, long *input_offset)
 
long attribute_align_arg mpg123_seek_frame (mpg123_handle *mh, long frameoff, int whence)
 
long attribute_align_arg mpg123_timeframe (mpg123_handle *mh, double sec)
 
int attribute_align_arg mpg123_index (mpg123_handle *mh, long **offsets, long *step, size_t *fill)
 
int attribute_align_arg mpg123_set_index (mpg123_handle *mh, long *offsets, long step, size_t fill)
 
int attribute_align_arg mpg123_position (mpg123_handle *mh, long frame_offset, long buffered_bytes, long *current_frame, long *frames_left, double *current_seconds, double *seconds_left)
 
long attribute_align_arg mpg123_framelength (mpg123_handle *mh)
 
long attribute_align_arg mpg123_length (mpg123_handle *mh)
 
int attribute_align_arg mpg123_set_filesize (mpg123_handle *mh, long size)
 
ssize_t wrap_read (void *handle, void *buf, size_t count)
 
off_t wrap_lseek (void *handle, off_t offset, int whence)
 
static ssize_t fallback_read (int fd, void *buf, size_t count)
 
static long fallback_lseek (int fd, long offset, int whence)
 
int attribute_align_arg mpg123_replace_reader (mpg123_handle *mh, ssize_t(*r_read)(int, void *, size_t), long(*r_lseek)(int, long, int))
 
int attribute_align_arg mpg123_replace_reader_handle (mpg123_handle *mh, ssize_t(*r_read)(void *, void *, size_t), long(*r_lseek)(void *, long, int), void(*cleanup)(void *))
 
int attribute_align_arg mpg123_open (mpg123_handle *mh, const char *path)
 
int attribute_align_arg mpg123_open_fixed (mpg123_handle *mh, const char *path, int channels, int encoding)
 
int attribute_align_arg mpg123_open_fd (mpg123_handle *mh, int fd)
 
int attribute_align_arg mpg123_open_handle (mpg123_handle *mh, void *handle)
 

Macro Definition Documentation

◆ IO_FD

#define IO_FD   1 /* Wrapping over callbacks operation on integer file descriptor. */

Definition at line 72 of file lfs_wrap.c.

◆ IO_HANDLE

#define IO_HANDLE   2 /* Wrapping over custom handle callbacks. */

Definition at line 73 of file lfs_wrap.c.

◆ O_BINARY

#define O_BINARY   0

Definition at line 527 of file lfs_wrap.c.

Function Documentation

◆ fallback_lseek()

static long fallback_lseek ( int  fd,
long  offset,
int  whence 
)
static

Definition at line 584 of file lfs_wrap.c.

585{
586 /* Since the offset is long int already, the returned value really should fit into a long... but whatever. */
587 long newpos_long;
588 off_t newpos;
589 newpos = lseek(fd, offset, whence);
590 newpos_long = newpos;
591 if(newpos_long == newpos)
592 return newpos_long;
593 else
594 {
596 return -1;
597 }
598}
#define EOVERFLOW
Definition: errno.h:82
__kernel_off_t off_t
Definition: linux.h:201
GLintptr offset
Definition: glext.h:5920
#define lseek
Definition: syshdrs.h:47
#define errno
Definition: errno.h:18
static int fd
Definition: io.c:51

Referenced by mpg123_replace_reader().

◆ fallback_read()

static ssize_t fallback_read ( int  fd,
void buf,
size_t  count 
)
static

Definition at line 579 of file lfs_wrap.c.

580{
581 return read(fd, buf, count);
582}
#define read
Definition: acwin.h:96
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by mpg123_replace_reader().

◆ wrap_destroy()

static void wrap_destroy ( void handle)
static

Definition at line 115 of file lfs_wrap.c.

116{
117 struct wrap_data *wh = handle;
119 if(wh->indextable != NULL)
120 free(wh->indextable);
121
122 free(wh);
123}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
static void wrap_io_cleanup(void *handle)
Definition: lfs_wrap.c:97
long * indextable
Definition: lfs_wrap.c:78
void * handle
Definition: lfs_wrap.c:88

Referenced by wrap_get().

◆ wrap_get()

static struct wrap_data * wrap_get ( mpg123_handle mh)
static

Definition at line 126 of file lfs_wrap.c.

127{
128 struct wrap_data* whd;
129 if(mh == NULL) return NULL;
130
131 /* Access the private storage inside the mpg123 handle.
132 The real callback functions and handles are stored there. */
133 if(mh->wrapperdata == NULL)
134 {
135 /* Create a new one. */
136 mh->wrapperdata = malloc(sizeof(struct wrap_data));
137 if(mh->wrapperdata == NULL)
138 {
140 return NULL;
141 }
142 /* When we have wrapper data present, the callback for its proper cleanup is needed. */
144
145 whd = mh->wrapperdata;
146 whd->indextable = NULL;
147 whd->iotype = 0;
148 whd->fd = -1;
149 whd->my_fd = -1;
150 whd->r_read = NULL;
151 whd->r_lseek = NULL;
152 whd->handle = NULL;
153 whd->r_h_read = NULL;
154 whd->r_h_lseek = NULL;
155 whd->h_cleanup = NULL;
156 }
157 else whd = mh->wrapperdata;
158
159 return whd;
160}
#define malloc
Definition: debug_ros.c:4
@ MPG123_OUT_OF_MEM
Definition: mpg123.h:390
static void wrap_destroy(void *handle)
Definition: lfs_wrap.c:115
void * wrapperdata
Definition: frame.h:337
void(* wrapperclean)(void *)
Definition: frame.h:339
long(* r_h_lseek)(void *, long, int)
Definition: lfs_wrap.c:90
ssize_t(* r_h_read)(void *, void *, size_t)
Definition: lfs_wrap.c:89
ssize_t(* r_read)(int, void *, size_t)
Definition: lfs_wrap.c:85
int fd
Definition: lfs_wrap.c:82
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
void(* h_cleanup)(void *)
Definition: lfs_wrap.c:91
int iotype
Definition: lfs_wrap.c:80
int my_fd
Definition: lfs_wrap.c:83

Referenced by mpg123_index(), mpg123_replace_reader(), mpg123_replace_reader_handle(), and mpg123_set_index().

◆ wrap_io_cleanup()

static void wrap_io_cleanup ( void handle)
static

Definition at line 97 of file lfs_wrap.c.

98{
99 struct wrap_data *ioh = handle;
100 if(ioh->iotype == IO_HANDLE)
101 {
102 if(ioh->h_cleanup != NULL && ioh->handle != NULL)
103 ioh->h_cleanup(ioh->handle);
104
105 ioh->handle = NULL;
106 }
107 if(ioh->my_fd >= 0)
108 {
109 close(ioh->my_fd);
110 ioh->my_fd = -1;
111 }
112}
#define close
Definition: acwin.h:98
#define IO_HANDLE
Definition: lfs_wrap.c:73

Referenced by mpg123_open(), mpg123_open_fd(), mpg123_open_handle(), and wrap_destroy().

◆ wrap_lseek()

off_t wrap_lseek ( void handle,
off_t  offset,
int  whence 
)

Definition at line 544 of file lfs_wrap.c.

545{
546 struct wrap_data *ioh = handle;
547 long smalloff = offset;
548 if(smalloff == offset)
549 {
550 switch(ioh->iotype)
551 {
552 case IO_FD: return ioh->r_lseek(ioh->fd, smalloff, whence);
553 case IO_HANDLE: return ioh->r_h_lseek(ioh->handle, smalloff, whence);
554 }
555 return -1;
556 }
557 else
558 {
560 return -1;
561 }
562}
#define IO_FD
Definition: lfs_wrap.c:72

Referenced by mpg123_open(), mpg123_open_fd(), and mpg123_open_handle().

◆ wrap_read()

ssize_t wrap_read ( void handle,
void buf,
size_t  count 
)

Definition at line 531 of file lfs_wrap.c.

532{
533 struct wrap_data *ioh = handle;
534 switch(ioh->iotype)
535 {
536 case IO_FD: return ioh->r_read(ioh->fd, buf, count);
537 case IO_HANDLE: return ioh->r_h_read(ioh->handle, buf, count);
538 }
539 error("Serious breakage - bad IO type in LFS wrapper!");
540 return -1;
541}
#define error(str)
Definition: mkdosfs.c:1605

Referenced by mpg123_open(), mpg123_open_fd(), and mpg123_open_handle().