source: roaraudio/libroar/error.c @ 5231:8b30ddb689b8

Last change on this file since 5231:8b30ddb689b8 was 5216:e16c15116d46, checked in by phi, 12 years ago

moved roar_err_{build,parse}msg2() -> roar_err_{build,parse}msg(), see #184

File size: 30.8 KB
Line 
1//error.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
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 "libroar.h"
37
38// 'no error' value for errno.
39// zero is true for GNU/Linux.
40// don't know about other systems.
41// IEEE Std 1003.1-2008 (POSIX 7) requires:
42// 'distinct positive values'.
43#define CLEAN_ERRNO 0
44
45static int roar_errno = ROAR_ERROR_NONE;
46
47struct roar_error_frame * roar_err_errorframe(void) {
48 static struct roar_error_frame frame = {
49  .version     =  0,
50  .cmd         = -1,
51  .ra_errno    = ROAR_ERROR_UNKNOWN,
52  .ra_suberrno = -1,
53  .p_errno     = -1,
54  .flags       =  0,
55  .datalen     =  0,
56  .data        = NULL
57 };
58
59 return &frame;
60}
61
62int    roar_err_init(struct roar_error_frame * frame) {
63 if ( frame == NULL ) {
64  roar_err_set(ROAR_ERROR_FAULT);
65  return -1;
66 }
67
68 memset(frame, 0, sizeof(struct roar_error_frame));
69
70 frame->cmd         = -1;
71 frame->ra_errno    = ROAR_ERROR_UNKNOWN;
72 frame->ra_suberrno = -1;
73 frame->p_errno     = -1;
74 frame->datalen     =  0;
75 frame->data        = NULL;
76
77 return 0;
78}
79
80
81void * roar_err_buildmsg(struct roar_message * mes, void ** data, struct roar_error_frame * frame) {
82 char * databuf = NULL;
83 int16_t * d;
84 size_t datalen;
85
86 if ( mes == NULL || frame == NULL ) {
87  roar_err_set(ROAR_ERROR_FAULT);
88  return NULL;
89 }
90
91 if ( data != NULL )
92  *data = NULL;
93
94 datalen = 8 + frame->datalen;
95 if ( datalen > LIBROAR_BUFFER_MSGDATA ) {
96  if ( data == NULL ) {
97   roar_err_set(ROAR_ERROR_FAULT);
98   return NULL;
99  }
100
101  roar_err_clear_errno();
102  *data = malloc(datalen);
103  roar_err_from_errno();
104  if ( *data == NULL )
105   return NULL;
106
107  databuf = *data;
108 } else {
109  databuf = mes->data;
110 }
111
112 memset(mes,  0, sizeof(struct roar_message));
113 memset(databuf, 0, mes->datalen);
114
115 mes->datalen = datalen;
116
117 d = (int16_t*)databuf;
118
119 frame->data  = &(databuf[8]);
120
121 databuf[0]    = 0; // version.
122 databuf[1]    = frame->cmd;
123 databuf[2]    = frame->ra_errno;
124 databuf[3]    = frame->ra_suberrno;
125 d[2]            = ROAR_HOST2NET16(frame->p_errno);
126 d[3]            = ROAR_HOST2NET16(frame->flags);
127
128 return frame->data;
129}
130
131int    roar_err_parsemsg(struct roar_message * mes, void *  data, struct roar_error_frame * frame) {
132 char * databuf = (char *)data;
133 int16_t * d;
134
135 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
136          mes, (int)mes->datalen, mes->data, data, frame);
137
138 if ( mes == NULL || frame == NULL ) {
139  roar_err_set(ROAR_ERROR_FAULT);
140  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=FAULT",
141           mes, (int)mes->datalen, mes->data, data, frame);
142  return -1;
143 }
144
145 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
146          mes, (int)mes->datalen, mes->data, data, frame);
147
148 if ( databuf == NULL )
149  databuf = mes->data;
150
151 d = (int16_t*)databuf;
152
153 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
154          mes, (int)mes->datalen, mes->data, data, frame);
155
156 if ( mes->datalen < 8 ) {
157  roar_err_set(ROAR_ERROR_MSGSIZE);
158  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=MSGSIZE",
159           mes, (int)mes->datalen, mes->data, data, frame);
160  return -1;
161 }
162
163 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
164          mes, (int)mes->datalen, mes->data, data, frame);
165
166 if ( databuf[0] != 0 ) {
167  roar_err_set(ROAR_ERROR_NSVERSION);
168  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=NSVERSION",
169           mes, (int)mes->datalen, mes->data, data, frame);
170  return -1;
171 }
172
173 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
174          mes, (int)mes->datalen, mes->data, data, frame);
175
176 frame->cmd         = databuf[1];
177 frame->ra_errno    = databuf[2];
178 frame->ra_suberrno = databuf[3];
179 frame->p_errno     = ROAR_NET2HOST16(d[2]);
180 frame->flags       = ROAR_NET2HOST16(d[3]);
181
182 frame->datalen     = mes->datalen - 8;
183 frame->data        = &(databuf[8]);
184
185 ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = 0",
186          mes, (int)mes->datalen, mes->data, data, frame);
187 return 0;
188}
189
190int *  roar_errno2(void) {
191 return &roar_errno;
192}
193
194void   roar_err_clear(void) {
195 *roar_errno2() = ROAR_ERROR_NONE;
196}
197
198void   roar_err_clear_errno(void) {
199 errno = CLEAN_ERRNO;
200}
201
202void   roar_err_clear_all(void) {
203 roar_err_clear();
204 roar_err_clear_errno();
205}
206
207void   roar_err_update(void) {
208 int * err = roar_errno2();
209
210 // NOTE: _NEVER_ call ROAR_{DBG,INFO,WARN,ERR}() in here! (will result in endless loop)
211 //printf("*err=%i, errno=%i\n", *err, (int)errno);
212
213 if ( *err != ROAR_ERROR_NONE ) {
214  roar_err_to_errno();
215 } else if ( !roar_err_is_errno_clear() ) {
216  roar_err_from_errno();
217 }
218}
219
220int    roar_err_is_errno_clean(void) {
221 roar_debug_warn_obsolete("roar_err_is_errno_clean", "roar_err_is_errno_clear", NULL);
222 return roar_err_is_errno_clear();
223}
224
225int    roar_err_is_errno_clear(void) {
226 return errno == CLEAN_ERRNO ? 1 : 0;
227}
228
229void   roar_err_set(const int error) {
230 *roar_errno2() = error;
231}
232
233void   roar_err_from_errno(void) {
234 int _roar_errno = ROAR_ERROR_NONE;
235
236 switch (errno) {
237#ifdef EACCES
238  case EACCES:       _roar_errno = ROAR_ERROR_PERM; break;
239#endif
240#ifdef EPERM
241  case EPERM:        _roar_errno = ROAR_ERROR_PERM; break;
242#endif
243#ifdef ENOENT
244  case ENOENT:       _roar_errno = ROAR_ERROR_NOENT; break;
245#endif
246#ifdef EBADMSG
247  case EBADMSG:      _roar_errno = ROAR_ERROR_BADMSG; break;
248#endif
249#ifdef EBUSY
250  case EBUSY:        _roar_errno = ROAR_ERROR_BUSY; break;
251#endif
252#ifdef ECONNREFUSED
253  case ECONNREFUSED: _roar_errno = ROAR_ERROR_CONNREFUSED; break;
254#endif
255#ifdef ENOSYS
256  case ENOSYS:       _roar_errno = ROAR_ERROR_NOSYS; break;
257#endif
258#ifdef ENOTSUP
259  case ENOTSUP:      _roar_errno = ROAR_ERROR_NOTSUP; break;
260#endif
261#ifdef EPIPE
262  case EPIPE:        _roar_errno = ROAR_ERROR_PIPE; break;
263#endif
264#ifdef EPROTO
265  case EPROTO:       _roar_errno = ROAR_ERROR_PROTO; break;
266#endif
267#ifdef ERANGE
268  case ERANGE:       _roar_errno = ROAR_ERROR_RANGE; break;
269#endif
270#ifdef EMSGSIZE
271  case EMSGSIZE:     _roar_errno = ROAR_ERROR_MSGSIZE; break;
272#endif
273#ifdef ENOMEM
274  case ENOMEM:       _roar_errno = ROAR_ERROR_NOMEM; break;
275#endif
276#ifdef EINVAL
277  case EINVAL:       _roar_errno = ROAR_ERROR_INVAL; break;
278#endif
279#ifdef EALREADY
280  case EALREADY:     _roar_errno = ROAR_ERROR_ALREADY; break;
281#endif
282#ifdef EBADRQC
283  case EBADRQC:      _roar_errno = ROAR_ERROR_BADRQC; break;
284#endif
285#ifdef EDOM
286  case EDOM:         _roar_errno = ROAR_ERROR_DOM; break;
287#endif
288#ifdef EEXIST
289  case EEXIST:       _roar_errno = ROAR_ERROR_EXIST; break;
290#endif
291#ifdef EFAULT
292  case EFAULT:       _roar_errno = ROAR_ERROR_FAULT; break;
293#endif
294#ifdef EIO
295  case EIO:          _roar_errno = ROAR_ERROR_IO; break;
296#endif
297#ifdef EREMOTEIO
298  case EREMOTEIO:    _roar_errno = ROAR_ERROR_RIO; break;
299#endif
300#ifdef EKEYEXPIRED
301  case EKEYEXPIRED:  _roar_errno = ROAR_ERROR_KEYEXPIRED; break;
302#endif
303#ifdef EKEYREJECTED
304  case EKEYREJECTED: _roar_errno = ROAR_ERROR_KEYREJECTED; break;
305#endif
306#ifdef ELOOP
307  case ELOOP:        _roar_errno = ROAR_ERROR_LOOP; break;
308#endif
309#ifdef EMFILE
310  case EMFILE:       _roar_errno = ROAR_ERROR_MFILE; break;
311#endif
312#ifdef ENAMETOOLONG
313  case ENAMETOOLONG: _roar_errno = ROAR_ERROR_NAMETOOLONG; break;
314#endif
315#ifdef ENODATA
316  case ENODATA:      _roar_errno = ROAR_ERROR_NODATA; break;
317#endif
318#ifdef ENODEV
319  case ENODEV:       _roar_errno = ROAR_ERROR_NODEV; break;
320#endif
321#ifdef ENOSPC
322  case ENOSPC:       _roar_errno = ROAR_ERROR_NOSPC; break;
323#endif
324#ifdef ENOTCONN
325  case ENOTCONN:     _roar_errno = ROAR_ERROR_NOTCONN; break;
326#endif
327#ifdef EPROTONOSUPPORT
328  case EPROTONOSUPPORT: _roar_errno = ROAR_ERROR_PROTONOSUP; break;
329#endif
330#ifdef EROFS
331  case EROFS:        _roar_errno = ROAR_ERROR_RO; break;
332#endif
333#ifdef ETIMEDOUT
334  case ETIMEDOUT:    _roar_errno = ROAR_ERROR_TIMEDOUT; break;
335#endif
336#ifdef EAGAIN
337  case EAGAIN:       _roar_errno = ROAR_ERROR_AGAIN; break;
338#endif
339#ifdef ENETDOWN
340  case ENETDOWN:     _roar_errno = ROAR_ERROR_LINKDOWN; break;
341#endif
342#ifdef EINTR
343  case EINTR:        _roar_errno = ROAR_ERROR_INTERRUPTED; break;
344#endif
345#ifdef EDQUOT
346  case EDQUOT:       _roar_errno = ROAR_ERROR_QUOTA; break;
347#endif
348#ifdef ELIBBAD
349  case ELIBBAD:      _roar_errno = ROAR_ERROR_BADLIB; break;
350#endif
351#ifdef ENOMEDIUM
352  case ENOMEDIUM:    _roar_errno = ROAR_ERROR_NOMEDIUM; break;
353#endif
354#ifdef ENOTUNIQ
355  case ENOTUNIQ:     _roar_errno = ROAR_ERROR_NOTUNIQ; break;
356#endif
357#ifdef EILSEQ
358  case EILSEQ:       _roar_errno = ROAR_ERROR_ILLSEQ; break;
359#endif
360#ifdef EADDRINUSE
361  case EADDRINUSE:   _roar_errno = ROAR_ERROR_ADDRINUSE; break;
362#endif
363#ifdef ESPIPE
364  case ESPIPE:       _roar_errno = ROAR_ERROR_BADSEEK; break;
365#endif
366#ifdef ECHERNOBYL
367  case ECHERNOBYL:   _roar_errno = ROAR_ERROR_CHERNOBYL; break;
368#endif
369#ifdef ECRAY
370  case ECRAY:        _roar_errno = ROAR_ERROR_CAUSALITY; break;
371#endif
372#ifdef ENOHORSE
373  case ENOHORSE:     _roar_errno = ROAR_ERROR_NOHORSE; break;
374#endif
375#ifdef ETXTBSY
376  case ETXTBSY:      _roar_errno = ROAR_ERROR_TEXTBUSY; break;
377#endif
378#ifdef ENOTEMPTY
379  case ENOTEMPTY:    _roar_errno = ROAR_ERROR_NOTEMPTY; break;
380#endif
381#ifdef EHOSTUNREACH
382  case EHOSTUNREACH: _roar_errno = ROAR_ERROR_NODEUNREACH; break;
383#endif
384#ifdef EIDRM
385  case EIDRM:        _roar_errno = ROAR_ERROR_IDREMOVED; break;
386#endif
387#ifdef EINPROGRESS
388  case EINPROGRESS:  _roar_errno = ROAR_ERROR_INPROGRESS; break;
389#endif
390#ifdef ECHILD
391  case ECHILD:       _roar_errno = ROAR_ERROR_NOCHILD; break;
392#endif
393#ifdef ENETUNREACH
394  case ENETUNREACH:  _roar_errno = ROAR_ERROR_NETUNREACH; break;
395#endif
396#ifdef ECANCELED
397  case ECANCELED:    _roar_errno = ROAR_ERROR_CANCELED; break;
398#endif
399#ifdef EISDIR
400  case EISDIR:       _roar_errno = ROAR_ERROR_ISDIR; break;
401#endif
402#ifdef ENOTDIR
403  case ENOTDIR:      _roar_errno = ROAR_ERROR_NOTDIR; break;
404#endif
405#ifdef ENOEXEC
406  case ENOEXEC:      _roar_errno = ROAR_ERROR_BADEXEC; break;
407#endif
408#ifdef EISCONN
409  case EISCONN:      _roar_errno = ROAR_ERROR_ISCONN; break;
410#endif
411#ifdef EDEADLK
412  case EDEADLK:      _roar_errno = ROAR_ERROR_DEADLOCK; break;
413#endif
414#ifdef ECONNRESET
415  case ECONNRESET:   _roar_errno = ROAR_ERROR_CONNRST; break;
416#endif
417#ifdef EBADF
418  case EBADF:        _roar_errno = ROAR_ERROR_BADFH; break;
419#endif
420#ifdef ENOTSOCK
421  case ENOTSOCK:     _roar_errno = ROAR_ERROR_NOTSOCK; break;
422#endif
423#ifdef E2BIG
424  case E2BIG:        _roar_errno = ROAR_ERROR_TOOMANYARGS; break;
425#endif
426#ifdef EFBIG
427  case EFBIG:        _roar_errno = ROAR_ERROR_TOOLARGE; break;
428#endif
429#ifdef EDESTADDRREQ
430  case EDESTADDRREQ: _roar_errno = ROAR_ERROR_DESTADDRREQ; break;
431#endif
432#ifdef EAFNOSUPPORT
433  case EAFNOSUPPORT: _roar_errno = ROAR_ERROR_AFNOTSUP; break;
434#endif
435#ifdef ENFILE
436  case ENFILE:       _roar_errno = ROAR_ERROR_NFILE; break;
437#endif
438#ifdef ESTALE
439  case ESTALE:       _roar_errno = ROAR_ERROR_STALE; break;
440#endif
441#ifdef EXDEV
442  case EXDEV:        _roar_errno = ROAR_ERROR_XDEVLINK; break;
443#endif
444#ifdef EMLINK
445  case EMLINK:       _roar_errno = ROAR_ERROR_MLINK; break;
446#endif
447#ifdef ENONET
448  case ENONET:       _roar_errno = ROAR_ERROR_NONET; break;
449#endif
450#ifdef ENETRESET
451  case ENETRESET:    _roar_errno = ROAR_ERROR_CONNRSTNET; break;
452#endif
453#ifdef ECONNABORTED
454  case ECONNABORTED: _roar_errno = ROAR_ERROR_CONNABORTED; break;
455#endif
456  default:
457    _roar_errno = ROAR_ERROR_UNKNOWN;
458   break;
459 }
460
461 roar_err_set(_roar_errno);
462}
463
464void   roar_err_to_errno(void) {
465 int * err = roar_errno2();
466 switch (*err) {
467  case ROAR_ERROR_NONE:
468    roar_err_clear_errno();
469   break;
470#ifdef EPERM
471  case ROAR_ERROR_PERM:
472    errno = EPERM;
473   break;
474#endif
475#ifdef ENOENT
476  case ROAR_ERROR_NOENT:
477    errno = ENOENT;
478   break;
479#endif
480#ifdef EBADMSG
481  case ROAR_ERROR_BADMSG:
482    errno = EBADMSG;
483   break;
484#endif
485#ifdef EBUSY
486  case ROAR_ERROR_BUSY:
487    errno = EBUSY;
488   break;
489#endif
490#ifdef ECONNREFUSED
491  case ROAR_ERROR_CONNREFUSED:
492    errno = ECONNREFUSED;
493   break;
494#endif
495#ifdef ENOSYS
496  case ROAR_ERROR_NOSYS:
497    errno = ENOSYS;
498   break;
499#endif
500#ifdef ENOTSUP
501  case ROAR_ERROR_NOTSUP:
502    errno = ENOTSUP;
503   break;
504#endif
505#ifdef EPIPE
506  case ROAR_ERROR_PIPE:
507    errno = EPIPE;
508   break;
509#endif
510#ifdef EPROTO
511  case ROAR_ERROR_PROTO:
512    errno = EPROTO;
513   break;
514#endif
515#ifdef ERANGE
516  case ROAR_ERROR_RANGE:
517    errno = ERANGE;
518   break;
519#endif
520#ifdef EMSGSIZE
521  case ROAR_ERROR_MSGSIZE:
522    errno = EMSGSIZE;
523   break;
524#endif
525#ifdef ENOMEM
526  case ROAR_ERROR_NOMEM:
527    errno = ENOMEM;
528   break;
529#endif
530#ifdef EINVAL
531  case ROAR_ERROR_INVAL:
532    errno = EINVAL;
533   break;
534#endif
535#ifdef EALREADY
536  case ROAR_ERROR_ALREADY:
537    errno = EALREADY;
538   break;
539#endif
540#ifdef EBADRQC
541  case ROAR_ERROR_BADRQC:
542    errno = EBADRQC;
543   break;
544#endif
545#ifdef EDOM
546  case ROAR_ERROR_DOM:
547    errno = EDOM;
548   break;
549#endif
550#ifdef EEXIST
551  case ROAR_ERROR_EXIST:
552    errno = EEXIST;
553   break;
554#endif
555#ifdef EFAULT
556  case ROAR_ERROR_FAULT:
557    errno = EFAULT;
558   break;
559#endif
560#if defined(EREMOTEIO) || defined(EIO)
561  case ROAR_ERROR_RIO:
562#ifdef EREMOTEIO
563    errno = EREMOTEIO;
564#else
565    errno = EIO;
566#endif
567   break;
568#endif
569#ifdef EIO
570  case ROAR_ERROR_IO:
571  case ROAR_ERROR_HOLE:
572  case ROAR_ERROR_BADCKSUM:
573  case ROAR_ERROR_LOSTSYNC:
574  case ROAR_ERROR_NOHORSE:
575    errno = EIO;
576   break;
577#endif
578#ifdef EKEYEXPIRED
579  case ROAR_ERROR_KEYEXPIRED:
580    errno = EKEYEXPIRED;
581   break;
582#endif
583#ifdef EKEYREJECTED
584  case ROAR_ERROR_KEYREJECTED:
585    errno = EKEYREJECTED;
586   break;
587#endif
588#ifdef ELOOP
589  case ROAR_ERROR_LOOP:
590    errno = ELOOP;
591   break;
592#endif
593#ifdef EMFILE
594  case ROAR_ERROR_MFILE:
595    errno = EMFILE;
596   break;
597#endif
598#ifdef ENAMETOOLONG
599  case ROAR_ERROR_NAMETOOLONG:
600    errno = ENAMETOOLONG;
601   break;
602#endif
603#ifdef ENODATA
604  case ROAR_ERROR_NODATA:
605    errno = ENODATA;
606   break;
607#endif
608#ifdef ENODEV
609  case ROAR_ERROR_NODEV:
610  case ROAR_ERROR_NODRV:
611    errno = ENODEV;
612   break;
613#endif
614#ifdef ENOSPC
615  case ROAR_ERROR_NOSPC:
616    errno = ENOSPC;
617   break;
618#endif
619#ifdef EINVAL
620  case ROAR_ERROR_TYPEMM:
621    errno = EINVAL;
622   break;
623#endif
624#ifdef ENOSYS
625  case ROAR_ERROR_NORSYS:
626    errno = ENOSYS;
627   break;
628#endif
629#ifdef ENOTCONN
630  case ROAR_ERROR_NOTCONN:
631    errno = ENOTCONN;
632   break;
633#endif
634#ifdef EPROTONOSUPPORT
635  case ROAR_ERROR_PROTONOSUP:
636    errno = EPROTONOSUPPORT;
637   break;
638#endif
639#ifdef EROFS
640  case ROAR_ERROR_RO:
641    errno = EROFS;
642   break;
643#endif
644#ifdef ETIMEDOUT
645  case ROAR_ERROR_TIMEDOUT:
646    errno = ETIMEDOUT;
647   break;
648#endif
649#ifdef EAGAIN
650  case ROAR_ERROR_AGAIN:
651    errno = EAGAIN;
652   break;
653#endif
654#ifdef ENETDOWN
655  case ROAR_ERROR_LINKDOWN:
656    errno = ENETDOWN;
657   break;
658#endif
659#ifdef EINTR
660  case ROAR_ERROR_INTERRUPTED:
661    errno = EINTR;
662   break;
663#endif
664#ifdef EDQUOT
665  case ROAR_ERROR_QUOTA:
666    errno = EDQUOT;
667   break;
668#endif
669#ifdef ELIBBAD
670  case ROAR_ERROR_BADLIB:
671    errno = ELIBBAD;
672   break;
673#endif
674#ifdef ENOMEDIUM
675  case ROAR_ERROR_NOMEDIUM:
676    errno = ENOMEDIUM;
677   break;
678#endif
679#ifdef ENOTUNIQ
680  case ROAR_ERROR_NOTUNIQ:
681    errno = ENOTUNIQ;
682   break;
683#endif
684#ifdef EILSEQ
685  case ROAR_ERROR_ILLSEQ:
686    errno = EILSEQ;
687   break;
688#endif
689#ifdef EADDRINUSE
690  case ROAR_ERROR_ADDRINUSE:
691    errno = EADDRINUSE;
692   break;
693#endif
694#ifdef ESPIPE
695  case ROAR_ERROR_BADSEEK:
696  case ROAR_ERROR_NOSEEK:
697    errno = ESPIPE;
698   break;
699#endif
700#ifdef ECHERNOBYL
701  case ROAR_ERROR_CHERNOBYL:
702    errno = ECHERNOBYL;
703   break;
704#endif
705#ifdef ECRAY
706  case ROAR_ERROR_CAUSALITY:
707    errno = ECRAY;
708   break;
709#endif
710#ifdef ENOHORSE
711  case ROAR_ERROR_NOHORSE:
712    errno = ENOHORSE;
713   break;
714#endif
715#ifdef ETXTBSY
716  case ROAR_ERROR_TEXTBUSY:
717    errno = ETXTBSY;
718   break;
719#endif
720#ifdef ENOTEMPTY
721  case ROAR_ERROR_NOTEMPTY:
722    errno = ENOTEMPTY;
723   break;
724#endif
725#ifdef EHOSTUNREACH
726  case ROAR_ERROR_NODEUNREACH:
727    errno = EHOSTUNREACH;
728   break;
729#endif
730#ifdef EIDRM
731  case ROAR_ERROR_IDREMOVED:
732    errno = EIDRM;
733   break;
734#endif
735#ifdef EINPROGRESS
736  case ROAR_ERROR_INPROGRESS:
737    errno = EINPROGRESS;
738   break;
739#endif
740#ifdef ECHILD
741  case ROAR_ERROR_NOCHILD:
742    errno = ECHILD;
743   break;
744#endif
745#ifdef ENETUNREACH
746  case ROAR_ERROR_NETUNREACH:
747    errno = ENETUNREACH;
748   break;
749#endif
750#ifdef ECANCELED
751  case ROAR_ERROR_CANCELED:
752    errno = ECANCELED;
753   break;
754#endif
755#ifdef EISDIR
756  case ROAR_ERROR_ISDIR:
757    errno = EISDIR;
758   break;
759#endif
760#ifdef ENOTDOR
761  case ROAR_ERROR_NOTDIR:
762    errno = ENOTDIR;
763   break;
764#endif
765#ifdef ENOEXEC
766  case ROAR_ERROR_BADEXEC:
767    errno = ENOEXEC;
768   break;
769#endif
770#ifdef EISCONN
771  case ROAR_ERROR_ISCONN:
772    errno = EISCONN;
773   break;
774#endif
775#ifdef EDEADLK
776  case ROAR_ERROR_DEADLOCK:
777    errno = EDEADLK;
778   break;
779#endif
780#ifdef ECONNRESET
781  case ROAR_ERROR_CONNRST:
782    errno = ECONNRESET;
783   break;
784#endif
785#ifdef EBADF
786  case ROAR_ERROR_BADFH:
787    errno = EBADF;
788   break;
789#endif
790#ifdef ENOTSOCK
791  case ROAR_ERROR_NOTSOCK:
792    errno = ENOTSOCK;
793   break;
794#endif
795#ifdef E2BIG
796  case ROAR_ERROR_TOOMANYARGS:
797    errno = E2BIG;
798   break;
799#endif
800#ifdef EFBIG
801  case ROAR_ERROR_TOOLARGE:
802    errno = EFBIG;
803   break;
804#endif
805#ifdef EDESTADDRREQ
806  case ROAR_ERROR_DESTADDRREQ:
807    errno = EDESTADDRREQ;
808   break;
809#endif
810#ifdef EAFNOSUPPORT
811  case ROAR_ERROR_AFNOTSUP:
812    errno = EAFNOSUPPORT;
813   break;
814#endif
815// FIXME....
816#ifdef ENOPOWER
817  case ROAR_ERROR_NOPOWER:
818    errno = ENOPOWER;
819   break;
820#endif
821#ifdef EUSER
822  case ROAR_ERROR_USER:
823    errno = EUSER;
824   break;
825#endif
826
827#ifdef ENFILE
828  case ROAR_ERROR_NFILE:
829    errno = ENFILE;
830   break;
831#endif
832#ifdef ESTALE
833  case ROAR_ERROR_STALE:
834    errno = ESTALE;
835   break;
836#endif
837#ifdef EXDEV
838  case ROAR_ERROR_XDEVLINK:
839    errno = EXDEV;
840   break;
841#endif
842#ifdef EMLINK
843  case ROAR_ERROR_MLINK:
844    errno = EMLINK;
845   break;
846#endif
847#ifdef ENONET
848  case ROAR_ERROR_NONET:
849    errno = ENONET;
850   break;
851#endif
852#ifdef ENETRESET
853  case ROAR_ERROR_CONNRSTNET:
854    errno = ENETRESET;
855   break;
856#endif
857#ifdef ECONNABORTED
858  case ROAR_ERROR_CONNABORTED:
859    errno = ECONNABORTED;
860   break;
861#endif
862
863  default:
864#ifdef EINVAL
865    errno = EINVAL;
866#else
867    errno = -1; // just guess
868#endif
869   break;
870 }
871}
872
873
874// store a error state (both libroar and system)
875int    roar_err_store(struct roar_error_state * state) {
876 if ( state == NULL )
877  return ROAR_ERROR_FAULT;
878
879 memset(state, 0, sizeof(struct roar_error_state));
880
881 state->refc          = 0;
882 state->libroar_error = roar_error;
883 state->system_errno  = errno;
884
885 return ROAR_ERROR_NONE;
886}
887
888// restore error state to values at time of call to roar_err_store()
889int    roar_err_restore(struct roar_error_state * state) {
890 if ( state == NULL )
891  return ROAR_ERROR_FAULT;
892
893 roar_err_set(state->libroar_error);
894 errno = state->system_errno;
895
896 return ROAR_ERROR_NONE;
897}
898
899
900// phi@ph7:roaraudio $ grep '^#define ROAR_ERROR_' error.h  | tr -d /\* | while read d c d t; do printf "  {%-23s \"%s\"},\n" $c, "$t"; done
901
902static const char * roar_error2str_ms(const int error, const char * msg) {
903 static char buf[1024] = "";
904 int num[8];
905 int i;
906 int _ra_err = roar_error;
907 int _sys_err = errno;
908
909 for (i = 0; i < (sizeof(num)/sizeof(*num)); i++)
910  num[i] = roar_random_uint32();
911
912 snprintf(buf, sizeof(buf), "\e[44;39;1m\e[2J\e[H"
913                            "                                   RoarAudio\n"
914                            "\n\n"
915                            "Fatal error %.4x: %s\n"
916                            "RA Error: %.4i, Sys Error: %.4i (%s)\n"
917                            "Random numbers:\n"
918                            " A: 0x%.8X B: 0x%.8X\n"
919                            " C: 0x%.8X D: 0x%.8X\n"
920                            " E: 0x%.8X F: 0x%.8X\n"
921                            " G: 0x%.8X H: 0x%.8X\n"
922                            "\n\n"
923                            "\e[0m",
924                            error, msg,
925                            _ra_err, _sys_err, strerror(_sys_err),
926                            num[0], num[1], num[2], num[3], num[4], num[5], num[6], num[7]);
927
928 return buf;
929}
930
931const char * roar_error2str(const int error) {
932 struct roar_libroar_config * config = roar_libroar_get_config();
933 const struct {
934  const int    err;
935  const char * msg;
936 } msgs[] = {
937  {ROAR_ERROR_NONE,        "No error"},
938  {ROAR_ERROR_PERM,        "Operation not permitted"},
939  {ROAR_ERROR_NOENT,       "No such object, file, directory or node"},
940  {ROAR_ERROR_BADMSG,      "Bad message"},
941  {ROAR_ERROR_BUSY,        "Device or resource busy"},
942  {ROAR_ERROR_CONNREFUSED, "Connection refused"},
943  {ROAR_ERROR_NOSYS,       "Function not implemented"},
944  {ROAR_ERROR_NOTSUP,      "Operation not supported"},
945  {ROAR_ERROR_PIPE,        "Broken pipe"},
946  {ROAR_ERROR_PROTO,       "Protocol error"},
947  {ROAR_ERROR_RANGE,       "Result too large or parameter out of range"},
948  {ROAR_ERROR_MSGSIZE,     "Message too long"},
949  {ROAR_ERROR_NOMEM,       "Not enough space"},
950  {ROAR_ERROR_INVAL,       "Invalid argument"},
951  {ROAR_ERROR_ALREADY,     "Connection already in progress"},
952  {ROAR_ERROR_BADRQC,      "Invalid request code"},
953  {ROAR_ERROR_DOM,         "Mathematics argument out of domain of function"},
954  {ROAR_ERROR_EXIST,       "File or object exists"},
955  {ROAR_ERROR_FAULT,       "Bad address"},
956  {ROAR_ERROR_IO,          "I/O-Error"},
957  {ROAR_ERROR_KEYEXPIRED,  "Key has expired"},
958  {ROAR_ERROR_KEYREJECTED, "Key was rejected by service"},
959  {ROAR_ERROR_LOOP,        "Too many recursions"},
960  {ROAR_ERROR_MFILE,       "Too many open files or objects"},
961  {ROAR_ERROR_NAMETOOLONG, "File or object name too long"},
962  {ROAR_ERROR_NODATA,      "No message is available on the read queue"},
963  {ROAR_ERROR_NODEV,       "No such device"},
964  {ROAR_ERROR_NODRV,       "No such driver"},
965  {ROAR_ERROR_NOSPC,       "No space left on device"},
966  {ROAR_ERROR_TYPEMM,      "Type missmatch. Object of diffrent type required"},
967  {ROAR_ERROR_NORSYS,      "Feature not implemented by remote end"},
968  {ROAR_ERROR_NOTCONN,     "Socket or object not connected"},
969  {ROAR_ERROR_PROTONOSUP,  "Protocol not supported"},
970  {ROAR_ERROR_RIO,         "Remote I/O Error"},
971  {ROAR_ERROR_RO,          "File or object is read only"},
972  {ROAR_ERROR_TIMEDOUT,    "Connection timed out"},
973  {ROAR_ERROR_AGAIN,       "Resource temporarily unavailable"},
974  {ROAR_ERROR_NOISE,       "Line too noisy"},
975  {ROAR_ERROR_LINKDOWN,    "Physical or logical link down"},
976  {ROAR_ERROR_INTERRUPTED, "Operation was interruped"},
977  {ROAR_ERROR_CAUSALITY,   "Causality error"},
978  {ROAR_ERROR_QUOTA,       "Quota exceeded"},
979  {ROAR_ERROR_BADLIB,      "Accessing a corrupted shared library"},
980  {ROAR_ERROR_NOMEDIUM,    "No medium found"},
981  {ROAR_ERROR_NOTUNIQ,     "Name not unique"},
982  {ROAR_ERROR_ILLSEQ,      "Illegal byte sequence"},
983  {ROAR_ERROR_ADDRINUSE,   "Address in use"},
984  {ROAR_ERROR_HOLE,        "Hole in data"},
985  {ROAR_ERROR_BADVERSION,  "Bad version"},
986  {ROAR_ERROR_NSVERSION,   "Not supported version"},
987  {ROAR_ERROR_BADMAGIC,    "Bad magic number"},
988  {ROAR_ERROR_LOSTSYNC,    "Lost synchronization"},
989  {ROAR_ERROR_BADSEEK,     "Can not seek to destination position"},
990  {ROAR_ERROR_NOSEEK,      "Seeking not supported on resource"},
991  {ROAR_ERROR_BADCKSUM,    "Data integrity error"},
992  {ROAR_ERROR_NOHORSE,     "Mount failed"},
993  {ROAR_ERROR_CHERNOBYL,   "Fatal device error"},
994  {ROAR_ERROR_NOHUG,       "Device needs love"},
995  {ROAR_ERROR_TEXTBUSY,    "Text file busy"},
996  {ROAR_ERROR_NOTEMPTY,    "Directory not empty"},
997  {ROAR_ERROR_NODEUNREACH, "Node is unreachable"},
998  {ROAR_ERROR_IDREMOVED,   "Identifier removed"},
999  {ROAR_ERROR_INPROGRESS,  "Operation in progress"},
1000  {ROAR_ERROR_NOCHILD,     "No child processes or object"},
1001  {ROAR_ERROR_NETUNREACH,  "Network unreachable"},
1002  {ROAR_ERROR_CANCELED,    "Operation canceled"},
1003  {ROAR_ERROR_ISDIR,       "Is a directory"},
1004  {ROAR_ERROR_NOTDIR,      "Not a directory"},
1005  {ROAR_ERROR_BADEXEC,     "Executable file format error"},
1006  {ROAR_ERROR_ISCONN,      "Socket or Object is connected"},
1007  {ROAR_ERROR_DEADLOCK,    "Resource deadlock would occur"},
1008  {ROAR_ERROR_CONNRST,     "Connection reset"},
1009  {ROAR_ERROR_BADFH,       "Bad file handle"},
1010  {ROAR_ERROR_NOTSOCK,     "Not a socket"},
1011  {ROAR_ERROR_TOOMANYARGS, "Argument list too long"},
1012  {ROAR_ERROR_TOOLARGE,    "File or Object too large"},
1013  {ROAR_ERROR_DESTADDRREQ, "Destination address required"},
1014  {ROAR_ERROR_AFNOTSUP,    "Address family not supported"},
1015  {ROAR_ERROR_NOPOWER,     "Operation can not be completed because we are low on power"},
1016  {ROAR_ERROR_USER,        "Error in front of screen"},
1017  {ROAR_ERROR_NFILE,       "Too many filesobjects open in system"},
1018  {ROAR_ERROR_STALE,       "Stale file handle or object"},
1019  {ROAR_ERROR_XDEVLINK,    "Cross-device link"},
1020  {ROAR_ERROR_MLINK,       "Too many links to file or object"},
1021  {ROAR_ERROR_NONET,       "Not connected to any network"},
1022  {ROAR_ERROR_CONNRSTNET,  "Connection reset by network"},
1023  {ROAR_ERROR_CONNABORTED, "Connection aborted"},
1024  {-1, NULL}
1025 }, msgs_funny[] = {
1026//  {ROAR_ERROR_UNKNOWN,     "Unknown (maybe no) error"},
1027  {ROAR_ERROR_NONE,        "No error, huh?"},
1028  {ROAR_ERROR_PERM,        "Little kitty is not allowed to do this"},
1029  {ROAR_ERROR_NOENT,       "Mouse not found"},
1030//  {ROAR_ERROR_BADMSG,      "Bad message"},
1031  {ROAR_ERROR_BUSY,        "Another kitty is playing with this mouse"},
1032//  {ROAR_ERROR_CONNREFUSED, "Connection refused"},
1033//  {ROAR_ERROR_NOSYS,       "Function not implemented"},
1034//  {ROAR_ERROR_NOTSUP,      "Operation not supported"},
1035  {ROAR_ERROR_PIPE,        "Flood"},
1036//  {ROAR_ERROR_PROTO,       "Protocol error"},
1037//  {ROAR_ERROR_RANGE,       "Result too largegeneral out of range"},
1038//  {ROAR_ERROR_MSGSIZE,     "Message too long"},
1039//  {ROAR_ERROR_NOMEM,       "Not enough space"},
1040//  {ROAR_ERROR_INVAL,       "Invalid argument"},
1041//  {ROAR_ERROR_ALREADY,     "Connection already in progress"},
1042  {ROAR_ERROR_BADRQC,      "Stupid staff"},
1043//  {ROAR_ERROR_DOM,         "Mathematics argument out of domain of function"},
1044//  {ROAR_ERROR_EXIST,       "File or object exists"},
1045//  {ROAR_ERROR_FAULT,       "Bad address"},
1046//  {ROAR_ERROR_IO,          "IO-Error"},
1047//  {ROAR_ERROR_KEYEXPIRED,  "Key has expired"},
1048//  {ROAR_ERROR_KEYREJECTED, "Key was rejected by service"},
1049//  {ROAR_ERROR_LOOP,        "Too many recursions"},
1050//  {ROAR_ERROR_MFILE,       "Too many open files or objects"},
1051  {ROAR_ERROR_NAMETOOLONG, "Staff can not remember long names"},
1052//  {ROAR_ERROR_NODATA,      "No message is available on the read queue"},
1053  {ROAR_ERROR_NODEV,       "No such mouse"},
1054//  {ROAR_ERROR_NODRV,       "No such driver"},
1055  {ROAR_ERROR_NOSPC,       "Too many fish on desk"},
1056//  {ROAR_ERROR_TYPEMM,      "Type missmatch. Object of diffrent type required"},
1057//  {ROAR_ERROR_NORSYS,      "Feature not implemented by remote end"},
1058//  {ROAR_ERROR_NOTCONN,     "Socket or object not connected"},
1059//  {ROAR_ERROR_PROTONOSUP,  "Protocol not supported"},
1060//  {ROAR_ERROR_RIO,         "Remote IO Error"},
1061  {ROAR_ERROR_RO,          "Touching disallowed"},
1062//  {ROAR_ERROR_TIMEDOUT,    "Connection timed out"},
1063//  {ROAR_ERROR_AGAIN,       "Resource temporarily unavailable"},
1064//  {ROAR_ERROR_NOISE,       "Line too noisy"},
1065//  {ROAR_ERROR_LINKDOWN,    "Physical or logical link down"},
1066//  {ROAR_ERROR_INTERRUPTED, "Operation was interruped"},
1067//  {ROAR_ERROR_CAUSALITY,   "Causality error"},
1068//  {ROAR_ERROR_QUOTA,       "Quota exceeded"},
1069//  {ROAR_ERROR_BADLIB,      "Accessing a corrupted shared library"},
1070//  {ROAR_ERROR_NOMEDIUM,    "No medium found"},
1071//  {ROAR_ERROR_NOTUNIQ,     "Name not unique"},
1072//  {ROAR_ERROR_ILLSEQ,      "Illegal byte sequence"},
1073//  {ROAR_ERROR_ADDRINUSE,   "Address in use"},
1074  {ROAR_ERROR_HOLE,        "Hole in wall"},
1075//  {ROAR_ERROR_BADVERSION,  "Bad version"},
1076//  {ROAR_ERROR_NSVERSION,   "Not supported version"},
1077  {ROAR_ERROR_BADMAGIC,    "Magician's fault"},
1078//  {ROAR_ERROR_LOSTSYNC,    "Lost synchronization"},
1079//  {ROAR_ERROR_BADSEEK,     "Can not seek to destination position"},
1080//  {ROAR_ERROR_NOSEEK,      "Seeking not supported on resource"},
1081//  {ROAR_ERROR_BADCKSUM,    "Data integrity error"},
1082  {ROAR_ERROR_NOHORSE,     "No horse"},
1083//  {ROAR_ERROR_CHERNOBYL,   "Fatal device error"},
1084  {ROAR_ERROR_NOHUG,       "No hug"},
1085//  {ROAR_ERROR_TEXTBUSY,    "Text file busy"},
1086//  {ROAR_ERROR_NOTEMPTY,    "Directory not empty"},
1087//  {ROAR_ERROR_NODEUNREACH, "Node is unreachable"},
1088//  {ROAR_ERROR_IDREMOVED,   "Identifier removed"},
1089//  {ROAR_ERROR_INPROGRESS,  "Operation in progress"},
1090//  {ROAR_ERROR_NOCHILD,     "No child processesobject"},
1091//  {ROAR_ERROR_NETUNREACH,  "Network unreachable"},
1092//  {ROAR_ERROR_CANCELED,    "Operation canceled"},
1093//  {ROAR_ERROR_ISDIR,       "Is a directory"},
1094//  {ROAR_ERROR_NOTDIR,      "Not a directory"},
1095//  {ROAR_ERROR_BADEXEC,     "Executable file format error"},
1096//  {ROAR_ERROR_ISCONN,      "Socket/Object is connected"},
1097  {ROAR_ERROR_DEADLOCK,    "Mouse would die"},
1098//  {ROAR_ERROR_CONNRST,     "Connection reset"},
1099//  {ROAR_ERROR_BADFH,       "Bad file handle"},
1100//  {ROAR_ERROR_NOTSOCK,     "Not a socket"},
1101//  {ROAR_ERROR_TOOMANYARGS, "Argument list too long"},
1102//  {ROAR_ERROR_TOOLARGE,    "File/Object too large"},
1103//  {ROAR_ERROR_DESTADDRREQ, "Destination address required"},
1104//  {ROAR_ERROR_AFNOTSUP,    "Address family not supported"},
1105//  {ROAR_ERROR_NOPOWER,     "Operation can not be completed because we are low on power"},
1106//  {ROAR_ERROR_USER,        "Error in front of screen"},
1107//  {ROAR_ERROR_NFILE,       "Too many filesobjects open in system"},
1108//  {ROAR_ERROR_STALE,       "Stale file handle or object"},
1109  {ROAR_ERROR_XDEVLINK,    "Mice tails too short for kinking"},
1110//  {ROAR_ERROR_MLINK,       "Too many links to file or object"},
1111//  {ROAR_ERROR_NONET,       "Not connected to any network"},
1112//  {ROAR_ERROR_CONNRSTNET,  "Connection reset by network"},
1113//  {ROAR_ERROR_CONNABORTED, "Connection aborted"},
1114  {-1, NULL}
1115 };
1116 int i;
1117
1118 if ( config->opmode == ROAR_LIBROAR_CONFIG_OPMODE_MS )
1119  for (i = 0; msgs[i].msg != NULL; i++)
1120   if ( msgs[i].err == error )
1121    return roar_error2str_ms(error, msgs[i].msg);
1122
1123 if ( config->opmode == ROAR_LIBROAR_CONFIG_OPMODE_FUNNY )
1124  for (i = 0; msgs_funny[i].msg != NULL; i++)
1125   if ( msgs_funny[i].err == error )
1126    return msgs_funny[i].msg;
1127
1128 for (i = 0; msgs[i].msg != NULL; i++)
1129  if ( msgs[i].err == error )
1130   return msgs[i].msg;
1131
1132 return NULL;
1133}
1134
1135//ll
Note: See TracBrowser for help on using the repository browser.