forked from heiher/hev-socks5-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
============================================================================ | ||
Name : hev-list.c | ||
Authors : Heiher <[email protected]> | ||
Copyright : Copyright (c) 2019 everyone. | ||
Description : Double-linked List | ||
============================================================================ | ||
*/ | ||
|
||
#include <stddef.h> | ||
|
||
#include "hev-list.h" | ||
|
||
void | ||
hev_list_add_tail (HevList *self, HevListNode *new_) | ||
{ | ||
new_->prev = self->tail; | ||
new_->next = NULL; | ||
|
||
if (self->tail) | ||
self->tail->next = new_; | ||
else | ||
self->head = new_; | ||
self->tail = new_; | ||
} | ||
|
||
void | ||
hev_list_del (HevList *self, HevListNode *node) | ||
{ | ||
if (node->prev) | ||
node->prev->next = node->next; | ||
else | ||
self->head = node->next; | ||
|
||
if (node->next) | ||
node->next->prev = node->prev; | ||
else | ||
self->tail = node->prev; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
============================================================================ | ||
Name : hev-list.h | ||
Authors : Heiher <[email protected]> | ||
Copyright : Copyright (c) 2019 everyone. | ||
Description : Double-linked List | ||
============================================================================ | ||
*/ | ||
|
||
#ifndef __HEV_LIST_H__ | ||
#define __HEV_LIST_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct _HevList HevList; | ||
typedef struct _HevListNode HevListNode; | ||
|
||
struct _HevList | ||
{ | ||
HevListNode *head; | ||
HevListNode *tail; | ||
}; | ||
|
||
struct _HevListNode | ||
{ | ||
HevListNode *next; | ||
HevListNode *prev; | ||
}; | ||
|
||
static inline HevListNode * | ||
hev_list_node_prev (HevListNode *node) | ||
{ | ||
return node->prev; | ||
} | ||
|
||
static inline HevListNode * | ||
hev_list_node_next (HevListNode *node) | ||
{ | ||
return node->next; | ||
} | ||
|
||
static inline HevListNode * | ||
hev_list_first (HevList *self) | ||
{ | ||
return self->head; | ||
} | ||
|
||
static inline HevListNode * | ||
hev_list_last (HevList *self) | ||
{ | ||
return self->tail; | ||
} | ||
|
||
void hev_list_add_tail (HevList *self, HevListNode *new_); | ||
void hev_list_del (HevList *self, HevListNode *node); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __HEV_LIST_H__ */ |