source: roaraudio/libroar/error.c @ 5119:66203ccc8f12

Last change on this file since 5119:66203ccc8f12 was 5097:9d74ce71fcdd, checked in by phi, 13 years ago

text corrections

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