Whamcloud - gitweb
ChangeLog, dumpe2fs.8.in, dumpe2fs.c, mke2fs.8.in, mke2fs.c, partinfo.c:
[tools/e2fsprogs.git] / lib / et / et_name.c
1 /*
2  * Copyright 1987 by MIT Student Information Processing Board
3  *
4  * This file may be copied under the terms of the GNU Public License.
5  */
6
7 #include "com_err.h"
8 #include "error_table.h"
9 #include "internal.h"
10
11 static const char char_set[] =
12         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
13
14 static char buf[6];
15
16 const char * error_table_name(num)
17     errcode_t num;
18 {
19     int ch;
20     int i;
21     char *p;
22
23     /* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */
24     p = buf;
25     num >>= ERRCODE_RANGE;
26     /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
27     num &= 077777777L;
28     /* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
29     for (i = 4; i >= 0; i--) {
30         ch = (int)((num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1));
31         if (ch != 0)
32             *p++ = char_set[ch-1];
33     }
34     *p = '\0';
35     return(buf);
36 }