source: roaraudio/libroar/error.c @ 5147:6493378fc025

Last change on this file since 5147:6493378fc025 was 5147:6493378fc025, checked in by phi, 13 years ago

typo

File size: 24.3 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_clean() ) {
228  roar_err_from_errno();
229 }
230}
231
232int    roar_err_is_errno_clean(void) {
233 return errno == CLEAN_ERRNO ? 1 : 0;
234}
235
236void   roar_err_set(const int error) {
237 *roar_errno2() = error;
238}
239
240void   roar_err_from_errno(void) {
241 int _roar_errno = ROAR_ERROR_NONE;
242
243 switch (errno) {
244#ifdef EACCES
245  case EACCES:       _roar_errno = ROAR_ERROR_PERM; break;
246#endif
247#ifdef EPERM
248  case EPERM:        _roar_errno = ROAR_ERROR_PERM; break;
249#endif
250#ifdef ENOENT
251  case ENOENT:       _roar_errno = ROAR_ERROR_NOENT; break;
252#endif
253#ifdef EBADMSG
254  case EBADMSG:      _roar_errno = ROAR_ERROR_BADMSG; break;
255#endif
256#ifdef EBUSY
257  case EBUSY:        _roar_errno = ROAR_ERROR_BUSY; break;
258#endif
259#ifdef ECONNREFUSED
260  case ECONNREFUSED: _roar_errno = ROAR_ERROR_CONNREFUSED; break;
261#endif
262#ifdef ENOSYS
263  case ENOSYS:       _roar_errno = ROAR_ERROR_NOSYS; break;
264#endif
265#ifdef ENOTSUP
266  case ENOTSUP:      _roar_errno = ROAR_ERROR_NOTSUP; break;
267#endif
268#ifdef EPIPE
269  case EPIPE:        _roar_errno = ROAR_ERROR_PIPE; break;
270#endif
271#ifdef EPROTO
272  case EPROTO:       _roar_errno = ROAR_ERROR_PROTO; break;
273#endif
274#ifdef ERANGE
275  case ERANGE:       _roar_errno = ROAR_ERROR_RANGE; break;
276#endif
277#ifdef EMSGSIZE
278  case EMSGSIZE:     _roar_errno = ROAR_ERROR_MSGSIZE; break;
279#endif
280#ifdef ENOMEM
281  case ENOMEM:       _roar_errno = ROAR_ERROR_NOMEM; break;
282#endif
283#ifdef EINVAL
284  case EINVAL:       _roar_errno = ROAR_ERROR_INVAL; break;
285#endif
286#ifdef EALREADY
287  case EALREADY:     _roar_errno = ROAR_ERROR_ALREADY; break;
288#endif
289#ifdef EBADRQC
290  case EBADRQC:      _roar_errno = ROAR_ERROR_BADRQC; break;
291#endif
292#ifdef EDOM
293  case EDOM:         _roar_errno = ROAR_ERROR_DOM; break;
294#endif
295#ifdef EEXIST
296  case EEXIST:       _roar_errno = ROAR_ERROR_EXIST; break;
297#endif
298#ifdef EFAULT
299  case EFAULT:       _roar_errno = ROAR_ERROR_FAULT; break;
300#endif
301#ifdef EIO
302  case EIO:          _roar_errno = ROAR_ERROR_IO; break;
303#endif
304#ifdef EREMOTEIO
305  case EREMOTEIO:    _roar_errno = ROAR_ERROR_RIO; break;
306#endif
307#ifdef EKEYEXPIRED
308  case EKEYEXPIRED:  _roar_errno = ROAR_ERROR_KEYEXPIRED; break;
309#endif
310#ifdef EKEYREJECTED
311  case EKEYREJECTED: _roar_errno = ROAR_ERROR_KEYREJECTED; break;
312#endif
313#ifdef ELOOP
314  case ELOOP:        _roar_errno = ROAR_ERROR_LOOP; break;
315#endif
316#ifdef EMFILE
317  case EMFILE:       _roar_errno = ROAR_ERROR_MFILE; break;
318#endif
319#ifdef ENAMETOOLONG
320  case ENAMETOOLONG: _roar_errno = ROAR_ERROR_NAMETOOLONG; break;
321#endif
322#ifdef ENODATA
323  case ENODATA:      _roar_errno = ROAR_ERROR_NODATA; break;
324#endif
325#ifdef ENODEV
326  case ENODEV:       _roar_errno = ROAR_ERROR_NODEV; break;
327#endif
328#ifdef ENOSPC
329  case ENOSPC:       _roar_errno = ROAR_ERROR_NOSPC; break;
330#endif
331#ifdef ENOTCONN
332  case ENOTCONN:     _roar_errno = ROAR_ERROR_NOTCONN; break;
333#endif
334#ifdef EPROTONOSUPPORT
335  case EPROTONOSUPPORT: _roar_errno = ROAR_ERROR_PROTONOSUP; break;
336#endif
337#ifdef EROFS
338  case EROFS:        _roar_errno = ROAR_ERROR_RO; break;
339#endif
340#ifdef ETIMEDOUT
341  case ETIMEDOUT:    _roar_errno = ROAR_ERROR_TIMEDOUT; break;
342#endif
343#ifdef EAGAIN
344  case EAGAIN:       _roar_errno = ROAR_ERROR_AGAIN; break;
345#endif
346#ifdef ENETDOWN
347  case ENETDOWN:     _roar_errno = ROAR_ERROR_LINKDOWN; break;
348#endif
349#ifdef EINTR
350  case EINTR:        _roar_errno = ROAR_ERROR_INTERRUPTED; break;
351#endif
352#ifdef EDQUOT
353  case EDQUOT:       _roar_errno = ROAR_ERROR_QUOTA; break;
354#endif
355#ifdef ELIBBAD
356  case ELIBBAD:      _roar_errno = ROAR_ERROR_BADLIB; break;
357#endif
358#ifdef ENOMEDIUM
359  case ENOMEDIUM:    _roar_errno = ROAR_ERROR_NOMEDIUM; break;
360#endif
361#ifdef ENOTUNIQ
362  case ENOTUNIQ:     _roar_errno = ROAR_ERROR_NOTUNIQ; break;
363#endif
364#ifdef EILSEQ
365  case EILSEQ:       _roar_errno = ROAR_ERROR_ILLSEQ; break;
366#endif
367#ifdef EADDRINUSE
368  case EADDRINUSE:   _roar_errno = ROAR_ERROR_ADDRINUSE; break;
369#endif
370#ifdef ESPIPE
371  case ESPIPE:       _roar_errno = ROAR_ERROR_BADSEEK; break;
372#endif
373#ifdef ECHERNOBYL
374  case ECHERNOBYL:   _roar_errno = ROAR_ERROR_CHERNOBYL; break;
375#endif
376#ifdef ECRAY
377  case ECRAY:        _roar_errno = ROAR_ERROR_CAUSALITY; break;
378#endif
379#ifdef ENOHORSE
380  case ENOHORSE:     _roar_errno = ROAR_ERROR_NOHORSE; break;
381#endif
382#ifdef ETXTBSY
383  case ETXTBSY:      _roar_errno = ROAR_ERROR_TEXTBUSY; break;
384#endif
385#ifdef ENOTEMPTY
386  case ENOTEMPTY:    _roar_errno = ROAR_ERROR_NOTEMPTY; break;
387#endif
388#ifdef EHOSTUNREACH
389  case EHOSTUNREACH: _roar_errno = ROAR_ERROR_NODEUNREACH; break;
390#endif
391#ifdef EIDRM
392  case EIDRM:        _roar_errno = ROAR_ERROR_IDREMOVED; break;
393#endif
394#ifdef EINPROGRESS
395  case EINPROGRESS:  _roar_errno = ROAR_ERROR_INPROGRESS; break;
396#endif
397#ifdef ECHILD
398  case ECHILD:       _roar_errno = ROAR_ERROR_NOCHILD; break;
399#endif
400#ifdef ENETUNREACH
401  case ENETUNREACH:  _roar_errno = ROAR_ERROR_NETUNREACH; break;
402#endif
403#ifdef ECANCELED
404  case ECANCELED:    _roar_errno = ROAR_ERROR_CANCELED; break;
405#endif
406#ifdef EISDIR
407  case EISDIR:       _roar_errno = ROAR_ERROR_ISDIR; break;
408#endif
409#ifdef ENOTDIR
410  case ENOTDIR:      _roar_errno = ROAR_ERROR_NOTDIR; break;
411#endif
412#ifdef ENOEXEC
413  case ENOEXEC:      _roar_errno = ROAR_ERROR_BADEXEC; break;
414#endif
415#ifdef EISCONN
416  case EISCONN:      _roar_errno = ROAR_ERROR_ISCONN; break;
417#endif
418#ifdef EDEADLK
419  case EDEADLK:      _roar_errno = ROAR_ERROR_DEADLOCK; break;
420#endif
421#ifdef ECONNRESET
422  case ECONNRESET:   _roar_errno = ROAR_ERROR_CONNRST; break;
423#endif
424#ifdef EBADF
425  case EBADF:        _roar_errno = ROAR_ERROR_BADFH; break;
426#endif
427#ifdef ENOTSOCK
428  case ENOTSOCK:     _roar_errno = ROAR_ERROR_NOTSOCK; break;
429#endif
430#ifdef E2BIG
431  case E2BIG:        _roar_errno = ROAR_ERROR_TOOMANYARGS; break;
432#endif
433#ifdef EFBIG
434  case EFBIG:        _roar_errno = ROAR_ERROR_TOOLARGE; break;
435#endif
436#ifdef EDESTADDRREQ
437  case EDESTADDRREQ: _roar_errno = ROAR_ERROR_DESTADDRREQ; break;
438#endif
439#ifdef EAFNOSUPPORT
440  case EAFNOSUPPORT: _roar_errno = ROAR_ERROR_AFNOTSUP; break;
441#endif
442#ifdef ENFILE
443  case ENFILE:       _roar_errno = ROAR_ERROR_NFILE; break;
444#endif
445#ifdef ESTALE
446  case ESTALE:       _roar_errno = ROAR_ERROR_STALE; break;
447#endif
448#ifdef EXDEV
449  case EXDEV:        _roar_errno = ROAR_ERROR_XDEVLINK; break;
450#endif
451#ifdef EMLINK
452  case EMLINK:       _roar_errno = ROAR_ERROR_MLINK; break;
453#endif
454#ifdef ENONET
455  case ENONET:       _roar_errno = ROAR_ERROR_NONET; break;
456#endif
457#ifdef ENETRESET
458  case ENETRESET:    _roar_errno = ROAR_ERROR_CONNRSTNET; break;
459#endif
460#ifdef ECONNABORTED
461  case ECONNABORTED: _roar_errno = ROAR_ERROR_CONNABORTED; break;
462#endif
463  default:
464    _roar_errno = ROAR_ERROR_UNKNOWN;
465   break;
466 }
467
468 roar_err_set(_roar_errno);
469}
470
471void   roar_err_to_errno(void) {
472 int * err = roar_errno2();
473 switch (*err) {
474  case ROAR_ERROR_NONE:
475    roar_err_clear_errno();
476   break;
477#ifdef EPERM
478  case ROAR_ERROR_PERM:
479    errno = EPERM;
480   break;
481#endif
482#ifdef ENOENT
483  case ROAR_ERROR_NOENT:
484    errno = ENOENT;
485   break;
486#endif
487#ifdef EBADMSG
488  case ROAR_ERROR_BADMSG:
489    errno = EBADMSG;
490   break;
491#endif
492#ifdef EBUSY
493  case ROAR_ERROR_BUSY:
494    errno = EBUSY;
495   break;
496#endif
497#ifdef ECONNREFUSED
498  case ROAR_ERROR_CONNREFUSED:
499    errno = ECONNREFUSED;
500   break;
501#endif
502#ifdef ENOSYS
503  case ROAR_ERROR_NOSYS:
504    errno = ENOSYS;
505   break;
506#endif
507#ifdef ENOTSUP
508  case ROAR_ERROR_NOTSUP:
509    errno = ENOTSUP;
510   break;
511#endif
512#ifdef EPIPE
513  case ROAR_ERROR_PIPE:
514    errno = EPIPE;
515   break;
516#endif
517#ifdef EPROTO
518  case ROAR_ERROR_PROTO:
519    errno = EPROTO;
520   break;
521#endif
522#ifdef ERANGE
523  case ROAR_ERROR_RANGE:
524    errno = ERANGE;
525   break;
526#endif
527#ifdef EMSGSIZE
528  case ROAR_ERROR_MSGSIZE:
529    errno = EMSGSIZE;
530   break;
531#endif
532#ifdef ENOMEM
533  case ROAR_ERROR_NOMEM:
534    errno = ENOMEM;
535   break;
536#endif
537#ifdef EINVAL
538  case ROAR_ERROR_INVAL:
539    errno = EINVAL;
540   break;
541#endif
542#ifdef EALREADY
543  case ROAR_ERROR_ALREADY:
544    errno = EALREADY;
545   break;
546#endif
547#ifdef EBADRQC
548  case ROAR_ERROR_BADRQC:
549    errno = EBADRQC;
550   break;
551#endif
552#ifdef EDOM
553  case ROAR_ERROR_DOM:
554    errno = EDOM;
555   break;
556#endif
557#ifdef EEXIST
558  case ROAR_ERROR_EXIST:
559    errno = EEXIST;
560   break;
561#endif
562#ifdef EFAULT
563  case ROAR_ERROR_FAULT:
564    errno = EFAULT;
565   break;
566#endif
567#if defined(EREMOTEIO) || defined(EIO)
568  case ROAR_ERROR_RIO:
569#ifdef EREMOTEIO
570    errno = EREMOTEIO;
571#else
572    errno = EIO;
573#endif
574   break;
575#endif
576#ifdef EIO
577  case ROAR_ERROR_IO:
578  case ROAR_ERROR_HOLE:
579  case ROAR_ERROR_BADCKSUM:
580  case ROAR_ERROR_LOSTSYNC:
581  case ROAR_ERROR_NOHORSE:
582    errno = EIO;
583   break;
584#endif
585#ifdef EKEYEXPIRED
586  case ROAR_ERROR_KEYEXPIRED:
587    errno = EKEYEXPIRED;
588   break;
589#endif
590#ifdef EKEYREJECTED
591  case ROAR_ERROR_KEYREJECTED:
592    errno = EKEYREJECTED;
593   break;
594#endif
595#ifdef ELOOP
596  case ROAR_ERROR_LOOP:
597    errno = ELOOP;
598   break;
599#endif
600#ifdef EMFILE
601  case ROAR_ERROR_MFILE:
602    errno = EMFILE;
603   break;
604#endif
605#ifdef ENAMETOOLONG
606  case ROAR_ERROR_NAMETOOLONG:
607    errno = ENAMETOOLONG;
608   break;
609#endif
610#ifdef ENODATA
611  case ROAR_ERROR_NODATA:
612    errno = ENODATA;
613   break;
614#endif
615#ifdef ENODEV
616  case ROAR_ERROR_NODEV:
617  case ROAR_ERROR_NODRV:
618    errno = ENODEV;
619   break;
620#endif
621#ifdef ENOSPC
622  case ROAR_ERROR_NOSPC:
623    errno = ENOSPC;
624   break;
625#endif
626#ifdef EINVAL
627  case ROAR_ERROR_TYPEMM:
628    errno = EINVAL;
629   break;
630#endif
631#ifdef ENOSYS
632  case ROAR_ERROR_NORSYS:
633    errno = ENOSYS;
634   break;
635#endif
636#ifdef ENOTCONN
637  case ROAR_ERROR_NOTCONN:
638    errno = ENOTCONN;
639   break;
640#endif
641#ifdef EPROTONOSUPPORT
642  case ROAR_ERROR_PROTONOSUP:
643    errno = EPROTONOSUPPORT;
644   break;
645#endif
646#ifdef EROFS
647  case ROAR_ERROR_RO:
648    errno = EROFS;
649   break;
650#endif
651#ifdef ETIMEDOUT
652  case ROAR_ERROR_TIMEDOUT:
653    errno = ETIMEDOUT;
654   break;
655#endif
656#ifdef EAGAIN
657  case ROAR_ERROR_AGAIN:
658    errno = EAGAIN;
659   break;
660#endif
661#ifdef ENETDOWN
662  case ROAR_ERROR_LINKDOWN:
663    errno = ENETDOWN;
664   break;
665#endif
666#ifdef EINTR
667  case ROAR_ERROR_INTERRUPTED:
668    errno = EINTR;
669   break;
670#endif
671#ifdef EDQUOT
672  case ROAR_ERROR_QUOTA:
673    errno = EDQUOT;
674   break;
675#endif
676#ifdef ELIBBAD
677  case ROAR_ERROR_BADLIB:
678    errno = ELIBBAD;
679   break;
680#endif
681#ifdef ENOMEDIUM
682  case ROAR_ERROR_NOMEDIUM:
683    errno = ENOMEDIUM;
684   break;
685#endif
686#ifdef ENOTUNIQ
687  case ROAR_ERROR_NOTUNIQ:
688    errno = ENOTUNIQ;
689   break;
690#endif
691#ifdef EILSEQ
692  case ROAR_ERROR_ILLSEQ:
693    errno = EILSEQ;
694   break;
695#endif
696#ifdef EADDRINUSE
697  case ROAR_ERROR_ADDRINUSE:
698    errno = EADDRINUSE;
699   break;
700#endif
701#ifdef ESPIPE
702  case ROAR_ERROR_BADSEEK:
703  case ROAR_ERROR_NOSEEK:
704    errno = ESPIPE;
705   break;
706#endif
707#ifdef ECHERNOBYL
708  case ROAR_ERROR_CHERNOBYL:
709    errno = ECHERNOBYL;
710   break;
711#endif
712#ifdef ECRAY
713  case ROAR_ERROR_CAUSALITY:
714    errno = ECRAY;
715   break;
716#endif
717#ifdef ENOHORSE
718  case ROAR_ERROR_NOHORSE:
719    errno = ENOHORSE;
720   break;
721#endif
722#ifdef ETXTBSY
723  case ROAR_ERROR_TEXTBUSY:
724    errno = ETXTBSY;
725   break;
726#endif
727#ifdef ENOTEMPTY
728  case ROAR_ERROR_NOTEMPTY:
729    errno = ENOTEMPTY;
730   break;
731#endif
732#ifdef EHOSTUNREACH
733  case ROAR_ERROR_NODEUNREACH:
734    errno = EHOSTUNREACH;
735   break;
736#endif
737#ifdef EIDRM
738  case ROAR_ERROR_IDREMOVED:
739    errno = EIDRM;
740   break;
741#endif
742#ifdef EINPROGRESS
743  case ROAR_ERROR_INPROGRESS:
744    errno = EINPROGRESS;
745   break;
746#endif
747#ifdef ECHILD
748  case ROAR_ERROR_NOCHILD:
749    errno = ECHILD;
750   break;
751#endif
752#ifdef ENETUNREACH
753  case ROAR_ERROR_NETUNREACH:
754    errno = ENETUNREACH;
755   break;
756#endif
757#ifdef ECANCELED
758  case ROAR_ERROR_CANCELED:
759    errno = ECANCELED;
760   break;
761#endif
762#ifdef EISDIR
763  case ROAR_ERROR_ISDIR:
764    errno = EISDIR;
765   break;
766#endif
767#ifdef ENOTDOR
768  case ROAR_ERROR_NOTDIR:
769    errno = ENOTDIR;
770   break;
771#endif
772#ifdef ENOEXEC
773  case ROAR_ERROR_BADEXEC:
774    errno = ENOEXEC;
775   break;
776#endif
777#ifdef EISCONN
778  case ROAR_ERROR_ISCONN:
779    errno = EISCONN;
780   break;
781#endif
782#ifdef EDEADLK
783  case ROAR_ERROR_DEADLOCK:
784    errno = EDEADLK;
785   break;
786#endif
787#ifdef ECONNRESET
788  case ROAR_ERROR_CONNRST:
789    errno = ECONNRESET;
790   break;
791#endif
792#ifdef EBADF
793  case ROAR_ERROR_BADFH:
794    errno = EBADF;
795   break;
796#endif
797#ifdef ENOTSOCK
798  case ROAR_ERROR_NOTSOCK:
799    errno = ENOTSOCK;
800   break;
801#endif
802#ifdef E2BIG
803  case ROAR_ERROR_TOOMANYARGS:
804    errno = E2BIG;
805   break;
806#endif
807#ifdef EFBIG
808  case ROAR_ERROR_TOOLARGE:
809    errno = EFBIG;
810   break;
811#endif
812#ifdef EDESTADDRREQ
813  case ROAR_ERROR_DESTADDRREQ:
814    errno = EDESTADDRREQ;
815   break;
816#endif
817#ifdef EAFNOSUPPORT
818  case ROAR_ERROR_AFNOTSUP:
819    errno = EAFNOSUPPORT;
820   break;
821#endif
822// FIXME....
823#ifdef ENOPOWER
824  case ROAR_ERROR_NOPOWER:
825    errno = ENOPOWER;
826   break;
827#endif
828#ifdef EUSER
829  case ROAR_ERROR_USER:
830    errno = EUSER;
831   break;
832#endif
833
834#ifdef ENFILE
835  case ROAR_ERROR_NFILE:
836    errno = ENFILE;
837   break;
838#endif
839#ifdef ESTALE
840  case ROAR_ERROR_STALE:
841    errno = ESTALE;
842   break;
843#endif
844#ifdef EXDEV
845  case ROAR_ERROR_XDEVLINK:
846    errno = EXDEV;
847   break;
848#endif
849#ifdef EMLINK
850  case ROAR_ERROR_MLINK:
851    errno = EMLINK;
852   break;
853#endif
854#ifdef ENONET
855  case ROAR_ERROR_NONET:
856    errno = ENONET;
857   break;
858#endif
859#ifdef ENETRESET
860  case ROAR_ERROR_CONNRSTNET:
861    errno = ENETRESET;
862   break;
863#endif
864#ifdef ECONNABORTED
865  case ROAR_ERROR_CONNABORTED:
866    errno = ECONNABORTED;
867   break;
868#endif
869
870  default:
871#ifdef EINVAL
872    errno = EINVAL;
873#else
874    errno = -1; // just guess
875#endif
876   break;
877 }
878}
879
880// 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
881
882const char * roar_error2str(const int error) {
883 const struct {
884  const int    err;
885  const char * msg;
886 } msgs[] = {
887  {ROAR_ERROR_NONE,        "No error"},
888  {ROAR_ERROR_PERM,        "Operation not permitted"},
889  {ROAR_ERROR_NOENT,       "No such object, file or directory"},
890  {ROAR_ERROR_BADMSG,      "Bad message"},
891  {ROAR_ERROR_BUSY,        "Device or resource busy"},
892  {ROAR_ERROR_CONNREFUSED, "Connection refused"},
893  {ROAR_ERROR_NOSYS,       "Function not implemented"},
894  {ROAR_ERROR_NOTSUP,      "Operation not supported"},
895  {ROAR_ERROR_PIPE,        "Broken pipe"},
896  {ROAR_ERROR_PROTO,       "Protocol error"},
897  {ROAR_ERROR_RANGE,       "Result too large or parameter out of range"},
898  {ROAR_ERROR_MSGSIZE,     "Message too long"},
899  {ROAR_ERROR_NOMEM,       "Not enough space"},
900  {ROAR_ERROR_INVAL,       "Invalid argument"},
901  {ROAR_ERROR_ALREADY,     "Connection already in progress"},
902  {ROAR_ERROR_BADRQC,      "Invalid request code"},
903  {ROAR_ERROR_DOM,         "Mathematics argument out of domain of function"},
904  {ROAR_ERROR_EXIST,       "File or object exists"},
905  {ROAR_ERROR_FAULT,       "Bad address"},
906  {ROAR_ERROR_IO,          "I/O-Error"},
907  {ROAR_ERROR_KEYEXPIRED,  "Key has expired"},
908  {ROAR_ERROR_KEYREJECTED, "Key was rejected by service"},
909  {ROAR_ERROR_LOOP,        "Too many recursions"},
910  {ROAR_ERROR_MFILE,       "Too many open files or objects"},
911  {ROAR_ERROR_NAMETOOLONG, "File or object name too long"},
912  {ROAR_ERROR_NODATA,      "No message is available on the read queue"},
913  {ROAR_ERROR_NODEV,       "No such device"},
914  {ROAR_ERROR_NODRV,       "No such driver"},
915  {ROAR_ERROR_NOSPC,       "No space left on device"},
916  {ROAR_ERROR_TYPEMM,      "Type missmatch. Object of diffrent type required"},
917  {ROAR_ERROR_NORSYS,      "Feature not implemented by remote end"},
918  {ROAR_ERROR_NOTCONN,     "Socket or object not connected"},
919  {ROAR_ERROR_PROTONOSUP,  "Protocol not supported"},
920  {ROAR_ERROR_RIO,         "Remote I/O Error"},
921  {ROAR_ERROR_RO,          "File or object is read only"},
922  {ROAR_ERROR_TIMEDOUT,    "Connection timed out"},
923  {ROAR_ERROR_AGAIN,       "Resource temporarily unavailable"},
924  {ROAR_ERROR_NOISE,       "Line too noisy"},
925  {ROAR_ERROR_LINKDOWN,    "Physical or logical link down"},
926  {ROAR_ERROR_INTERRUPTED, "Operation was interruped"},
927  {ROAR_ERROR_CAUSALITY,   "Causality error"},
928  {ROAR_ERROR_QUOTA,       "Quota exceeded"},
929  {ROAR_ERROR_BADLIB,      "Accessing a corrupted shared library"},
930  {ROAR_ERROR_NOMEDIUM,    "No medium found"},
931  {ROAR_ERROR_NOTUNIQ,     "Name not unique"},
932  {ROAR_ERROR_ILLSEQ,      "Illegal byte sequence"},
933  {ROAR_ERROR_ADDRINUSE,   "Address in use"},
934  {ROAR_ERROR_HOLE,        "Hole in data"},
935  {ROAR_ERROR_BADVERSION,  "Bad version"},
936  {ROAR_ERROR_NSVERSION,   "Not supported version"},
937  {ROAR_ERROR_BADMAGIC,    "Bad magic number"},
938  {ROAR_ERROR_LOSTSYNC,    "Lost synchronization"},
939  {ROAR_ERROR_BADSEEK,     "Can not seek to destination position"},
940  {ROAR_ERROR_NOSEEK,      "Seeking not supported on resource"},
941  {ROAR_ERROR_BADCKSUM,    "Data integrity error"},
942  {ROAR_ERROR_NOHORSE,     "Mount failed"},
943  {ROAR_ERROR_CHERNOBYL,   "Fatal device error"},
944  {ROAR_ERROR_NOHUG,       "Device needs love"},
945  {ROAR_ERROR_TEXTBUSY,    "Text file busy"},
946  {ROAR_ERROR_NOTEMPTY,    "Directory not empty"},
947  {ROAR_ERROR_NODEUNREACH, "Node is unreachable"},
948  {ROAR_ERROR_IDREMOVED,   "Identifier removed"},
949  {ROAR_ERROR_INPROGRESS,  "Operation in progress"},
950  {ROAR_ERROR_NOCHILD,     "No child processesobject"},
951  {ROAR_ERROR_NETUNREACH,  "Network unreachable"},
952  {ROAR_ERROR_CANCELED,    "Operation canceled"},
953  {ROAR_ERROR_ISDIR,       "Is a directory"},
954  {ROAR_ERROR_NOTDIR,      "Not a directory"},
955  {ROAR_ERROR_BADEXEC,     "Executable file format error"},
956  {ROAR_ERROR_ISCONN,      "Socket or Object is connected"},
957  {ROAR_ERROR_DEADLOCK,    "Resource deadlock would occur"},
958  {ROAR_ERROR_CONNRST,     "Connection reset"},
959  {ROAR_ERROR_BADFH,       "Bad file handle"},
960  {ROAR_ERROR_NOTSOCK,     "Not a socket"},
961  {ROAR_ERROR_TOOMANYARGS, "Argument list too long"},
962  {ROAR_ERROR_TOOLARGE,    "File or Object too large"},
963  {ROAR_ERROR_DESTADDRREQ, "Destination address required"},
964  {ROAR_ERROR_AFNOTSUP,    "Address family not supported"},
965  {ROAR_ERROR_NOPOWER,     "Operation can not be completed because we are low on power"},
966  {ROAR_ERROR_USER,        "Error in front of screen"},
967  {ROAR_ERROR_NFILE,       "Too many filesobjects open in system"},
968  {ROAR_ERROR_STALE,       "Stale file handle or object"},
969  {ROAR_ERROR_XDEVLINK,    "Cross-device link"},
970  {ROAR_ERROR_MLINK,       "Too many links to file or object"},
971  {ROAR_ERROR_NONET,       "Not connected to any network"},
972  {ROAR_ERROR_CONNRSTNET,  "Connection reset by network"},
973  {ROAR_ERROR_CONNABORTED, "Connection aborted"},
974  {-1, NULL}
975 };
976 int i;
977
978 for (i = 0; msgs[i].msg != NULL; i++)
979  if ( msgs[i].err == error )
980   return msgs[i].msg;
981
982 return NULL;
983}
984
985//ll
Note: See TracBrowser for help on using the repository browser.