Index: libroar/vio.c
===================================================================
--- libroar/vio.c	(revision 4831)
+++ libroar/vio.c	(revision 4873)
@@ -46,6 +46,8 @@
 int roar_vio_init_calls (struct roar_vio_calls * calls) {
 #ifdef _CAN_OPERATE
- if ( calls == NULL )
-  return -1;
+ if ( calls == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
@@ -72,6 +74,8 @@
 
 int roar_vio_set_inst (struct roar_vio_calls * vio, void * inst) {
- if ( vio == NULL )
-  return -1;
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  vio->inst = inst;
@@ -85,6 +89,8 @@
 
 int roar_vio_get_fh   (struct roar_vio_calls * vio) {
- if ( vio == NULL )
-  return -1;
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return ((int)(ROAR_INSTINT)vio->inst) - 1;
@@ -93,68 +99,122 @@
 
 ssize_t roar_vio_read (struct roar_vio_calls * vio, void *buf, size_t count) {
+ ssize_t ret;
+
  ROAR_DBG("roar_vio_read(vio=%p, buf=%p, count=%u) = ?", vio, buf, (unsigned int)count);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->read == NULL )
-  return -1;
-
- return vio->read(vio, buf, count);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->read == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->read(vio, buf, count);
+ roar_err_update();
+
+ return ret;
 }
 
 ssize_t roar_vio_write(struct roar_vio_calls * vio, void *buf, size_t count) {
+ ssize_t ret;
+
  ROAR_DBG("roar_vio_write(vio=%p, buf=%p, count=%u) = ?", vio, buf, (unsigned int)count);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->write == NULL )
-  return -1;
-
- return vio->write(vio, buf, count);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->write == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->write(vio, buf, count);
+ roar_err_update();
+
+ return ret;
 }
 
 off_t   roar_vio_lseek(struct roar_vio_calls * vio, off_t offset, int whence) {
+ off_t ret;
+
  ROAR_DBG("roar_vio_lseek(vio=%p, offset=%u, whence=%i) = ?", vio, (unsigned int)offset, whence);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->lseek == NULL )
-  return -1;
-
- return vio->lseek(vio, offset, whence);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->lseek == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->lseek(vio, offset, whence);
+ roar_err_update();
+
+ return ret;
 }
 
 int     roar_vio_nonblock(struct roar_vio_calls * vio, int state) {
+ int ret;
+
  ROAR_DBG("roar_vio_nonblock(vio=%p, state=%i) = ?", vio, state);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->nonblock == NULL )
-  return -1;
-
- return vio->nonblock(vio, state);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->nonblock == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->nonblock(vio, state);
+ roar_err_update();
+
+ return ret;
 }
 
 int     roar_vio_sync    (struct roar_vio_calls * vio) {
+ int ret;
+
  ROAR_DBG("roar_vio_sync(vio=%p) = ?", vio);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->sync == NULL )
-  return -1;
-
- return vio->sync(vio);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->sync == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->sync(vio);
+ roar_err_update();
+
+ return ret;
 }
 
 int     roar_vio_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
+ int ret;
+
  ROAR_DBG("roar_vio_ctl(vio=%p, cmd=%i, data=%p) = ?", vio, cmd, data);
 
- if ( vio == NULL )
-  return -1;
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  ROAR_DBG("roar_vio_ctl(vio=%p, cmd=0x%.8x, data=%p): vio->ctl=%p", vio, cmd, data, vio->ctl);
@@ -166,30 +226,49 @@
     ROAR_ERR("roar_vio_ctl(vio=%p, cmd=0x%.8x, data=%p): Please recompile your program to fix this. (No additional steps are required beside that.)", vio, cmd, data);
     ROAR_DBG("roar_vio_ctl(vio=%p, cmd=0x%.8x, data=%p) = -1", vio, cmd, data);
+    roar_err_set(ROAR_ERROR_BADRQC);
     return -1;
    break;
  }
 
- if ( vio->ctl == NULL )
-  return -1;
-
- return vio->ctl(vio, cmd, data);
+ if ( vio->ctl == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->ctl(vio, cmd, data);
+ roar_err_update();
+
+ return ret;
 }
 
 int     roar_vio_close    (struct roar_vio_calls * vio) {
+ int ret;
+
  ROAR_DBG("roar_vio_close(vio=%p) = ?", vio);
 
- if ( vio == NULL )
-  return -1;
-
- if ( vio->close == NULL )
-  return -1;
-
- return vio->close(vio);
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->close == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
+  return -1;
+ }
+
+ roar_err_clear_all();
+ ret = vio->close(vio);
+ roar_err_update();
+
+ return ret;
 }
 
 // specal commands:
 int     roar_vio_accept  (struct roar_vio_calls * calls, struct roar_vio_calls * dst) {
- if (dst == NULL || calls == NULL)
-  return -1;
+ if (dst == NULL || calls == NULL) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return roar_vio_ctl(dst, ROAR_VIO_CTL_ACCEPT, calls);
@@ -205,6 +284,10 @@
  int fh;
 
- if ( calls == NULL || filename == NULL )
-  return -1;
+ roar_debug_warn_obsolete("roar_vio_open_file", "roar_vio_open_dstr", NULL);
+
+ if ( calls == NULL || filename == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
 #ifdef ROAR_TARGET_WIN32
@@ -212,12 +295,17 @@
 #endif
 
- if ( (fh = open(filename, flags, mode)) == -1 )
-  return -1;
+ roar_err_clear_all();
+ if ( (fh = open(filename, flags, mode)) == -1 ) {
+  roar_err_update();
+  return -1;
+ }
 
  if ( roar_vio_open_fh(calls, fh) == -1 ) {
   close(fh);
-  return -1;
- }
-
+  roar_err_update();
+  return -1;
+ }
+
+ roar_err_update();
  return 0;
 #else
@@ -584,4 +672,5 @@
  }
 
+ roar_err_set(ROAR_ERROR_BADRQC);
  return -1;
 }
@@ -708,5 +797,5 @@
   return -1;
 
- errno = 0;
+ roar_err_clear_all();
 
  while ( (r = roar_vio_read((struct roar_vio_calls *) vio->inst, buf, count)) > 0 ) {
@@ -734,5 +823,5 @@
   return -1;
 
- errno = 0;
+ roar_err_clear_all();
 
  while ( (r = roar_vio_write((struct roar_vio_calls *) vio->inst, buf, count)) > 0 ) {
