summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libdl/dlerror.c
blob: 3fea0b75c2791749b7852075ca7e93d3a2c0008d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#include "_dl_int.h"

#ifdef __DIET_LD_SO__
static unsigned int _dl_error;
static const char*_dl_error_location;
static const char*_dl_error_data;
#else
#include <string.h>
unsigned int _dl_error;
const char*_dl_error_location;
const char*_dl_error_data;
#endif

static struct _dl_err_msg {
  char*msg;
  int len;
} _dl_error_msg[]={
#define MSG(n) { (n), sizeof((n))-1 }
  MSG("can't open: "),					/* 1 */
  MSG("can't stat: "),					/* 2 */
  MSG("shared object is not position independent: "),	/* 3 */
  MSG("can't resolve all symbols in: "),		/* 4 */
  MSG("can't find symbol: "),				/* 5 */
  MSG("invalid relocation type in: "),			/* 6 */
  MSG("internal error: layout not yet supported: "),	/* 7 */
};

const char *dlerror(void) {
  static char buf[1024],*p=buf;
  register int l,len=sizeof(buf)-1;
  if (_dl_error==0) return 0;

  buf[0]=0;
  buf[len]=0;
  --_dl_error;

  if (_dl_error>=(sizeof(_dl_error_msg)/sizeof(struct _dl_err_msg)))
    return "HAE ?!?";

  if (_dl_error_location) {
    l=strlen(_dl_error_location);
    strncpy(p,_dl_error_location,len); len-=l; p+=l;
    strncpy(p,": ",len); len-=2; p+=2;
  }
  l=_dl_error_msg[_dl_error].len;
  strncpy(p,_dl_error_msg[_dl_error].msg,len); len-=l; p+=l;
  strncpy(p,_dl_error_data,len);

  _dl_error_location=0;
  _dl_error_data="";
  _dl_error=0;

  return buf;
}