Switch to K&R style indentation.
This commit is contained in:
parent
f75dcef72a
commit
9f38e39463
8 changed files with 771 additions and 787 deletions
177
lib/avl_tree.c
177
lib/avl_tree.c
|
@ -29,7 +29,7 @@
|
|||
library for inclusion into tinc (http://tinc.nl.linux.org/) by
|
||||
Guus Sliepen <guus@sliepen.eu.org>.
|
||||
|
||||
$Id: avl_tree.c,v 1.1.2.9 2002/06/21 10:11:11 guus Exp $
|
||||
$Id: avl_tree.c,v 1.1.2.10 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -56,30 +56,33 @@
|
|||
int lg(unsigned int u)
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
if(!u)
|
||||
return 0;
|
||||
if (u & 0xffff0000)
|
||||
{
|
||||
|
||||
if(u & 0xffff0000) {
|
||||
u >>= 16;
|
||||
r += 16;
|
||||
}
|
||||
if (u & 0x0000ff00)
|
||||
{
|
||||
|
||||
if(u & 0x0000ff00) {
|
||||
u >>= 8;
|
||||
r += 8;
|
||||
}
|
||||
if (u & 0x000000f0)
|
||||
{
|
||||
|
||||
if(u & 0x000000f0) {
|
||||
u >>= 4;
|
||||
r += 4;
|
||||
}
|
||||
if (u & 0x0000000c)
|
||||
{
|
||||
|
||||
if(u & 0x0000000c) {
|
||||
u >>= 2;
|
||||
r += 2;
|
||||
}
|
||||
|
||||
if(u & 0x00000002)
|
||||
r++;
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
@ -90,7 +93,9 @@ int avl_check_balance(avl_node_t *node)
|
|||
{
|
||||
#ifdef AVL_DEPTH
|
||||
int d;
|
||||
|
||||
d = R_AVL_DEPTH(node) - L_AVL_DEPTH(node);
|
||||
|
||||
return d < -1 ? -1 : d > 1 ? 1 : 0;
|
||||
#else
|
||||
/* int d;
|
||||
|
@ -104,8 +109,10 @@ int avl_check_balance(avl_node_t *node)
|
|||
|
||||
if(r >> pl + 1)
|
||||
return 1;
|
||||
|
||||
if(pl < 2 || r >> pl - 2)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
@ -119,25 +126,25 @@ void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
|
|||
|
||||
parent = node;
|
||||
|
||||
while (node)
|
||||
{
|
||||
while(node) {
|
||||
parent = node->parent;
|
||||
|
||||
superparent = parent ? node == parent->left ? &parent->left : &parent->right : &tree->root;
|
||||
superparent =
|
||||
parent ? node ==
|
||||
parent->left ? &parent->left : &parent->right : &tree->root;
|
||||
|
||||
switch (avl_check_balance(node))
|
||||
{
|
||||
switch (avl_check_balance(node)) {
|
||||
case -1:
|
||||
child = node->left;
|
||||
#ifdef AVL_DEPTH
|
||||
if(L_AVL_DEPTH(child) >= R_AVL_DEPTH(child)) {
|
||||
#else
|
||||
if (AVL_L_COUNT(child) >= AVL_R_COUNT(child))
|
||||
{
|
||||
if(AVL_L_COUNT(child) >= AVL_R_COUNT(child)) {
|
||||
#endif
|
||||
node->left = child->right;
|
||||
if(node->left)
|
||||
node->left->parent = node;
|
||||
|
||||
child->right = node;
|
||||
node->parent = child;
|
||||
*superparent = child;
|
||||
|
@ -150,22 +157,26 @@ void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
|
|||
node->depth = AVL_CALC_DEPTH(node);
|
||||
child->depth = AVL_CALC_DEPTH(child);
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
gchild = child->right;
|
||||
node->left = gchild->right;
|
||||
|
||||
if(node->left)
|
||||
node->left->parent = node;
|
||||
child->right = gchild->left;
|
||||
|
||||
if(child->right)
|
||||
child->right->parent = child;
|
||||
gchild->right = node;
|
||||
|
||||
if(gchild->right)
|
||||
gchild->right->parent = gchild;
|
||||
gchild->left = child;
|
||||
|
||||
if(gchild->left)
|
||||
gchild->left->parent = gchild;
|
||||
*superparent = gchild;
|
||||
|
||||
gchild->parent = parent;
|
||||
#ifdef AVL_COUNT
|
||||
node->count = AVL_CALC_COUNT(node);
|
||||
|
@ -179,13 +190,13 @@ void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
|
|||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
child = node->right;
|
||||
#ifdef AVL_DEPTH
|
||||
if(R_AVL_DEPTH(child) >= L_AVL_DEPTH(child)) {
|
||||
#else
|
||||
if (AVL_R_COUNT(child) >= AVL_L_COUNT(child))
|
||||
{
|
||||
if(AVL_R_COUNT(child) >= AVL_L_COUNT(child)) {
|
||||
#endif
|
||||
node->right = child->left;
|
||||
if(node->right)
|
||||
|
@ -202,21 +213,25 @@ void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
|
|||
node->depth = AVL_CALC_DEPTH(node);
|
||||
child->depth = AVL_CALC_DEPTH(child);
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
gchild = child->left;
|
||||
node->right = gchild->left;
|
||||
|
||||
if(node->right)
|
||||
node->right->parent = node;
|
||||
child->left = gchild->right;
|
||||
|
||||
if(child->left)
|
||||
child->left->parent = child;
|
||||
gchild->left = node;
|
||||
|
||||
if(gchild->left)
|
||||
gchild->left->parent = gchild;
|
||||
gchild->right = child;
|
||||
|
||||
if(gchild->right)
|
||||
gchild->right->parent = gchild;
|
||||
|
||||
*superparent = gchild;
|
||||
gchild->parent = parent;
|
||||
#ifdef AVL_COUNT
|
||||
|
@ -231,6 +246,7 @@ void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
|
|||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef AVL_COUNT
|
||||
node->count = AVL_CALC_COUNT(node);
|
||||
|
@ -263,17 +279,14 @@ void avl_free_tree(avl_tree_t *tree)
|
|||
|
||||
avl_node_t *avl_alloc_node(void)
|
||||
{
|
||||
avl_node_t *node;
|
||||
|
||||
node = xmalloc_and_zero(sizeof(avl_node_t));
|
||||
|
||||
return node;
|
||||
return (avl_node_t *)xmalloc_and_zero(sizeof(avl_node_t));
|
||||
}
|
||||
|
||||
void avl_free_node(avl_tree_t * tree, avl_node_t * node)
|
||||
{
|
||||
if(node->data && tree->delete)
|
||||
tree->delete(node->data);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
|
@ -325,48 +338,40 @@ avl_node_t *avl_search_node(const avl_tree_t *tree, const void *data)
|
|||
return result ? NULL : node;
|
||||
}
|
||||
|
||||
avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data, int *result)
|
||||
avl_node_t *avl_search_closest_node(const avl_tree_t * tree, const void *data,
|
||||
int *result)
|
||||
{
|
||||
avl_node_t *node;
|
||||
int c;
|
||||
|
||||
node = tree->root;
|
||||
|
||||
if (!node)
|
||||
{
|
||||
if(!node) {
|
||||
if(result)
|
||||
*result = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for(;;) {
|
||||
c = tree->compare(data, node->data);
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
if(c < 0) {
|
||||
if(node->left)
|
||||
node = node->left;
|
||||
else
|
||||
{
|
||||
else {
|
||||
if(result)
|
||||
*result = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c > 0)
|
||||
{
|
||||
} else if(c > 0) {
|
||||
if(node->right)
|
||||
node = node->right;
|
||||
else
|
||||
{
|
||||
else {
|
||||
if(result)
|
||||
*result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if(result)
|
||||
*result = 0;
|
||||
break;
|
||||
|
@ -376,7 +381,8 @@ avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data, in
|
|||
return node;
|
||||
}
|
||||
|
||||
avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree, const void *data)
|
||||
avl_node_t *avl_search_closest_smaller_node(const avl_tree_t * tree,
|
||||
const void *data)
|
||||
{
|
||||
avl_node_t *node;
|
||||
int result;
|
||||
|
@ -389,7 +395,8 @@ avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree, const void *
|
|||
return node;
|
||||
}
|
||||
|
||||
avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree, const void *data)
|
||||
avl_node_t *avl_search_closest_greater_node(const avl_tree_t * tree,
|
||||
const void *data)
|
||||
{
|
||||
avl_node_t *node;
|
||||
int result;
|
||||
|
@ -409,27 +416,26 @@ avl_node_t *avl_insert(avl_tree_t *tree, void *data)
|
|||
avl_node_t *closest, *new;
|
||||
int result;
|
||||
|
||||
if (!tree->root)
|
||||
{
|
||||
if(!tree->root) {
|
||||
new = avl_alloc_node();
|
||||
new->data = data;
|
||||
avl_insert_top(tree, new);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
closest = avl_search_closest_node(tree, data, &result);
|
||||
switch(result)
|
||||
{
|
||||
|
||||
switch (result) {
|
||||
case -1:
|
||||
new = avl_alloc_node();
|
||||
new->data = data;
|
||||
avl_insert_before(tree, closest, new);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
new = avl_alloc_node();
|
||||
new->data = data;
|
||||
avl_insert_after(tree, closest, new);
|
||||
break;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -452,17 +458,18 @@ avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node)
|
|||
|
||||
if(!tree->root)
|
||||
avl_insert_top(tree, node);
|
||||
else
|
||||
{
|
||||
else {
|
||||
closest = avl_search_closest_node(tree, node->data, &result);
|
||||
switch(result)
|
||||
{
|
||||
|
||||
switch (result) {
|
||||
case -1:
|
||||
avl_insert_before(tree, closest, node);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
avl_insert_after(tree, closest, node);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -484,7 +491,8 @@ void avl_insert_top(avl_tree_t *tree, avl_node_t *node)
|
|||
tree->head = tree->tail = tree->root = node;
|
||||
}
|
||||
|
||||
void avl_insert_before(avl_tree_t *tree, avl_node_t *before, avl_node_t *node)
|
||||
void avl_insert_before(avl_tree_t * tree, avl_node_t * before,
|
||||
avl_node_t * node)
|
||||
{
|
||||
if(!before)
|
||||
return tree->tail ? avl_insert_after(tree, tree->tail, node) : avl_insert_top(tree, node);
|
||||
|
@ -510,7 +518,9 @@ void avl_insert_before(avl_tree_t *tree, avl_node_t *before, avl_node_t *node)
|
|||
void avl_insert_after(avl_tree_t * tree, avl_node_t * after, avl_node_t * node)
|
||||
{
|
||||
if(!after)
|
||||
return tree->head ? avl_insert_before(tree, tree->head, node) : avl_insert_top(tree, node);
|
||||
return tree->head ? avl_insert_before(tree, tree->head,
|
||||
node) : avl_insert_top(tree,
|
||||
node);
|
||||
|
||||
if(after->right)
|
||||
return avl_insert_before(tree, after->next, node);
|
||||
|
@ -560,36 +570,39 @@ void avl_unlink_node(avl_tree_t *tree, avl_node_t *node)
|
|||
|
||||
parent = node->parent;
|
||||
|
||||
superparent = parent ? node == parent->left ? &parent->left : &parent->right : &tree->root;
|
||||
superparent =
|
||||
parent ? node ==
|
||||
parent->left ? &parent->left : &parent->right : &tree->root;
|
||||
|
||||
left = node->left;
|
||||
right = node->right;
|
||||
if (!left)
|
||||
{
|
||||
if(!left) {
|
||||
*superparent = right;
|
||||
|
||||
if(right)
|
||||
right->parent = parent;
|
||||
|
||||
balnode = parent;
|
||||
} else if (!right)
|
||||
{
|
||||
} else if(!right) {
|
||||
*superparent = left;
|
||||
left->parent = parent;
|
||||
balnode = parent;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
subst = node->prev;
|
||||
if (subst == left)
|
||||
{
|
||||
|
||||
if(subst == left) {
|
||||
balnode = subst;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
balnode = subst->parent;
|
||||
balnode->right = subst->left;
|
||||
|
||||
if(balnode->right)
|
||||
balnode->right->parent = balnode;
|
||||
|
||||
subst->left = left;
|
||||
left->parent = subst;
|
||||
}
|
||||
|
||||
subst->right = right;
|
||||
subst->parent = parent;
|
||||
right->parent = subst;
|
||||
|
@ -630,8 +643,7 @@ void avl_delete_tree(avl_tree_t *tree)
|
|||
{
|
||||
avl_node_t *node, *next;
|
||||
|
||||
for(node = tree->root; node; node = next)
|
||||
{
|
||||
for(node = tree->root; node; node = next) {
|
||||
next = node->next;
|
||||
avl_free_node(tree, node);
|
||||
}
|
||||
|
@ -645,8 +657,7 @@ void avl_foreach(avl_tree_t *tree, avl_action_t action)
|
|||
{
|
||||
avl_node_t *node, *next;
|
||||
|
||||
for(node = tree->head; node; node = next)
|
||||
{
|
||||
for(node = tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
action(node->data);
|
||||
}
|
||||
|
@ -656,8 +667,7 @@ void avl_foreach_node(avl_tree_t *tree, avl_action_t action)
|
|||
{
|
||||
avl_node_t *node, *next;
|
||||
|
||||
for(node = tree->head; node; node = next)
|
||||
{
|
||||
for(node = tree->head; node; node = next) {
|
||||
next = node->next;
|
||||
action(node);
|
||||
}
|
||||
|
@ -678,19 +688,15 @@ avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index)
|
|||
|
||||
node = tree->root;
|
||||
|
||||
while (node)
|
||||
{
|
||||
while(node) {
|
||||
c = AVL_L_COUNT(node);
|
||||
|
||||
if (index < c)
|
||||
{
|
||||
if(index < c) {
|
||||
node = node->left;
|
||||
} else if (index > c)
|
||||
{
|
||||
} else if(index > c) {
|
||||
node = node->right;
|
||||
index -= c + 1;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
@ -705,8 +711,7 @@ unsigned int avl_index(const avl_node_t *node)
|
|||
|
||||
index = AVL_L_COUNT(node);
|
||||
|
||||
while ((next = node->parent))
|
||||
{
|
||||
while((next = node->parent)) {
|
||||
if(node == next->right)
|
||||
index += AVL_L_COUNT(next) + 1;
|
||||
node = next;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
library for inclusion into tinc (http://tinc.nl.linux.org/) by
|
||||
Guus Sliepen <guus@sliepen.eu.org>.
|
||||
|
||||
$Id: avl_tree.h,v 1.1.2.5 2002/06/21 10:11:11 guus Exp $
|
||||
$Id: avl_tree.h,v 1.1.2.6 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
|
||||
|
|
31
lib/dropin.c
31
lib/dropin.c
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: dropin.c,v 1.1.2.11 2002/07/12 11:45:21 guus Exp $
|
||||
$Id: dropin.c,v 1.1.2.12 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -57,8 +57,7 @@ int daemon(int nochdir, int noclose)
|
|||
pid = fork();
|
||||
|
||||
/* Check if forking failed */
|
||||
if(pid < 0)
|
||||
{
|
||||
if(pid < 0) {
|
||||
perror("fork");
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -68,31 +67,25 @@ int daemon(int nochdir, int noclose)
|
|||
exit(0);
|
||||
|
||||
/* Detach by becoming the new process group leader */
|
||||
if(setsid() < 0)
|
||||
{
|
||||
if(setsid() < 0) {
|
||||
perror("setsid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Change working directory to the root (to avoid keeping mount
|
||||
points busy) */
|
||||
if(!nochdir)
|
||||
{
|
||||
if(!nochdir) {
|
||||
chdir("/");
|
||||
}
|
||||
|
||||
/* Redirect stdin/out/err to /dev/null */
|
||||
if(!noclose)
|
||||
{
|
||||
if(!noclose) {
|
||||
fd = open("/dev/null", O_RDWR);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
if(fd < 0) {
|
||||
perror("opening /dev/null");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dup2(fd, 0);
|
||||
dup2(fd, 1);
|
||||
dup2(fd, 2);
|
||||
|
@ -103,9 +96,6 @@ int daemon(int nochdir, int noclose)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef HAVE_GET_CURRENT_DIR_NAME
|
||||
/*
|
||||
Replacement for the GNU get_current_dir_name function:
|
||||
|
@ -127,10 +117,10 @@ char *get_current_dir_name(void)
|
|||
|
||||
errno = 0; /* Success */
|
||||
r = getcwd(buf, size);
|
||||
|
||||
/* getcwd returns NULL and sets errno to ERANGE if the bufferspace
|
||||
is insufficient to contain the entire working directory. */
|
||||
while(r == NULL && errno == ERANGE)
|
||||
{
|
||||
while(r == NULL && errno == ERANGE) {
|
||||
free(buf);
|
||||
size <<= 1; /* double the size */
|
||||
buf = xmalloc(size);
|
||||
|
@ -158,8 +148,7 @@ int asprintf(char **buf, const char *fmt, ...)
|
|||
if(status >= 0)
|
||||
*buf = xrealloc(*buf, status);
|
||||
|
||||
if(status > len-1)
|
||||
{
|
||||
if(status > len - 1) {
|
||||
len = status;
|
||||
va_start(ap, fmt);
|
||||
status = vsnprintf(*buf, len, fmt, ap);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: dropin.h,v 1.1.2.8 2002/06/21 10:11:11 guus Exp $
|
||||
$Id: dropin.h,v 1.1.2.9 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __DROPIN_H__
|
||||
|
|
17
lib/list.c
17
lib/list.c
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: list.c,v 1.1.2.11 2002/06/21 10:11:11 guus Exp $
|
||||
$Id: list.c,v 1.1.2.12 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -48,11 +48,7 @@ void list_free(list_t *list)
|
|||
|
||||
list_node_t *list_alloc_node(void)
|
||||
{
|
||||
list_node_t *node;
|
||||
|
||||
node = xmalloc_and_zero(sizeof(list_node_t));
|
||||
|
||||
return node;
|
||||
return (list_node_t *)xmalloc_and_zero(sizeof(list_node_t));
|
||||
}
|
||||
|
||||
void list_free_node(list_t * list, list_node_t * node)
|
||||
|
@ -162,8 +158,7 @@ void list_delete_list(list_t *list)
|
|||
{
|
||||
list_node_t *node, *next;
|
||||
|
||||
for(node = list->head; node; node = next)
|
||||
{
|
||||
for(node = list->head; node; node = next) {
|
||||
next = node->next;
|
||||
list_free_node(list, node);
|
||||
}
|
||||
|
@ -177,8 +172,7 @@ void list_foreach_node(list_t *list, list_action_node_t action)
|
|||
{
|
||||
list_node_t *node, *next;
|
||||
|
||||
for(node = list->head; node; node = next)
|
||||
{
|
||||
for(node = list->head; node; node = next) {
|
||||
next = node->next;
|
||||
action(node);
|
||||
}
|
||||
|
@ -188,8 +182,7 @@ void list_foreach(list_t *list, list_action_t action)
|
|||
{
|
||||
list_node_t *node, *next;
|
||||
|
||||
for(node = list->head; node; node = next)
|
||||
{
|
||||
for(node = list->head; node; node = next) {
|
||||
next = node->next;
|
||||
if(node->data)
|
||||
action(node->data);
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: list.h,v 1.1.2.6 2002/06/21 10:11:11 guus Exp $
|
||||
$Id: list.h,v 1.1.2.7 2002/09/09 21:49:16 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_LIST_H__
|
||||
#define __TINC_LIST_H__
|
||||
|
||||
typedef struct list_node_t
|
||||
{
|
||||
typedef struct list_node_t {
|
||||
struct list_node_t *prev;
|
||||
struct list_node_t *next;
|
||||
|
||||
|
@ -36,8 +35,7 @@ typedef struct list_node_t
|
|||
typedef void (*list_action_t) (const void *);
|
||||
typedef void (*list_action_node_t) (const list_node_t *);
|
||||
|
||||
typedef struct list_t
|
||||
{
|
||||
typedef struct list_t {
|
||||
list_node_t *head;
|
||||
list_node_t *tail;
|
||||
int count;
|
||||
|
|
|
@ -55,8 +55,7 @@ void hex2bin(char *src, char *dst, int length)
|
|||
void bin2hex(char *src, char *dst, int length)
|
||||
{
|
||||
int i;
|
||||
for(i=length-1; i>=0; i--)
|
||||
{
|
||||
for(i = length - 1; i >= 0; i--) {
|
||||
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
|
||||
dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue