xref: /freebsd/crypto/krb5/src/util/et/et_name.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 1997 by Massachusetts Institute of Technology
4  *
5  * Copyright 1987 by MIT Student Information Processing Board
6  *
7  * Permission to use, copy, modify, and distribute this software
8  * and its documentation for any purpose and without fee is
9  * hereby granted, provided that the above copyright notice
10  * appear in all copies and that both that copyright notice and
11  * this permission notice appear in supporting documentation,
12  * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
13  * used in advertising or publicity pertaining to distribution
14  * of the software without specific, written prior permission.
15  * Furthermore if you modify this software you must label
16  * your software as modified software and not distribute it in such a
17  * fashion that it might be confused with the original M.I.T. software.
18  * M.I.T. and the M.I.T. S.I.P.B. make no representations about
19  * the suitability of this software for any purpose.  It is
20  * provided "as is" without express or implied warranty.
21  */
22 
23 #include "com_err.h"
24 #include "error_table.h"
25 
26 static const char char_set[] =
27     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
28 
29 const char *
error_table_name_r(unsigned long num,char * outbuf)30 error_table_name_r (unsigned long num,
31                     /*@out@*/ /*@returned@*/ char *outbuf)
32 /*@modifies outbuf@*/
33 {
34     long ch;
35     int i;
36     /*@out@*/ char *p;
37 
38     p = outbuf;
39     num >>= ERRCODE_RANGE;
40 
41     for (i = 3; i >= 0; i--) {
42         ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
43         if (ch != 0)
44             *p++ = char_set[ch-1];
45     }
46     *p = '\0';
47     return(outbuf);
48 }
49 
50 /*@observer@*/
error_table_name(unsigned long num)51 const char * error_table_name(unsigned long num)
52 /*@modifies internalState@*/
53 {
54     static char buf[6];
55 
56     return error_table_name_r(num, buf);
57 }
58