summaryrefslogtreecommitdiffstats
path: root/src/gen-errno.sh
blob: f9a81da28f58259cf75dff71c5ed128fb84f136d (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
#!/bin/sh

includes="/usr/include/errno.h"
if [ -f /usr/include/sys/errno.h ]; then
  includes="$includes /usr/include/sys/errno.h"
fi
if [ -f /usr/include/asm-generic/errno.h ]; then
  includes="$includes /usr/include/asm-generic/errno.h"
fi
if [ -f /usr/include/asm-generic/errno-base.h ]; then
  includes="$includes /usr/include/asm-generic/errno-base.h"
fi

echo 'const char* core_log_errstr(int err)
{
    switch (err) {'

egrep -Eh '^#define[	 ]+E\w+[	 ]+[0-9]+' $includes |
  grep -v ELAST |
  awk '{print $2}' |
  sort -u |
  awk '{print "#ifdef " $1 "\n    case " $1 ":\n        return \"" $1 "\";\n#endif"}'

echo '    default:
        break;
    }
    return "UNKNOWN";
}'