ReactOS  0.4.13-dev-544-gede3fdd
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_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  {
595  errno = EOVERFLOW;
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
static int fd
Definition: io.c:51
_Check_return_opt_ _CRTIMP long __cdecl lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin)
int errno

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 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLuint GLsizei count
Definition: gl.h:1545
static int fd
Definition: io.c:51
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

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 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
static void wrap_io_cleanup(void *handle)
Definition: lfs_wrap.c:97
long * indextable
Definition: lfs_wrap.c:78

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  {
139  mh->err = MPG123_OUT_OF_MEM;
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 }
long(* r_h_lseek)(void *, long, int)
Definition: lfs_wrap.c:90
static void wrap_destroy(void *handle)
Definition: lfs_wrap.c:115
void * wrapperdata
Definition: frame.h:333
ssize_t(* r_h_read)(void *, void *, size_t)
Definition: lfs_wrap.c:89
void(* wrapperclean)(void *)
Definition: frame.h:335
smooth NULL
Definition: ftsmooth.c:416
ssize_t(* r_read)(int, void *, size_t)
Definition: lfs_wrap.c:85
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
void * handle
Definition: lfs_wrap.c:88
int fd
Definition: lfs_wrap.c:82
int iotype
Definition: lfs_wrap.c:80
#define malloc
Definition: debug_ros.c:4
void(* h_cleanup)(void *)
Definition: lfs_wrap.c:91
long * indextable
Definition: lfs_wrap.c:78
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 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define IO_HANDLE
Definition: lfs_wrap.c:73
smooth NULL
Definition: ftsmooth.c:416
void * handle
Definition: lfs_wrap.c:88
#define close
Definition: acwin.h:74
int iotype
Definition: lfs_wrap.c:80
void(* h_cleanup)(void *)
Definition: lfs_wrap.c:91
int my_fd
Definition: lfs_wrap.c:83

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  error("Serious breakage - bad IO type in LFS wrapper!");
556  return -1;
557  }
558  else
559  {
560  errno = EOVERFLOW;
561  return -1;
562  }
563 }
long(* r_h_lseek)(void *, long, int)
Definition: lfs_wrap.c:90
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define error(str)
Definition: mkdosfs.c:1605
#define EOVERFLOW
Definition: errno.h:82
#define IO_HANDLE
Definition: lfs_wrap.c:73
GLintptr offset
Definition: glext.h:5920
int errno
long(* r_lseek)(int, long, int)
Definition: lfs_wrap.c:86
void * handle
Definition: lfs_wrap.c:88
int fd
Definition: lfs_wrap.c:82
int iotype
Definition: lfs_wrap.c:80
#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 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define error(str)
Definition: mkdosfs.c:1605
#define IO_HANDLE
Definition: lfs_wrap.c:73
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
void * handle
Definition: lfs_wrap.c:88
int fd
Definition: lfs_wrap.c:82
int iotype
Definition: lfs_wrap.c:80
#define IO_FD
Definition: lfs_wrap.c:72

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