Tuesday, 21 August 2018

m_node for keeping simple data structure in the memory

/*
 * File name: m_node.h
 * Author: Seree Rakwong
 * Date: 15-AUG-2018
 *
 * NOTE:
 */
#ifndef __M_NODE_H__
#define __M_NODE_H__

#ifdef __cplusplus
extern "C" {
#endif

struct _NODE;
typedef struct _NODE* node_t;

node_t node_init(const void*, unsigned long);
void   node_release(node_t);

#ifdef __cplusplus
}
#endif

#endif /* __M_NODE_H__ */

/*
 * File name: m_node.c
 * Author: Seree Rakwong
 * Date: 15-AUG-2018
 *
 * NOTE:
 */
#include "m_node.h"
#include <stdlib.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

node_t node_init(const void* vp, unsigned long sz)
{    
    node_t node = 0;

    if (0 == vp || 0 == sz)
    {
        return node;
    }

    node = (node_t)malloc(sz);
    if (node != 0)
    {
        memcpy(node, vp, sz);
    }
    return node;
}

void  node_release(node_t node)
{
    free(node);
}

#ifdef __cplusplus
}
#endif

No comments:

Post a Comment