source: roaraudio/libroaross/libroaross.c @ 3952:5d9df496e1a3

Last change on this file since 3952:5d9df496e1a3 was 3952:5d9df496e1a3, checked in by phi, 14 years ago

added libroaross_open_vio()

File size: 51.7 KB
Line 
1//libroaross.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "roaraudio.h"
37#include "libroarlight/libroarlight.h"
38
39#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
40#if defined(__OpenBSD__) || defined(__NetBSD__)
41#include <soundcard.h>
42#else
43#include <sys/soundcard.h>
44#endif
45#include <sys/ioctl.h>
46
47#ifdef ROAR_HAVE_H_SYS_TYPES
48#include <sys/types.h>
49#endif
50
51#ifdef ROAR_HAVE_H_FCNTL
52#include <fcntl.h>
53#endif
54
55#ifdef ROAR_HAVE_H_UNISTD
56#include <unistd.h>
57#endif
58
59#include <sys/stat.h>
60#include <dlfcn.h>
61#include <stdarg.h>
62
63#if defined(RTLD_NEXT)
64#define REAL_LIBC RTLD_NEXT
65#else
66#define REAL_LIBC ((void *) -1L)
67#endif
68
69#ifndef ENOTSUP
70#define ENOTSUP ENOSYS
71#endif
72
73#ifndef O_DIRECTORY
74#define O_DIRECTORY 0
75#endif
76
77#ifndef O_DIRECT
78#define O_DIRECT 0
79#endif
80
81#ifndef O_LARGEFILE
82#define O_LARGEFILE 0
83#endif
84
85#ifndef O_NOATIME
86#define O_NOATIME 0
87#endif
88
89#define _O_PARA_DIR (O_RDONLY|O_WRONLY|O_RDWR)
90#define _O_PARA_IGN (O_DIRECT|O_APPEND|O_LARGEFILE|O_NOATIME|O_NOCTTY|O_TRUNC)
91
92#if defined(ROAR_OS_NETBSD) && defined(ioctl)
93#define IOCTL_IS_ALIAS
94#endif
95
96#ifdef ROAR_OS_FREEBSD
97#define _VA_ARGS_MODE_T int
98#else
99#define _VA_ARGS_MODE_T mode_t
100#endif
101
102#ifdef ROAR_OS_FREEBSD
103#define _CREAT_ARG_PATHNAME path
104#else
105#define _CREAT_ARG_PATHNAME pathname
106#endif
107
108#ifdef ROAR_OS_NETBSD
109#define IOCTL() int _oss_ioctl __P((int fd, unsigned long com, void *argp))
110#define map_args int __fd = fd; unsigned long int __request = com
111#elif defined(ROAR_TARGET_CYGWIN)
112#define IOCTL() int ioctl (int __fd, int __cmd, ...)
113#define map_args unsigned long int __request = __cmd; void * argp
114#define va_argp
115#define ioctl_lastarg __cmd
116#else
117#define IOCTL() int ioctl (int __fd, unsigned long int __request, ...)
118#define map_args void * argp
119#define va_argp
120#define ioctl_lastarg __request
121#endif
122
123#define OSS_VOLUME_SCALE 100
124
125#define _MAX_POINTER  8
126
127// handle type:
128#define HT_NONE       0 /* Unused object */
129#define HT_STREAM     1 /* Stream with no specal handling needed */
130#define HT_MIXER      2 /* Mixer device */
131#define HT_WAVEFORM   3 /* Waveform device */
132#define HT_MIDI       4 /* MIDI device */
133#define HT_DMX        5 /* DMX512/DMX4Linux device */
134#define HT_VIO        6 /* General VIO object */
135#define HT_STATIC     7 /* Static file */
136
137struct session {
138 int refc;
139 struct roar_connection con;
140};
141
142static struct session _session = {.refc = 0};
143
144struct handle {
145 int refc; // refrence counter
146 struct session * session;
147 int type;
148 int sysio_flags;
149 struct roar_stream    stream;
150 struct roar_vio_calls stream_vio;
151 int                   stream_dir;
152 int                   stream_opened;
153 size_t                stream_buffersize;
154 size_t                readc, writec;
155 size_t                pos;
156 union {
157  struct {
158   char * data;
159   size_t len;
160  } sf;
161 } userdata;
162};
163
164static struct {
165 int     (*open)(const char *pathname, int flags, mode_t mode);
166 int     (*close)(int fd);
167 ssize_t (*write)(int fd, const void *buf, size_t count);
168 ssize_t (*read)(int fd, void *buf, size_t count);
169#ifndef IOCTL_IS_ALIAS
170 int     (*ioctl)(int d, int request, ...);
171#endif
172 off_t   (*lseek)(int fildes, off_t offset, int whence);
173 FILE   *(*fopen)(const char *path, const char *mode);
174 int     (*dup)(int oldfd);
175 int     (*dup2)(int oldfd, int newfd);
176 int     (*select)(int nfds, fd_set *readfds, fd_set *writefds,
177                   fd_set *exceptfds, struct timeval *timeout);
178 int     (*fcntl)(int fd, int cmd, ...);
179 int     (*access)(const char *pathname, int mode);
180 int     (*open64)(const char *__file, int __oflag, ...);
181 int     (*creat)(const char *_CREAT_ARG_PATHNAME, mode_t mode);
182 int     (*stat)(const char *path, struct stat *buf);
183 int     (*fstat)(int filedes, struct stat *buf);
184 int     (*lstat)(const char *path, struct stat *buf);
185} _os;
186
187static struct {
188 struct {
189  int volume;
190  int pcm;
191  int line;
192  int line1;
193  int line2;
194  int line3;
195  int digital1;
196  int digital2;
197  int digital3;
198 } sid;
199} _mix_settings = {
200                   .sid = {
201                           .volume   = -1,
202                           .pcm      = -1,
203                           .line     =  0,
204                           .line1    =  1,
205                           .line2    =  2,
206                           .line3    =  3,
207                           .digital1 =  1,
208                           .digital2 =  2,
209                           .digital3 =  3
210                          }
211                  };
212
213static struct pointer {
214 int fh;
215 struct handle * handle;
216} _ptr[_MAX_POINTER];
217
218
219static char _sf__dev_sndstat[] =
220 "Sound Driver:RoarAudio\n"
221 "Config options: 0\n"
222 "\n"
223 "Installed drivers:\n"
224 "Type 10: RoarAudio emulation\n"
225 "\n"
226 "Card config:\n"
227 "\n"
228 "Audio devices:\n"
229 "0: RoarAudio OSS emulation (DUPLEX)\n"
230 "\n"
231 "Midi devices:\n"
232 "0: RoarAudio OSS emulation MIDI\n"
233 "\n"
234 "Timers:\n"
235 "\n"
236 "Mixers:\n"
237 "0: RoarAudio OSS emulation Mixer\n"
238;
239
240static struct devices {
241  char * prefix;
242  int type;
243  size_t len;
244  void * userdata;
245  struct handle * (*open)(const char * file, int flags, mode_t mode, struct devices * ptr);
246} _device_list[] = {
247 {"/dev/dsp*",          HT_WAVEFORM,  0, NULL, NULL},
248 {"/dev/audio*",        HT_WAVEFORM,  0, NULL, NULL},
249 {"/dev/sound/dsp*",    HT_WAVEFORM,  0, NULL, NULL},
250 {"/dev/sound/audio*",  HT_WAVEFORM,  0, NULL, NULL},
251 {"/dev/mixer*",        HT_MIXER,     0, NULL, NULL},
252 {"/dev/sound/mixer*",  HT_MIXER,     0, NULL, NULL},
253 {"/dev/midi*",         HT_MIDI,      0, NULL, NULL},
254 {"/dev/rmidi*",        HT_MIDI,      0, NULL, NULL},
255 {"/dev/sound/midi*",   HT_MIDI,      0, NULL, NULL},
256 {"/dev/sound/rmidi*",  HT_MIDI,      0, NULL, NULL},
257 {"/dev/dmx*",          HT_DMX,       0, NULL, NULL},
258 {"/dev/misc/dmx*",     HT_DMX,       0, NULL, NULL},
259 {"/dev/dmxin*",        HT_DMX,       0, NULL, NULL},
260 {"/dev/misc/dmxin*",   HT_DMX,       0, NULL, NULL},
261 {"/dev/sndstat",       HT_STATIC,    sizeof(_sf__dev_sndstat)-1, _sf__dev_sndstat, NULL},
262#ifdef ROAR_DEFAULT_OSS_DEV
263 {ROAR_DEFAULT_OSS_DEV, HT_WAVEFORM,  0, NULL, NULL},
264#endif
265 {NULL, HT_NONE, 0, NULL, NULL},
266};
267
268
269static int _update_nonblock (struct handle * handle);
270
271static void _init_os (void) {
272 memset(&_os, 0, sizeof(_os));
273
274 // if call roar_dl_getsym() here all applications will segfaul.
275 // why?
276
277 _os.open   = dlsym(REAL_LIBC, "open");
278 _os.close  = dlsym(REAL_LIBC, "close");
279 _os.write  = dlsym(REAL_LIBC, "write");
280 _os.read   = dlsym(REAL_LIBC, "read");
281#ifndef IOCTL_IS_ALIAS
282 _os.ioctl  = dlsym(REAL_LIBC, "ioctl");
283#endif
284 _os.lseek  = dlsym(REAL_LIBC, "lseek");
285 _os.fopen  = dlsym(REAL_LIBC, "fopen");
286 _os.dup    = dlsym(REAL_LIBC, "dup");
287 _os.dup2   = dlsym(REAL_LIBC, "dup2");
288 _os.select = dlsym(REAL_LIBC, "select");
289 _os.fcntl  = dlsym(REAL_LIBC, "fcntl");
290 _os.access = dlsym(REAL_LIBC, "access");
291 _os.open64 = dlsym(REAL_LIBC, "open64");
292 _os.creat  = dlsym(REAL_LIBC, "creat");
293 _os.stat   = dlsym(REAL_LIBC, "stat");
294 _os.fstat  = dlsym(REAL_LIBC, "fstat");
295 _os.lstat  = dlsym(REAL_LIBC, "lstat");
296}
297
298static void _init_ptr (void) {
299 int i;
300
301 for (i = 0; i < _MAX_POINTER; i++) {
302  _ptr[i].fh = -1;
303 }
304}
305
306static void _init (void) {
307 static int inited = 0;
308
309 if ( !inited ) {
310  _init_os();
311  _init_ptr();
312  roar_vio_select(NULL, 0, NULL, NULL);
313  inited++;
314 }
315}
316
317static void _find_volume_sid (struct session * session) {
318 int i;
319 int num;
320 int id[ROAR_STREAMS_MAX];
321 struct roar_stream s;
322 char name[1024];
323
324 ROAR_DBG("_find_volume_sid(session=%p) = ?", session);
325
326 if ( (num = roar_list_streams(&(session->con), id, ROAR_STREAMS_MAX)) == -1 ) {
327  return;
328 }
329
330 for (i = 0; i < num; i++) {
331  if ( roar_get_stream(&(session->con), &s, id[i]) == -1 )
332   continue;
333
334  if ( s.dir != ROAR_DIR_MIXING )
335   continue;
336
337  if ( roar_stream_get_name(&(session->con), &s, name, 1024) == -1 )
338   continue;
339
340  if ( !strcasecmp(name, "Waveform Mixer") ) {
341   _mix_settings.sid.volume = id[i];
342   ROAR_DBG("_find_volume_sid(session=%p): found waveform mixer at sid %i", session, id[i]);
343   ROAR_DBG("_find_volume_sid(session=%p) = (void)", session);
344   return;
345  }
346 }
347}
348
349static int _open_dummy (void) {
350 int p[2];
351
352 if ( pipe(p) == -1 )
353  return -1;
354
355 close(p[1]);
356
357 return p[0];
358}
359
360static struct session * _open_session (char * server, char * name) {
361 struct session * ses = &_session;
362 int new_session = getenv("ROAR_OSS_NEW_SESSION") == NULL ? 0 : 1;
363
364 ROAR_DBG("_open_session(server='%s', name='%s') = ?", server, name);
365 ROAR_DBG("_open_session(server='%s', name='%s'): _session.refc=%i", server, name, _session.refc);
366
367 if ( new_session ) {
368  ses = roar_mm_malloc(sizeof(struct session));
369  if ( ses == NULL )
370   return NULL;
371
372  memset(ses, 0, sizeof(struct session));
373 }
374
375 if ( ses->refc == 0 ) {
376
377  if ( name == NULL )
378   name = getenv("ROAR_OSS_CLIENT_NAME");
379
380  if ( name == NULL )
381   name = "libroaross client";
382
383  if ( roar_simple_connect(&(ses->con), server, name) == -1 ) {
384   if ( new_session )
385    roar_mm_free(ses);
386
387   return NULL;
388  }
389
390  _find_volume_sid(ses);
391
392  if ( !new_session ) {
393   if ( getenv("ROAR_OSS_KEEP_SESSION") != NULL )
394    ses->refc++;
395  }
396 }
397
398 ses->refc++;
399
400 ROAR_DBG("_open_session(server='%s', name='%s') = %p", server, name, ses);
401 return ses;
402}
403
404static void _close_session(struct session * session) {
405 if ( session == NULL )
406  return;
407
408 session->refc--;
409
410 ROAR_DBG("_close_session(session=%p): session->refc=%i", session, session->refc);
411
412 if ( session->refc == 0 ) {
413  roar_disconnect(&(session->con));
414 }
415
416 if ( session != &_session )
417  roar_mm_free(session);
418}
419
420static struct handle * _open_handle(struct session * session) {
421 struct handle * handle;
422
423 ROAR_DBG("_open_handle(session=%p) = ?", session);
424
425 if ( (handle = roar_mm_malloc(sizeof(struct handle))) == NULL )
426  return NULL;
427
428 memset(handle, 0, sizeof(struct handle));
429
430 handle->refc = 1;
431 handle->session = session;
432
433 if ( session != NULL )
434  session->refc++; // TODO: better warp this
435
436 handle->type = HT_NONE;
437 handle->stream_dir = ROAR_DIR_PLAY;
438 roar_stream_new(&(handle->stream), ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT, ROAR_CODEC_DEFAULT);
439
440 ROAR_DBG("_open_handle(session=%p) = %p", session, handle);
441 return handle;
442}
443
444static void _close_handle(struct handle * handle) {
445 int need_close = 0;
446
447 if (handle == NULL)
448  return;
449
450 handle->refc--;
451
452 ROAR_DBG("_close_handle(handle=%p): handle->refc=%i", handle, handle->refc);
453
454 if ( handle->refc == 0 ) {
455  switch (handle->type) {
456   case HT_VIO:
457     need_close = 1;
458    break;
459   case HT_STREAM:
460     if ( handle->stream_opened )
461      need_close = 1;
462    break;
463  }
464
465  if ( need_close )
466   roar_vio_close(&(handle->stream_vio));
467
468  if ( handle->session != NULL ) {
469   handle->session->refc--;
470
471   _close_session(handle->session);
472  }
473
474  roar_mm_free(handle);
475 }
476}
477
478static struct pointer * _get_pointer_by_fh (int fh) {
479 int i;
480
481 for (i = 0; i < _MAX_POINTER; i++) {
482  if ( _ptr[i].fh == fh )
483   return &(_ptr[i]);
484 }
485
486 return NULL;
487}
488
489static struct pointer * _open_pointer(struct handle * handle) {
490 struct pointer * ret = _get_pointer_by_fh(-1);
491
492 if ( ret == NULL )
493  return NULL;
494
495 if ( (ret->fh = _open_dummy()) == -1 )
496  return NULL;
497
498 ret->handle = handle;
499
500 return ret;
501}
502
503static struct pointer * _attach_pointer(struct handle * handle, int fh) {
504 struct pointer * ret = _get_pointer_by_fh(-1);
505
506 if ( ret == NULL )
507  return NULL;
508
509 if ( (ret->fh = fh) == -1 )
510  return NULL;
511
512 ret->handle = handle;
513
514 handle->refc++;
515
516 return ret;
517}
518
519static void _close_pointer(struct pointer * pointer) {
520 if ( pointer == NULL )
521  return;
522
523 _os.close(pointer->fh);
524
525 pointer->fh = -1;
526
527 _close_handle(pointer->handle);
528}
529
530// -------------------------------------
531// central function to find device:
532// -------------------------------------
533
534static struct devices * _get_device (const char * pathname) {
535 struct devices * ptr;
536 size_t len;
537 int i;
538
539 for (i = 0; _device_list[i].prefix != NULL; i++) {
540  len = strlen(_device_list[i].prefix);
541
542  if ( _device_list[i].prefix[len-1] == '*' ) {
543   len--;
544  } else {
545   len++;
546  }
547  if ( !strncmp(pathname, _device_list[i].prefix, len) ) {
548   ptr = &(_device_list[i]);
549  }
550 }
551
552 return NULL;
553}
554
555// -------------------------------------
556// central open function:
557// -------------------------------------
558
559static int _open_file (const char *pathname, int flags) {
560 struct session * session;
561 struct handle  * handle;
562 struct pointer * pointer;
563 struct devices * ptr = NULL;
564
565 ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = ?", pathname, flags);
566
567/*
568 * Flags we ignore:
569 * O_DIRECT, O_APPEND, O_LARGEFILE, O_NOATIME, O_NOCTTY, O_TRUNC
570 */
571
572#ifdef O_ASYNC
573 if ( flags & O_ASYNC ) {
574  ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1 // not supported O_ASYNC", pathname, flags);
575  errno = ENOSYS;
576  return -1;
577 }
578#endif
579
580 if ( (flags & O_DIRECTORY) || (flags & O_EXCL) ) {
581  ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1 // invalid flags (O_DIRECTORY or O_EXCL)", pathname, flags);
582  errno = EINVAL;
583  return -1;
584 }
585
586 if ( (ptr = _get_device(pathname)) == NULL )
587  return -2;
588
589 if ( ptr->type == HT_STATIC || ptr->type == HT_VIO ) { // non-session handles
590  session = NULL;
591 } else {
592  if ( (session = _open_session(NULL, NULL)) == NULL ) {
593   ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
594   return -1;
595  }
596 }
597
598 if ( ptr->open != NULL ) {
599  // TODO: Add support to pass mode (perms) to open.
600  if ( (handle = ptr->open(pathname, flags, 0000, ptr)) == NULL ) {
601   _close_session(session);
602   ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
603   return -1;
604  }
605 } else {
606  if ( (handle = _open_handle(session)) == NULL ) {
607   _close_session(session);
608   ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
609   return -1;
610  }
611
612  handle->type        = ptr->type;
613  handle->sysio_flags = flags;
614  handle->stream_dir  = -1;
615 }
616
617 switch (flags & _O_PARA_DIR) {
618  case O_RDONLY:
619    switch (ptr->type) {
620     case HT_WAVEFORM:
621       handle->stream_dir = ROAR_DIR_MONITOR;
622      break;
623     case HT_MIDI:
624       handle->stream_dir = ROAR_DIR_MIDI_OUT;
625      break;
626     case HT_DMX:
627       handle->stream_dir = ROAR_DIR_LIGHT_OUT;
628      break;
629     case HT_MIXER:
630     case HT_STATIC:
631      break;
632     default:
633       ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
634       return -1;
635    }
636   break;
637  case O_WRONLY:
638    switch (ptr->type) {
639     case HT_WAVEFORM:
640       handle->stream_dir = ROAR_DIR_PLAY;
641      break;
642     case HT_MIDI:
643       handle->stream_dir = ROAR_DIR_MIDI_IN;
644      break;
645     case HT_DMX:
646       handle->stream_dir = ROAR_DIR_LIGHT_IN;
647      break;
648     case HT_MIXER:
649     case HT_STATIC:
650      break;
651     default:
652       ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
653       return -1;
654    }
655   break;
656  case O_RDWR:
657    switch (ptr->type) {
658     case HT_WAVEFORM:
659       handle->stream_dir = ROAR_DIR_BIDIR;
660      break;
661     case HT_MIXER:
662     case HT_STATIC:
663      break;
664     default:
665       ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
666       return -1;
667    }
668   break;
669 }
670
671 switch (handle->type) {
672  case HT_WAVEFORM:
673    handle->type = HT_STREAM;
674   break;
675  case HT_MIDI:
676    handle->type = HT_STREAM;
677    handle->stream.info.rate     = 0;
678    handle->stream.info.bits     = ROAR_MIDI_BITS;
679    handle->stream.info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
680    handle->stream.info.codec    = ROAR_CODEC_MIDI;
681   break;
682  case HT_DMX:
683    handle->stream.info.rate     = 0;
684    handle->stream.info.bits     = ROAR_LIGHT_BITS;
685    handle->stream.info.channels = 512;
686    handle->stream.info.codec    = ROAR_CODEC_ROARDMX;
687   break;
688  case HT_STATIC:
689    handle->userdata.sf.len      = ptr->len;
690    handle->userdata.sf.data     = ptr->userdata;
691   break;
692 }
693
694 if ( (pointer = _open_pointer(handle)) == NULL ) {
695  _close_handle(handle);
696  ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = -1", pathname, flags);
697  return -1;
698 }
699
700 ROAR_DBG("_open_file(pathname='%s', flags=0x%x) = %i", pathname, flags, pointer->fh);
701
702 return pointer->fh;
703}
704
705// -------------------------------------
706// VIO open function:
707// -------------------------------------
708
709int libroaross_open_vio(struct handle ** handleret, struct roar_vio_calls ** vio, int flags) {
710 struct handle  * handle;
711 struct pointer * pointer;
712
713 _init();
714
715 if ( vio == NULL )
716  return -1;
717
718 if ( (handle = _open_handle(NULL)) == NULL ) {
719  return -1;
720 }
721
722 handle->type        = HT_VIO;
723 handle->sysio_flags = flags;
724
725 *vio = &(handle->stream_vio);
726
727 if ( handleret != NULL )
728  *handleret = handle;
729
730 if ( (pointer = _open_pointer(handle)) == NULL ) {
731  _close_handle(handle);
732  return -1;
733 }
734
735 return pointer->fh;
736}
737
738// -------------------------------------
739// open function for streams:
740// -------------------------------------
741
742static int _open_stream (struct handle * handle) {
743  // FIXME: this should be re-written much more cleanly:
744
745 if ( handle == NULL )
746  return -1;
747
748 if ( roar_vio_simple_new_stream_obj(&(handle->stream_vio),
749                                     &(handle->session->con), &(handle->stream),
750                                     handle->stream.info.rate,
751                                     handle->stream.info.channels,
752                                     handle->stream.info.bits,
753                                     handle->stream.info.codec,
754                                     handle->stream_dir
755                                    ) == -1 )
756  return -1;
757
758 handle->stream_opened++;
759
760 _mix_settings.sid.pcm = roar_stream_get_id(&(handle->stream));
761
762 _update_nonblock(handle);
763
764 return 0;
765}
766
767// -------------------------------------
768// function to update O_NONBLOCK:
769// -------------------------------------
770
771static int _update_nonblock (struct handle * handle) {
772 int opened = 0;
773 int state  = handle->sysio_flags & O_NONBLOCK ? ROAR_SOCKET_NONBLOCK : ROAR_SOCKET_BLOCK;
774
775 switch (handle->type) {
776  case HT_NONE:
777  case HT_STATIC:
778  case HT_MIXER:
779    // we can ignore setting of nonblock flag here.
780    return 0;
781   break;
782  case HT_VIO:
783    opened = 1;
784   break;
785  case HT_STREAM:
786  case HT_WAVEFORM:
787  case HT_MIDI:
788  case HT_DMX:
789    opened = handle->stream_opened;
790   break;
791 }
792
793 if ( opened ) {
794  return roar_vio_nonblock(&(handle->stream_vio), state);
795 }
796
797 return 0;
798}
799
800// -------------------------------------
801// function to parse format:
802// -------------------------------------
803
804static int _ioctl_stream_format (struct handle * handle, int format) {
805 struct roar_audio_info * info = &(handle->stream.info);
806
807 switch (format) {
808  case AFMT_S8:
809    info->bits  = 8;
810    info->codec = ROAR_CODEC_PCM_S_LE;
811   break;
812  case AFMT_U8:
813    info->bits  = 8;
814    info->codec = ROAR_CODEC_PCM_U_LE;
815   break;
816  case AFMT_S16_BE:
817    info->bits  = 16;
818    info->codec = ROAR_CODEC_PCM_S_BE;
819   break;
820  case AFMT_S16_LE:
821    info->bits  = 16;
822    info->codec = ROAR_CODEC_PCM_S_LE;
823   break;
824  case AFMT_U16_BE:
825    info->bits  = 16;
826    info->codec = ROAR_CODEC_PCM_U_BE;
827   break;
828  case AFMT_U16_LE:
829    info->bits  = 16;
830    info->codec = ROAR_CODEC_PCM_U_LE;
831   break;
832#ifdef AFMT_S32_BE
833  case AFMT_S32_BE:
834    info->bits  = 32;
835    info->codec = ROAR_CODEC_PCM_S_BE;
836   break;
837#endif
838#ifdef AFMT_S32_LE
839  case AFMT_S32_LE:
840    info->bits  = 32;
841    info->codec = ROAR_CODEC_PCM_S_LE;
842   break;
843#endif
844  case AFMT_A_LAW:
845    info->bits  = 8;
846    info->codec = ROAR_CODEC_ALAW;
847   break;
848  case AFMT_MU_LAW:
849    info->bits  = 8;
850    info->codec = ROAR_CODEC_MULAW;
851   break;
852#ifdef AFMT_VORBIS
853  case AFMT_VORBIS:
854    info->codec = ROAR_CODEC_OGG_VORBIS;
855   break;
856#endif
857  default:
858    ROAR_DBG("_ioctl_stream_format(*): unsupported format");
859    errno = ENOSYS;
860    return -1;
861   break;
862 }
863
864 return 0;
865}
866
867static inline int _ioctl_stream_format_list (void) {
868 int format = 0;
869
870 format |= AFMT_S8;
871 format |= AFMT_U8;
872
873 format |= AFMT_S16_BE;
874 format |= AFMT_S16_LE;
875
876 format |= AFMT_U16_BE;
877 format |= AFMT_U16_LE;
878
879#ifdef AFMT_S32_BE
880 format |= AFMT_S32_BE;
881#endif
882#ifdef AFMT_S32_LE
883 format |= AFMT_S32_LE;
884#endif
885
886 format |= AFMT_A_LAW;
887 format |= AFMT_MU_LAW;
888
889#ifdef AFMT_VORBIS
890 format |= AFMT_VORBIS;
891#endif
892
893 return format;
894}
895
896// -------------------------------------
897// mixer ioctls:
898// -------------------------------------
899
900static int _ioctl_mixer (struct handle * handle, long unsigned int req, void * vp) {
901 mixer_info * info;
902 int channels;
903 struct roar_mixer_settings mixer;
904 int o_w    =  0;
905 int o_sid  = -1;
906 int * ip   = vp;
907#if defined(DEBUG) && defined(DEBUG_IOCTL_NAMES)
908 char * name = NULL;
909#endif
910
911#if defined(DEBUG) && defined(DEBUG_IOCTL_NAMES)
912 switch (req) {
913#if 0
914  case SNDCTL_MIX_DESCRIPTION: name = "SNDCTL_MIX_DESCRIPTION"; break;
915  case SNDCTL_MIX_ENUMINFO:    name = "SNDCTL_MIX_ENUMINFO";    break;
916  case SNDCTL_MIX_EXTINFO:     name = "SNDCTL_MIX_EXTINFO";     break;
917  case SNDCTL_MIX_NREXT:       name = "SNDCTL_MIX_NREXT";       break;
918  case SNDCTL_MIX_NRMIX:       name = "SNDCTL_MIX_NRMIX";       break;
919  case SNDCTL_MIX_READ:        name = "SNDCTL_MIX_READ";        break;
920  case SNDCTL_MIX_WRITE:       name = "SNDCTL_MIX_WRITE";       break;
921#endif
922//  case SOUND_MIXER_INFO:             name = "SOUND_MIXER_INFO";             break;
923  case SOUND_OLD_MIXER_INFO:         name = "SOUND_OLD_MIXER_INFO";         break;
924  case SOUND_MIXER_ACCESS:           name = "SOUND_MIXER_ACCESS";           break;
925  case SOUND_MIXER_AGC:              name = "SOUND_MIXER_AGC";              break;
926  case SOUND_MIXER_3DSE:             name = "SOUND_MIXER_3DSE";             break;
927  case SOUND_MIXER_GETLEVELS:        name = "SOUND_MIXER_GETLEVELS";        break;
928  case SOUND_MIXER_SETLEVELS:        name = "SOUND_MIXER_SETLEVELS";        break;
929  case SOUND_MIXER_PRIVATE1:         name = "SOUND_MIXER_PRIVATE1";         break;
930  case SOUND_MIXER_PRIVATE2:         name = "SOUND_MIXER_PRIVATE2";         break;
931  case SOUND_MIXER_PRIVATE3:         name = "SOUND_MIXER_PRIVATE3";         break;
932  case SOUND_MIXER_PRIVATE4:         name = "SOUND_MIXER_PRIVATE4";         break;
933  case SOUND_MIXER_PRIVATE5:         name = "SOUND_MIXER_PRIVATE5";         break;
934  case OSS_GETVERSION:               name = "OSS_GETVERSION";               break;
935//  case SOUND_MIXER_READ_CAPS:        name = "SOUND_MIXER_READ_CAPS";        break;
936  case SOUND_MIXER_READ_MUTE:        name = "SOUND_MIXER_READ_MUTE";        break;
937/*
938  case :     name = "";     break;
939  case :     name = "";     break;
940*/
941 }
942 if ( name != NULL ) {
943  ROAR_DBG("_ioctl_mixer(handle=%p, req=0x%lX, ip=%p): unspported mixer command %s", handle, req, ip, name);
944  ROAR_DBG("_ioctl_mixer(handle=%p, req=0x%lX, ip=%p) = -1 // errno = ENOSYS", handle, req, ip);
945  errno = ENOSYS;
946  return -1;
947 }
948#endif
949
950 switch (req) {
951  case SOUND_MIXER_READ_VOLUME:    o_w = 0; o_sid = _mix_settings.sid.volume;   break;
952  case SOUND_MIXER_READ_LINE:      o_w = 0; o_sid = _mix_settings.sid.line;     break;
953  case SOUND_MIXER_READ_LINE1:     o_w = 0; o_sid = _mix_settings.sid.line1;    break;
954  case SOUND_MIXER_READ_LINE2:     o_w = 0; o_sid = _mix_settings.sid.line2;    break;
955  case SOUND_MIXER_READ_LINE3:     o_w = 0; o_sid = _mix_settings.sid.line3;    break;
956#if 0
957  case SOUND_MIXER_READ_DIGITAL1:  o_w = 0; o_sid = _mix_settings.sid.digital1; break;
958  case SOUND_MIXER_READ_DIGITAL2:  o_w = 0; o_sid = _mix_settings.sid.digital2; break;
959  case SOUND_MIXER_READ_DIGITAL3:  o_w = 0; o_sid = _mix_settings.sid.digital3; break;
960#endif
961  case SOUND_MIXER_WRITE_VOLUME:   o_w = 1; o_sid = _mix_settings.sid.volume;   break;
962  case SOUND_MIXER_WRITE_LINE:     o_w = 1; o_sid = _mix_settings.sid.line;     break;
963  case SOUND_MIXER_WRITE_LINE1:    o_w = 1; o_sid = _mix_settings.sid.line1;    break;
964  case SOUND_MIXER_WRITE_LINE2:    o_w = 1; o_sid = _mix_settings.sid.line2;    break;
965  case SOUND_MIXER_WRITE_LINE3:    o_w = 1; o_sid = _mix_settings.sid.line3;    break;
966#if 0
967  case SOUND_MIXER_WRITE_DIGITAL1: o_w = 1; o_sid = _mix_settings.sid.digital1; break;
968  case SOUND_MIXER_WRITE_DIGITAL2: o_w = 1; o_sid = _mix_settings.sid.digital2; break;
969  case SOUND_MIXER_WRITE_DIGITAL3: o_w = 1; o_sid = _mix_settings.sid.digital3; break;
970#endif
971  // we handle PCM seperatly as we want to be abled to abled to handle it on a stream (not mixer), too:
972  case SOUND_MIXER_READ_PCM:
973    o_w = 0;
974    if ( handle->type == HT_STREAM ) {
975     o_sid = roar_stream_get_id(&(handle->stream));
976    } else {
977     o_sid = _mix_settings.sid.pcm;
978    }
979   break;
980  case SOUND_MIXER_WRITE_PCM:
981    o_w = 1;
982    if ( handle->type == HT_STREAM ) {
983     o_sid = roar_stream_get_id(&(handle->stream));
984    } else {
985     o_sid = _mix_settings.sid.pcm;
986    }
987   break;
988 }
989 if ( o_sid != -1 ) {
990  // set/get volume
991  if ( o_w ) {
992   mixer.scale    = OSS_VOLUME_SCALE;
993   mixer.mixer[0] = ( *ip       & 0xFF);
994   mixer.mixer[1] = ((*ip >> 8) & 0xFF);
995   if ( roar_set_vol(&(handle->session->con), o_sid, &mixer, 2) == -1 ) {
996    errno = EIO;
997    return -1;
998   }
999   return 0;
1000  } else {
1001   if ( roar_get_vol(&(handle->session->con), o_sid, &mixer, &channels) == -1 ) {
1002    errno = EIO;
1003    return -1;
1004   }
1005   *ip = ((OSS_VOLUME_SCALE*mixer.mixer[0])/mixer.scale) | (((OSS_VOLUME_SCALE*mixer.mixer[0])/mixer.scale)<<8);
1006   return 0;
1007  }
1008 }
1009
1010 switch (req) {
1011  case SOUND_MIXER_READ_STEREODEVS: /* FIXME: check the streams for channel config */
1012  case SOUND_MIXER_READ_DEVMASK:
1013    *ip = 0;
1014
1015    if ( _mix_settings.sid.volume != -1 )
1016     *ip |= SOUND_MASK_VOLUME;
1017    if ( _mix_settings.sid.pcm != -1 )
1018     *ip |= SOUND_MASK_PCM;
1019    if ( _mix_settings.sid.line != -1 )
1020     *ip |= SOUND_MASK_LINE;
1021    if ( _mix_settings.sid.line1 != -1 )
1022     *ip |= SOUND_MASK_LINE1;
1023    if ( _mix_settings.sid.line2 != -1 )
1024     *ip |= SOUND_MASK_LINE2;
1025    if ( _mix_settings.sid.line3 != -1 )
1026     *ip |= SOUND_MASK_LINE3;
1027    if ( _mix_settings.sid.digital1 != -1 )
1028#if 0
1029     *ip |= SOUND_MASK_DIGITAL1;
1030    if ( _mix_settings.sid.digital2 != -1 )
1031     *ip |= SOUND_MASK_DIGITAL2;
1032    if ( _mix_settings.sid.digital3 != -1 )
1033     *ip |= SOUND_MASK_DIGITAL3;
1034#endif
1035
1036    return 0;
1037   break;
1038  case SOUND_MIXER_READ_RECMASK:
1039  case SOUND_MIXER_READ_RECSRC:
1040    *ip = SOUND_MASK_VOLUME; // we can currently only read from mixer
1041    return 0;
1042   break;
1043  case SOUND_MIXER_WRITE_RECSRC:
1044    if ( *ip == SOUND_MASK_VOLUME ) {
1045     return  0;
1046    } else {
1047     errno = ENOTSUP;
1048     return -1;
1049    }
1050   break;
1051  case SOUND_MIXER_READ_CAPS:
1052    *ip = 0;
1053    return 0;
1054   break;
1055  case SOUND_MIXER_INFO:
1056    info = vp;
1057    memset(info, 0, sizeof(*info));
1058    strcpy(info->id, "RoarAudio");
1059    strcpy(info->name, "RoarAudio");
1060    return 0;
1061   break;
1062 }
1063
1064 ROAR_DBG("_ioctl_mixer(handle=%p, req=0x%lX, ip=%p): unknown mixer CTL", handle, req, ip);
1065// _os.ioctl(-1, req, ip);
1066 ROAR_DBG("_ioctl_mixer(handle=%p, req=0x%lX, ip=%p) = -1 // errno = ENOSYS", handle, req, ip);
1067 errno = ENOSYS;
1068 return -1;
1069}
1070
1071// -------------------------------------
1072// buffer size calculation:
1073// -------------------------------------
1074
1075static size_t _get_stream_buffersize (struct handle * handle) {
1076 if ( handle->stream_buffersize )
1077  return handle->stream_buffersize;
1078
1079 return handle->stream_buffersize = handle->stream.info.rate     *
1080                                    handle->stream.info.channels *
1081                                    handle->stream.info.bits     / 800;
1082}
1083
1084// -------------------------------------
1085// emulated functions follow:
1086// -------------------------------------
1087
1088int     open(const char *pathname, int flags, ...) {
1089 int     ret;
1090 mode_t  mode = 0;
1091 va_list args;
1092
1093 _init();
1094
1095 if ( pathname == NULL ) {
1096  errno = EFAULT;
1097  return -1;
1098 }
1099
1100 ROAR_DBG("open(pathname='%s', flags=%x, ...) = ?\n", pathname, flags);
1101 ret = _open_file(pathname, flags);
1102
1103 switch (ret) {
1104  case -2:       // continue as normal, use _op.open()
1105   break;
1106  case -1:       // pass error to caller
1107    return -1;
1108   break;
1109  default:       // return successfully opened pointer to caller
1110    return ret;
1111   break;
1112 }
1113
1114 if (flags & O_CREAT) {
1115  va_start(args, flags);
1116  mode = va_arg(args, _VA_ARGS_MODE_T);
1117  va_end(args);
1118 }
1119
1120 return _os.open(pathname, flags, mode);
1121}
1122
1123int    open64(const char *__file, int __oflag, ...) {
1124 int     ret;
1125 mode_t  mode = 0;
1126 va_list args;
1127
1128 _init();
1129
1130 if ( __file == NULL ) {
1131  errno = EFAULT;
1132  return -1;
1133 }
1134
1135 ROAR_DBG("open64(__file='%s', __oflags=%x, ...) = ?\n", __file, __oflag);
1136 ret = _open_file(__file, __oflag);
1137
1138 switch (ret) {
1139  case -2:       // continue as normal, use _op.open()
1140   break;
1141  case -1:       // pass error to caller
1142    return -1;
1143   break;
1144  default:       // return successfully opened pointer to caller
1145    return ret;
1146   break;
1147 }
1148
1149 if (__oflag & O_CREAT) {
1150  va_start(args, __oflag);
1151  mode = va_arg(args, _VA_ARGS_MODE_T);
1152  va_end(args);
1153 }
1154
1155 if ( _os.open64 != NULL ) {
1156  return _os.open64(__file, __oflag, mode);
1157 } else {
1158#ifdef O_LARGEFILE
1159  return _os.open(__file, __oflag | O_LARGEFILE, mode);
1160#else
1161  return _os.open(__file, __oflag, mode);
1162#endif
1163 }
1164}
1165
1166int     close(int fd) {
1167 struct pointer * pointer;
1168 _init();
1169
1170 if ( (pointer = _get_pointer_by_fh(fd)) != NULL ) {
1171  _close_pointer(pointer);
1172  return 0;
1173 }
1174
1175 return _os.close(fd);
1176}
1177
1178ssize_t write(int fd, const void *buf, size_t count) {
1179 struct roar_roardmx_message roardmxmsg;
1180 struct pointer * pointer;
1181 ssize_t ret;
1182 size_t i;
1183
1184 _init();
1185
1186 if ( (pointer = _get_pointer_by_fh(fd)) != NULL ) {
1187  ROAR_DBG("write(fd=%i, buf=%p, count=%lu) = ? // pointer write", fd, buf, (long unsigned int) count);
1188  switch (pointer->handle->type) {
1189   case HT_STREAM: // handle stream specific stuff
1190     if ( pointer->handle->stream_opened == 0 ) {
1191      if ( _open_stream(pointer->handle) == -1 ) {
1192       errno = EIO;
1193       return -1;
1194      }
1195     }
1196   case HT_VIO: // from here we only look at the VIO object of streams, or handle simple VIOs
1197     ret = roar_vio_write(&(pointer->handle->stream_vio), (char*)buf, count);
1198     if ( ret > 0 )
1199      pointer->handle->writec += ret;
1200     return ret;
1201    break;
1202   case HT_DMX: // DMX need specal handling as we need to convert the protocol
1203     if ( pointer->handle->stream_opened == 0 ) {
1204      if ( _open_stream(pointer->handle) == -1 ) {
1205       errno = EIO;
1206       return -1;
1207      }
1208     }
1209     if ( count > 0 ) {
1210      if ( roar_roardmx_message_new_sset(&roardmxmsg) == -1 ) {
1211       errno = EIO;
1212       return -1;
1213      }
1214      for (i = 0; i < count; i++) {
1215       if ( roar_roardmx_message_add_chanval(&roardmxmsg, pointer->handle->pos + i, ((unsigned char*)buf)[i]) == -1 ) {
1216#ifdef EMSGSIZE
1217        errno = EMSGSIZE;
1218#else
1219        errno = EIO;
1220#endif
1221        return -1;
1222       }
1223      }
1224      if ( roar_roardmx_message_send(&roardmxmsg, &(pointer->handle->stream_vio)) == -1 ) {
1225       errno = EIO;
1226       return -1;
1227      }
1228     }
1229     pointer->handle->pos += count;
1230     return count;
1231    break;
1232   default: // we don't know what to do with other types
1233     errno = EINVAL;
1234     return -1;
1235    break;
1236  }
1237 }
1238
1239 return _os.write(fd, buf, count);
1240}
1241
1242ssize_t read(int fd, void *buf, size_t count) {
1243 struct pointer * pointer;
1244 ssize_t ret;
1245
1246 _init();
1247
1248 if ( (pointer = _get_pointer_by_fh(fd)) != NULL ) {
1249  ROAR_DBG("read(fd=%i, buf=%p, count=%lu) = ? // pointer read", fd, buf, (long unsigned int)count);
1250
1251  switch (pointer->handle->type) {
1252   case HT_STREAM:
1253     if ( pointer->handle->stream_opened == 0 ) {
1254      if ( _open_stream(pointer->handle) == -1 ) {
1255       errno = EIO;
1256       return -1;
1257      }
1258     }
1259   case HT_VIO:
1260     ret = roar_vio_read(&(pointer->handle->stream_vio), buf, count);
1261     if ( ret > 0 )
1262      pointer->handle->readc += ret;
1263     return ret;
1264    break;
1265   case HT_STATIC:
1266     ROAR_DBG("read(fd=%i, buf=%p, count=%lu) = ? // type=HT_STATIC", fd, buf, (long unsigned int)count);
1267     ret = pointer->handle->pos + count; // calc the end of the read
1268
1269     if ( ret > (ssize_t)pointer->handle->userdata.sf.len ) {
1270      count = pointer->handle->userdata.sf.len - pointer->handle->pos;
1271     }
1272
1273     memcpy(buf, pointer->handle->userdata.sf.data + pointer->handle->pos, count);
1274     pointer->handle->pos += count;
1275     return count;
1276    break;
1277   default:
1278     errno = EINVAL;
1279     return -1;
1280    break;
1281  }
1282 }
1283
1284 return _os.read(fd, buf, count);
1285}
1286
1287off_t lseek(int fildes, off_t offset, int whence) {
1288 struct pointer * pointer;
1289 ssize_t tmp;
1290
1291 _init();
1292
1293 if ( (pointer = _get_pointer_by_fh(fildes)) != NULL ) {
1294  switch (pointer->handle->type) {
1295   case HT_DMX:
1296     switch (whence) {
1297      case SEEK_SET:
1298        pointer->handle->pos  = offset;
1299       break;
1300      case SEEK_CUR:
1301        pointer->handle->pos += offset;
1302       break;
1303      case SEEK_END:
1304      default:
1305        errno = EINVAL;
1306        return -1;
1307       break;
1308     }
1309     return pointer->handle->pos;
1310    break;
1311   case HT_VIO:
1312     return roar_vio_lseek(&(pointer->handle->stream_vio), offset, whence);
1313    break;
1314   case HT_STATIC:
1315     switch (whence) {
1316      case SEEK_SET:
1317        if ( offset < 0 || offset > (ssize_t)pointer->handle->userdata.sf.len ) {
1318         errno = EINVAL;
1319         return -1;
1320        }
1321        pointer->handle->pos  = offset;
1322       break;
1323      case SEEK_CUR:
1324        tmp = pointer->handle->pos + offset;
1325        if ( tmp < 0 || tmp > (ssize_t)pointer->handle->userdata.sf.len ) {
1326         errno = EINVAL;
1327         return -1;
1328        }
1329        pointer->handle->pos = tmp;
1330       break;
1331      case SEEK_END:
1332        tmp = pointer->handle->userdata.sf.len + offset;
1333        if ( tmp < 0 || tmp > (ssize_t)pointer->handle->userdata.sf.len ) {
1334         errno = EINVAL;
1335         return -1;
1336        }
1337        pointer->handle->pos = tmp;
1338       break;
1339      default:
1340        errno = EINVAL;
1341        return -1;
1342       break;
1343     }
1344    break;
1345   default:
1346     errno = EINVAL;
1347     return -1;
1348    break;
1349  }
1350 }
1351
1352 return _os.lseek(fildes, offset, whence);
1353}
1354
1355IOCTL() {
1356 map_args;
1357 struct pointer * pointer;
1358 struct handle  * handle;
1359 int * ip = NULL;
1360 size_t tmp;
1361 audio_buf_info * bi;
1362 count_info     * ci;
1363#ifdef __FIXME__
1364 char * nosys_reqname = NULL;
1365#endif
1366#ifdef va_argp
1367 va_list args;
1368#endif
1369
1370 _init();
1371
1372// ROAR_DBG("ioctl(__fd=%i, __request=0x%lX) = ?", __fd, (long unsigned int) __request);
1373
1374#ifdef va_argp
1375 va_start (args, ioctl_lastarg);
1376 argp = va_arg (args, void *);
1377 va_end (args);
1378#endif
1379
1380// ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): argp=%p", __fd, (long unsigned int) __request, argp);
1381
1382 if ( (pointer = _get_pointer_by_fh(__fd)) != NULL ) {
1383  ip = argp;
1384//  ROAR_DBG("ioctl(__fd=%i, __request=0x%lx): ip=%p", __fd, (long unsigned int) __request, ip);
1385#ifdef __FIXME__
1386  switch ((handle = pointer->handle)->type) {
1387   case SOUND_PCM_READ_RATE: nosys_reqname     = "SOUND_PCM_READ_RATE";     break;
1388   case SOUND_PCM_READ_CHANNELS: nosys_reqname = "SOUND_PCM_READ_CHANNELS"; break;
1389   case SOUND_PCM_READ_BITS: nosys_reqname     = "SOUND_PCM_READ_BITS";     break;
1390   case SOUND_PCM_READ_FILTER: nosys_reqname   = "SOUND_PCM_READ_FILTER";   break;
1391   case SNDCTL_COPR_RESET: nosys_reqname       = "SNDCTL_COPR_RESET";       break;
1392   case SNDCTL_COPR_LOAD: nosys_reqname        = "SNDCTL_COPR_LOAD";        break;
1393   case SNDCTL_COPR_HALT: nosys_reqname        = "SNDCTL_COPR_HALT";        break;
1394   case SNDCTL_COPR_RDATA: nosys_reqname       = "SNDCTL_COPR_RDATA";       break;
1395   case SNDCTL_COPR_RCODE: nosys_reqname       = "SNDCTL_COPR_RCODE";       break;
1396   case SNDCTL_COPR_WDATA: nosys_reqname       = "SNDCTL_COPR_WDATA";       break;
1397   case SNDCTL_COPR_WCODE: nosys_reqname       = "SNDCTL_COPR_WCODE";       break;
1398   case SNDCTL_COPR_RUN: nosys_reqname         = "SNDCTL_COPR_RUN";         break;
1399   case SNDCTL_COPR_SENDMSG: nosys_reqname     = "SNDCTL_COPR_SENDMSG";     break;
1400   case SNDCTL_COPR_RCVMSG: nosys_reqname      = "SNDCTL_COPR_RCVMSG";      break;
1401   case SNDCTL_DSP_GETCAPS: nosys_reqname      = "SNDCTL_DSP_GETCAPS";      break;
1402   default: nosys_reqname = "<<<UNKNOWN>>>"; break;
1403/*
1404   case : nosys_reqname = ""; break;
1405   case : nosys_reqname = ""; break;
1406   case : nosys_reqname = ""; break;
1407*/
1408  }
1409#endif
1410  switch ((handle = pointer->handle)->type) {
1411   case HT_STREAM:
1412     switch (__request) {
1413      case SNDCTL_DSP_RESET:
1414      case SNDCTL_DSP_POST:
1415      case SNDCTL_DSP_SYNC: // ignore for the moment.
1416      case SNDCTL_DSP_SETFRAGMENT: // any fragments should be ok for us...
1417      case SNDCTL_DSP_SETTRIGGER: // we should implement this using PAUSE flag.
1418        return 0;
1419       break;
1420      case SNDCTL_DSP_SPEED:
1421        handle->stream.info.rate = *ip;
1422        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): rate=%i", __fd, (long unsigned int) __request, *ip);
1423        return 0;
1424       break;
1425      case SNDCTL_DSP_CHANNELS:
1426        handle->stream.info.channels = *ip;
1427        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): channels=%i", __fd, (long unsigned int) __request, *ip);
1428        return 0;
1429       break;
1430      case SNDCTL_DSP_STEREO:
1431        handle->stream.info.channels = *ip ? 2 : 1;
1432        return 0;
1433       break;
1434      case SNDCTL_DSP_GETBLKSIZE:
1435        *ip = _get_stream_buffersize(handle);
1436        return 0;
1437       break;
1438      case SNDCTL_DSP_SETFMT:
1439        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): fmt=0x%x", __fd, (long unsigned int) __request, *ip);
1440        return _ioctl_stream_format(handle, *ip);
1441       break;
1442      case SNDCTL_DSP_GETFMTS:
1443//        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): ip=%p", __fd, (long unsigned int) __request, ip);
1444        *ip = _ioctl_stream_format_list();
1445        return 0;
1446       break;
1447      case SNDCTL_DSP_GETOSPACE:
1448      case SNDCTL_DSP_GETISPACE:
1449        bi = argp;
1450        memset(bi, 0, sizeof(*bi));
1451        bi->bytes      = _get_stream_buffersize(handle);
1452        bi->fragments  = 1;
1453        bi->fragsize   = bi->bytes;
1454        bi->fragstotal = 1;
1455        return 0;
1456       break;
1457      case SNDCTL_DSP_GETOPTR:
1458        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): writec=%lu", __fd, (long unsigned int) __request, (long unsigned int) handle->writec);
1459        ci = argp;
1460        memset(ci, 0, sizeof(*ci));
1461        ci->bytes  = handle->writec;
1462        ci->blocks = ci->bytes / (tmp = _get_stream_buffersize(handle));
1463        ci->ptr    = ci->bytes % tmp;
1464        return 0;
1465       break;
1466      case SNDCTL_DSP_GETIPTR:
1467        ci = argp;
1468        memset(ci, 0, sizeof(*ci));
1469        ci->bytes  = handle->readc;
1470        ci->blocks = ci->bytes / (tmp = _get_stream_buffersize(handle));
1471        ci->ptr    = ci->bytes % tmp;
1472        return 0;
1473       break;
1474#ifdef SNDCTL_DSP_GETPLAYVOL
1475      case SNDCTL_DSP_GETPLAYVOL:
1476        return _ioctl_mixer(handle, SOUND_MIXER_READ_PCM, argp);
1477       break;
1478#endif
1479#ifdef SNDCTL_DSP_SETPLAYVOL
1480      case SNDCTL_DSP_SETPLAYVOL:
1481        return _ioctl_mixer(handle, SOUND_MIXER_WRITE_PCM, argp);
1482       break;
1483#endif
1484#ifdef SNDCTL_DSP_NONBLOCK
1485      case SNDCTL_DSP_NONBLOCK:
1486        return fcntl(__fd, F_SETFL, handle->sysio_flags|O_NONBLOCK);
1487       break;
1488#endif
1489      default:
1490#ifdef __FIXME__
1491        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX (%s)) = -1 // errno = ENOSYS", __fd, (long unsigned int) __request, nosys_reqname);
1492#else
1493        ROAR_DBG("ioctl(__fd=%i, __request=0x%lX) = -1 // errno = ENOSYS", __fd, (long unsigned int) __request);
1494#endif
1495        errno = ENOSYS;
1496        return -1;
1497     }
1498    break;
1499   case HT_MIXER:
1500     return _ioctl_mixer(handle, __request, argp);
1501    break;
1502   default:
1503     ROAR_DBG("ioctl(__fd=%i, __request=0x%lX): unknown handle type: no ioctl()s supported", __fd, (long unsigned int) __request);
1504     ROAR_DBG("ioctl(__fd=%i, __request=0x%lX) = -1 // errno = ENOSYS", __fd, (long unsigned int) __request);
1505     errno = EINVAL;
1506     return -1;
1507    break;
1508  }
1509 }
1510
1511#ifdef IOCTL_IS_ALIAS
1512 errno = ENOSYS;
1513 return -1;
1514#else
1515 return _os.ioctl(__fd, __request, argp);
1516#endif
1517}
1518
1519int dup(int oldfd) {
1520 struct pointer * pointer;
1521 int ret;
1522
1523 _init();
1524
1525 ret = _os.dup(oldfd);
1526
1527 if (ret == -1)
1528  return -1;
1529
1530 if ( (pointer = _get_pointer_by_fh(oldfd)) != NULL ) {
1531  if ( _attach_pointer(pointer->handle, ret) == NULL ) {
1532   _os.close(ret);
1533   return -1;
1534  }
1535 }
1536
1537 return ret;
1538}
1539
1540int dup2(int oldfd, int newfd) {
1541 struct pointer * pointer;
1542 int ret;
1543
1544 _init();
1545
1546 ret = _os.dup2(oldfd, newfd);
1547
1548 if (ret == -1)
1549  return -1;
1550
1551 if ( (pointer = _get_pointer_by_fh(oldfd)) != NULL ) {
1552  if ( _attach_pointer(pointer->handle, ret) == NULL ) {
1553   _os.close(ret);
1554   return -1;
1555  }
1556 }
1557
1558 return ret;
1559}
1560
1561int select(int nfds, fd_set *readfds, fd_set *writefds,
1562           fd_set *exceptfds, struct timeval *timeout) {
1563 struct roar_vio_selecttv rtv;
1564 struct roar_vio_select * sv  = NULL;
1565 struct pointer * pointer;
1566 struct handle  * handle;
1567 ssize_t ret;
1568 size_t num = 0;
1569 size_t idx;
1570 int i;
1571 int i_r, i_w, i_e;
1572 int max_index = -1;
1573 static volatile int is_critical = 0;
1574
1575 _init();
1576
1577 if ( is_critical )
1578  return _os.select(nfds, readfds, writefds, exceptfds, timeout);
1579
1580 ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = ?", nfds, readfds, writefds, exceptfds, timeout);
1581
1582 if ( nfds == 0 ) {
1583  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = 0", nfds, readfds, writefds, exceptfds, timeout);
1584  return 0;
1585 }
1586
1587 if ( readfds == NULL && writefds == NULL && exceptfds == NULL ) {
1588  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = 0", nfds, readfds, writefds, exceptfds, timeout);
1589  return 0;
1590 }
1591
1592 if ( timeout != NULL ) {
1593  rtv.sec = timeout->tv_sec;
1594  rtv.nsec = timeout->tv_usec*1000;
1595 }
1596
1597 // count number of handles:
1598 for (i = 0; i < nfds; i++) {
1599  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p): i=%i, EXISTS", nfds, readfds, writefds, exceptfds, timeout, i);
1600  if ( (readfds   != NULL && FD_ISSET(i, readfds  )) ||
1601       (writefds  != NULL && FD_ISSET(i, writefds )) ||
1602       (exceptfds != NULL && FD_ISSET(i, exceptfds))
1603     ) {
1604   ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p): i=%i, EXISTS", nfds, readfds, writefds, exceptfds, timeout, i);
1605   num++;
1606   max_index = i;
1607  }
1608 }
1609
1610 if ( num == 0 ) {
1611  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = 0", nfds, readfds, writefds, exceptfds, timeout);
1612  return 0;
1613 }
1614
1615 nfds = max_index + 1;
1616
1617 // create sv;
1618 sv = roar_mm_malloc(sizeof(struct roar_vio_select)*num);
1619 if ( sv == NULL ) {
1620  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = -1", nfds, readfds, writefds, exceptfds, timeout);
1621  return -1;
1622 }
1623
1624 memset(sv, 0, sizeof(struct roar_vio_select)*num);
1625
1626 for (i = 0, idx = 0; i < nfds; i++) {
1627  if ( idx >= num ) {
1628   roar_mm_free(sv);
1629   errno = EFAULT;
1630   ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = -1 // i=%i, idx=%i, num=%i", nfds, readfds, writefds, exceptfds, timeout, i, (int)idx, (int)num);
1631   return -1;
1632  }
1633  i_r = readfds   != NULL && FD_ISSET(i, readfds);
1634  i_w = writefds  != NULL && FD_ISSET(i, writefds);
1635  i_e = exceptfds != NULL && FD_ISSET(i, exceptfds);
1636
1637  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p): i=%i, i_r=%i, i_w=%i, i_e=%i", nfds, readfds, writefds, exceptfds, timeout, i, i_r, i_w, i_e);
1638
1639  if ( i_r || i_w || i_e ) {
1640   // TODO: use VIO for pointers...
1641   if ( (pointer = _get_pointer_by_fh(i)) != NULL ) {
1642    handle = pointer->handle;
1643    sv[idx].vio     = NULL;
1644    sv[idx].fh      = -1;
1645    switch (handle->type) {
1646     case HT_DMX:
1647     case HT_STREAM:
1648       if ( ! handle->stream_opened ) {
1649        // implement this as statichly return OK
1650        errno = ENOSYS;
1651        return -1;
1652       }
1653     case HT_VIO:
1654       sv[idx].vio = &(handle->stream_vio);
1655      break;
1656     default: /* non supported type */
1657       errno = EINVAL;
1658       return -1;
1659      break;
1660    }
1661   } else {
1662    sv[idx].vio     = NULL;
1663    sv[idx].fh      = i;
1664   }
1665
1666   sv[idx].ud.si   = i;
1667   sv[idx].eventsq = (i_r ? ROAR_VIO_SELECT_READ   : 0) |
1668                     (i_w ? ROAR_VIO_SELECT_WRITE  : 0) |
1669                     (i_e ? ROAR_VIO_SELECT_EXCEPT : 0);
1670   idx++;
1671  }
1672 }
1673
1674 is_critical++;
1675 ret = roar_vio_select(sv, num, timeout == NULL ? NULL : &rtv, NULL);
1676 is_critical--;
1677
1678 if ( ret < 1 ) {
1679  roar_mm_free(sv);
1680  ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = %i", nfds, readfds, writefds, exceptfds, timeout, (int)ret);
1681  return ret;
1682 }
1683
1684 // update readfds, writefds, exceptfds:
1685 if ( readfds != NULL )
1686  FD_ZERO(readfds);
1687
1688 if ( writefds != NULL )
1689  FD_ZERO(writefds);
1690
1691 if ( exceptfds != NULL )
1692  FD_ZERO(exceptfds);
1693
1694 for (idx = 0; idx < num; idx++) {
1695  if ( sv[idx].eventsa == 0 )
1696   continue;
1697
1698  if ( sv[idx].eventsa & ROAR_VIO_SELECT_READ )
1699   if ( readfds != NULL )
1700    FD_SET(sv[idx].ud.si, readfds);
1701
1702  if ( sv[idx].eventsa & ROAR_VIO_SELECT_WRITE )
1703   if ( writefds != NULL )
1704    FD_SET(sv[idx].ud.si, writefds);
1705
1706  if ( sv[idx].eventsa & ROAR_VIO_SELECT_EXCEPT )
1707   if ( exceptfds != NULL )
1708    FD_SET(sv[idx].ud.si, exceptfds);
1709 }
1710
1711 roar_mm_free(sv);
1712
1713 ROAR_DBG("select(nfds=%i, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p) = %i", nfds, readfds, writefds, exceptfds, timeout, (int)ret);
1714 return ret;
1715}
1716
1717int fcntl(int fd, int cmd, ...) {
1718 enum { NONE, UNKNOWN, LONG, POINTER } type = NONE;
1719 struct pointer * pointer;
1720 va_list ap;
1721 long argl = -1;
1722 void * vp = NULL;
1723 int ret   = -1;
1724 int diff;
1725
1726 _init();
1727
1728 ROAR_DBG("fcntl(fd=%i, cmd=%i, ...) = ?", fd, cmd);
1729
1730 switch (cmd) {
1731  case F_DUPFD:
1732  case F_SETFD:
1733  case F_SETFL:
1734  case F_SETOWN:
1735#ifdef F_SETSIG
1736  case F_SETSIG:
1737#endif
1738#ifdef F_SETLEASE
1739  case F_SETLEASE:
1740#endif
1741#ifdef F_NOTIFY
1742  case F_NOTIFY:
1743#endif
1744    type = LONG;
1745   break;
1746  case F_GETFD:
1747  case F_GETFL:
1748  case F_GETOWN:
1749#ifdef F_GETSIG
1750  case F_GETSIG:
1751#endif
1752#ifdef F_GETLEASE
1753  case F_GETLEASE:
1754#endif
1755    type = NONE;
1756   break;
1757  case F_GETLK:
1758  case F_SETLK:
1759  case F_SETLKW:
1760    type = POINTER;
1761   break;
1762/*
1763  case F_EXLCK:
1764  case F_GETLK64:
1765  case F_SETLK64:
1766  case F_SETLKW64:
1767  case F_SHLCK:
1768  case F_LINUX_SPECIFIC_BASE:
1769  case F_INPROGRESS:
1770*/
1771  default:
1772    type = UNKNOWN;
1773 }
1774
1775 if ( type == UNKNOWN ) {
1776  errno = EINVAL;
1777  return -1;
1778 }
1779
1780 if ( type != NONE ) {
1781  va_start(ap, cmd);
1782  switch (type) {
1783   case LONG:
1784     argl = va_arg(ap, long);
1785    break;
1786   case POINTER:
1787     vp = va_arg(ap, void*);
1788    break;
1789   default: /* make compiler happy */
1790    break;
1791  }
1792  va_end(ap);
1793 }
1794
1795 if ( (pointer = _get_pointer_by_fh(fd)) == NULL ) {
1796  switch (type) {
1797   case NONE:
1798     ROAR_DBG("fcntl(fd=%i, cmd=%i): fd is true sysio, pass call to kernel", fd, cmd);
1799     return _os.fcntl(fd, cmd);
1800    break;
1801   case LONG:
1802     ROAR_DBG("fcntl(fd=%i, cmd=%i, arg=%li): fd is true sysio, pass call to kernel", fd, cmd, argl);
1803     return _os.fcntl(fd, cmd, argl);
1804    break;
1805   case POINTER:
1806     ROAR_DBG("fcntl(fd=%i, cmd=%i, lock=%p): fd is true sysio, pass call to kernel", fd, cmd, vp);
1807     return _os.fcntl(fd, cmd, vp);
1808    break;
1809   default: /* make compiler happy */
1810    break;
1811  }
1812 }
1813
1814 ROAR_DBG("fcntl(fd=%i, cmd=%i, ...): fd is true pointer, handle internaly", fd, cmd);
1815
1816 switch (cmd) {
1817  case F_DUPFD:
1818    ret = _os.fcntl(fd, F_DUPFD, argl);
1819
1820    if ( ret != -1 ) {
1821     if ( _attach_pointer(pointer->handle, ret) == NULL ) {
1822      _os.close(ret);
1823      ret = -1;
1824     }
1825    }
1826   break;
1827  case F_SETFD:
1828    if ( argl == 0 ) {
1829     ret = 0;
1830    } else {
1831     errno = ENOSYS;
1832     ret = -1;
1833    }
1834   break;
1835  case F_GETFD:
1836    ret = 0;
1837   break;
1838  case F_GETFL:
1839    ret = pointer->handle->sysio_flags;
1840   break;
1841  case F_SETFL:
1842    diff  = (int)argl ^ pointer->handle->sysio_flags;
1843    diff &= (int)~(int)_O_PARA_DIR;
1844    diff &= (int)~(int)_O_PARA_IGN;
1845
1846    if ( diff & O_NONBLOCK ) {
1847     diff -= O_NONBLOCK;
1848     pointer->handle->sysio_flags ^= O_NONBLOCK;
1849     if ( _update_nonblock(pointer->handle) == -1 ) {
1850      pointer->handle->sysio_flags ^= O_NONBLOCK;
1851      return -1;
1852     }
1853    }
1854
1855    if ( diff == 0 ) { // only flags changed we ignore anyway.
1856     pointer->handle->sysio_flags  = (int)argl;
1857     ret = 0;
1858    } else {
1859     errno = EINVAL;
1860     ret = -1;
1861    }
1862   break;
1863/* TODO: add support for those types:
1864  case F_SETFD:
1865  case F_SETOWN:
1866  case F_SETSIG:
1867  case F_SETLEASE:
1868  case F_NOTIFY:
1869  case F_GETOWN:
1870  case F_GETSIG:
1871  case F_GETLEASE:
1872  case F_GETLK:
1873  case F_SETLK:
1874  case F_SETLKW:
1875*/
1876  default:
1877    errno = ENOSYS;
1878    ret = -1;
1879   break;
1880 }
1881
1882 return ret;
1883}
1884
1885int access(const char *pathname, int mode) {
1886 struct devices * ptr = NULL;
1887
1888 _init();
1889
1890 if ( (ptr = _get_device(pathname)) != NULL ) {
1891  // the only flag we do not support is +x, which means
1892  // we need to reject all requets with X_OK.
1893  if ( mode & X_OK ) {
1894   errno = EACCES;
1895   return -1;
1896  }
1897
1898  // in addition HT_STATIC files do not support write (+w)
1899  // so we need to reject W_OK.
1900  if ( ptr->type == HT_STATIC && (mode & W_OK) ) {
1901   errno = EACCES;
1902   return -1;
1903  }
1904
1905  // Else the access is granted:
1906  return 0;
1907 }
1908
1909 return _os.access(pathname, mode);
1910}
1911
1912int creat(const char *_CREAT_ARG_PATHNAME, mode_t mode) {
1913 _init();
1914
1915 if ( _get_device(_CREAT_ARG_PATHNAME) != NULL ) {
1916  errno = EEXIST;
1917  return -1;
1918 }
1919
1920 return _os.creat(_CREAT_ARG_PATHNAME, mode);
1921}
1922
1923// -------------------------------------
1924// emulated *stat*() functions follow:
1925// -------------------------------------
1926
1927int stat(const char *path, struct stat *buf) {
1928 struct devices * ptr;
1929
1930 _init();
1931
1932 if ( (ptr = _get_device(path)) != NULL ) {
1933  errno = ENOSYS;
1934  return -1;
1935 }
1936
1937 return _os.stat(path, buf);
1938}
1939
1940int fstat(int filedes, struct stat *buf) {
1941 struct pointer * pointer;
1942
1943 _init();
1944
1945 if ( (pointer = _get_pointer_by_fh(filedes)) == NULL ) {
1946  return _os.fstat(filedes, buf);
1947 }
1948
1949 errno = ENOSYS;
1950 return -1;
1951}
1952
1953int lstat(const char *path, struct stat *buf) {
1954 _init();
1955
1956 if ( _get_device(path) != NULL ) {
1957  return stat(path, buf);
1958 }
1959
1960 return _os.lstat(path, buf);
1961}
1962
1963// -------------------------------------
1964// emulated stdio functions follow:
1965// -------------------------------------
1966
1967//roar_vio_to_stdio
1968
1969static int _vio_close    (struct roar_vio_calls * vio) {
1970 int ret = 0;
1971
1972 if ( roar_vio_get_fh(vio) != -1 )
1973  ret = close(roar_vio_get_fh(vio));
1974
1975 roar_mm_free(vio);
1976
1977 return ret;
1978}
1979
1980FILE *fopen(const char *path, const char *mode) {
1981 struct roar_vio_calls * vio;
1982 FILE  * fr;
1983 int     ret;
1984 int     r = 0, w = 0;
1985 int     flags = 0;
1986 int     i;
1987 register char c;
1988
1989 _init();
1990
1991 if ( path == NULL || mode == NULL ) {
1992  errno = EFAULT;
1993  return NULL;
1994 }
1995
1996 ROAR_DBG("open(path='%s', mode='%s') = ?\n", path, mode);
1997
1998 for (i = 0; (c = mode[i]) != 0; i++) {
1999  switch (c) {
2000   case 'r': r = 1; break;
2001   case 'w': w = 1; break;
2002   case 'a': w = 1; break;
2003   case '+':
2004     r = 1;
2005     w = 1;
2006    break;
2007  }
2008 }
2009
2010 if ( r && w ) {
2011  flags = O_RDWR;
2012 } else if ( r ) {
2013  flags = O_RDONLY;
2014 } else if ( w ) {
2015  flags = O_WRONLY;
2016 } else {
2017  errno = EINVAL;
2018  return NULL;
2019 }
2020
2021 ret = _open_file(path, flags);
2022
2023 switch (ret) {
2024  case -2:       // continue as normal, use _op.open()
2025   break;
2026  case -1:       // pass error to caller
2027    return NULL;
2028   break;
2029  default:       // return successfully opened pointer to caller
2030    if ( (vio = roar_mm_malloc(sizeof(struct roar_vio_calls))) == NULL ) {
2031     return NULL; // errno should be set correctly by roar_mm_malloc().
2032    }
2033
2034    roar_vio_init_calls(vio);  // TODO: add error handling.
2035    roar_vio_set_fh(vio, ret); // TODO: add error handling.
2036    vio->close = _vio_close;
2037    if ( (fr = roar_vio_to_stdio(vio, flags)) == NULL ) {
2038     _vio_close(vio);
2039     errno = EIO;
2040     return NULL;
2041    } else {
2042     return fr;
2043    }
2044   break;
2045 }
2046
2047 return _os.fopen(path, mode);
2048}
2049
2050// -------------------------------------
2051// RoarAudio plugin functions follow:
2052// -------------------------------------
2053
2054ROAR_DL_PLUGIN_START(libroaross) {
2055 (void)para;
2056 _init();
2057} ROAR_DL_PLUGIN_END
2058
2059#endif
2060
2061//ll
Note: See TracBrowser for help on using the repository browser.