summaryrefslogtreecommitdiffstats
path: root/lib/base/nterrors.cpp
blob: 2eaf29b338d67e80c8d61f53e6dd91ba12cab498 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/** BEGIN COPYRIGHT BLOCK
 * Copyright 2001 Sun Microsystems, Inc.
 * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/
/*
 * nterrors.c: Conversion of error numbers to explanation strings
 * 
 * Aruna Victor 12/6/95
 */


#include <windows.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netsite.h>
#include <base/nterrors.h>
#include <base/nterr.h>

struct _NtHashedError {
	int ErrorNumber;
	char *ErrorString;
	struct _NtHashedError *next;
} ;

typedef struct _NtHashedError NtHashedError;

NtHashedError *hashedNtErrors[200];

#define HASH_ERROR_MODULUS 199
#define DEFAULT_ERROR_STRING "Error Number is unknown"

char *
FindError(int error)
{
    NtHashedError *tmp;

    int hashValue = error % HASH_ERROR_MODULUS;
    tmp = hashedNtErrors[hashValue];

    while(tmp) {
        if (tmp->ErrorNumber == error) {
            return tmp->ErrorString;
        }
        tmp = tmp->next;
    }
    return(DEFAULT_ERROR_STRING);
}

void
EnterError(NtHashedError *error)
{
    NtHashedError *tmp;
    int hashValue;
    int number = 199;

    hashValue = error->ErrorNumber % HASH_ERROR_MODULUS;

     if(!(tmp = hashedNtErrors[hashValue])){
        hashedNtErrors[hashValue] = error;
     } else {
        while(tmp->next) {
            tmp = tmp->next;
        }
        tmp->next = error;
    }
}

void
HashNtErrors()
{
    NtHashedError *error;
    int i = 0;
    
    while(NtErrorStrings[i].ErrorString) {
        error = (NtHashedError *)MALLOC(sizeof(NtHashedError));
        error->ErrorNumber = NtErrorStrings[i].ErrorNumber;
        error->ErrorString = NtErrorStrings[i++].ErrorString;
        error->next = NULL;
        EnterError(error);
    }
}