source: roaraudio/libroar/error.c @ 5183:41993c72f4d3

Last change on this file since 5183:41993c72f4d3 was 5183:41993c72f4d3, checked in by phi, 12 years ago

added opmode option

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