-
Notifications
You must be signed in to change notification settings - Fork 48
/
sihandlemgr.c
120 lines (100 loc) · 2.13 KB
/
sihandlemgr.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "sihandlemgr.h"
#include "utils.h"
#include <string.h>
//句柄链表
typedef struct SiHandleLink
{
struct SiHandleInfo handleinfo;
struct SiHandleLink* next;
};
static struct SiHandleLink* si_handle_link = NULL;
//创建一个SiHandleLink结构
static struct SiHandleLink* SiHandle_Create(HANDLE handle,int u8flag,char* orgfile,char* gbkfile)
{
struct SiHandleLink* tmp = (struct SiHandleLink*)malloc(sizeof(struct SiHandleLink));
memset(tmp,0,sizeof(struct SiHandleLink));
tmp->handleinfo.handle = handle;
tmp->handleinfo.u8flag = u8flag;
strcpy(tmp->handleinfo.orgfile,orgfile);
strcpy(tmp->handleinfo.gbkfile,gbkfile);
return tmp;
}
static void SiHandle_Destory(struct SiHandleLink* node)
{
free(node);
}
//添加到链表
void SiHandle_Add(HANDLE handle,int u8flag,char* orgfile,char* gbkfile)
{
if(handle == INVALID_HANDLE_VALUE)
{
return;
}
struct SiHandleLink* file = SiHandle_Create(handle,u8flag,orgfile,gbkfile);
struct SiHandleLink* tmp = si_handle_link;
if(tmp == NULL)
{
si_handle_link = file;
return;
}
while(tmp->next)
{
tmp = tmp->next;
}
tmp->next = file;
return;
}
//从链表删除
void SiHandle_Del(HANDLE handle)
{
struct SiHandleLink* cur = si_handle_link;
struct SiHandleLink* prev = NULL;
while(cur)
{
if(cur->handleinfo.handle == handle)
{
if(cur == si_handle_link)
{
si_handle_link = si_handle_link->next;
}
else
{
prev->next = cur->next;
}
SiHandle_Destory(cur);
return;
}
prev = cur;
cur = cur->next;
}
return;
}
//调试
void SiHandle_Debug(void)
{
struct SiHandleLink* cur = si_handle_link;
int size = 0;
if(cur == NULL)
{
OutputDebugString("SiHandleLink size=0");
return;
}
while(cur)
{
size++;
cur = cur->next;
}
OutputDebugStringEx("SiHandleLink size=%d",size);
}
//从链表中查找句柄
struct SiHandleInfo* FindSiHandleFromLink(HANDLE handle)
{
struct SiHandleLink* cur = si_handle_link;
while(cur)
{
if(cur->handleinfo.handle == handle)
return &cur->handleinfo;
cur = cur->next;
}
return NULL;
}