mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-14 19:59:48 +00:00
remove files
This commit is contained in:
425
czmod/czmod.c
425
czmod/czmod.c
@@ -1,425 +0,0 @@
|
||||
//=====================================================================
|
||||
//
|
||||
// czmod.c - c module to boost z.lua
|
||||
//
|
||||
// Created by skywind on 2020/03/11
|
||||
// Last Modified: 2020/03/11 16:37:01
|
||||
//
|
||||
//=====================================================================
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
|
||||
#include <windows.h>
|
||||
#elif defined(__linux)
|
||||
// #include <linux/limits.h>
|
||||
#include <limits.h>
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#define IB_STRING_SSO 256
|
||||
|
||||
#include "iposix.c"
|
||||
#include "imembase.c"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// INLINE
|
||||
//----------------------------------------------------------------------
|
||||
#ifndef INLINE
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
|
||||
#define INLINE __inline__ __attribute__((always_inline))
|
||||
#else
|
||||
#define INLINE __inline__
|
||||
#endif
|
||||
|
||||
#elif (defined(_MSC_VER) || defined(__WATCOMC__))
|
||||
#define INLINE __inline
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (!defined(__cplusplus)) && (!defined(inline))
|
||||
#define inline INLINE
|
||||
#endif
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// internal functions
|
||||
//---------------------------------------------------------------------
|
||||
static const char *get_data_file(void);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// get environ
|
||||
//---------------------------------------------------------------------
|
||||
static ib_string* os_getenv(const char *name)
|
||||
{
|
||||
char *p = getenv(name);
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ib_string *text = ib_string_new();
|
||||
ib_string_assign(text, p);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// get data file
|
||||
//---------------------------------------------------------------------
|
||||
static const char *get_data_file(void)
|
||||
{
|
||||
static ib_string *text = NULL;
|
||||
if (text != NULL) {
|
||||
return text->ptr;
|
||||
}
|
||||
text = os_getenv("_ZL_DATA2");
|
||||
if (text) {
|
||||
return text->ptr;
|
||||
}
|
||||
text = os_getenv("HOME");
|
||||
if (text == NULL) {
|
||||
text = os_getenv("USERPROFILE");
|
||||
}
|
||||
if (text == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ib_string_append(text, "/.zlua");
|
||||
return text->ptr;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// load file content
|
||||
//---------------------------------------------------------------------
|
||||
ib_string *load_content(const char *filename)
|
||||
{
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
int fd = fileno(fp);
|
||||
flock(fd, LOCK_SH);
|
||||
ib_string *text = ib_string_new();
|
||||
size_t block = 65536;
|
||||
ib_string_resize(text, block);
|
||||
size_t pos = 0;
|
||||
while (feof(fp) == 0) {
|
||||
size_t avail = text->size - pos;
|
||||
if (avail < block) {
|
||||
ib_string_resize(text, text->size + block);
|
||||
avail = text->size - pos;
|
||||
}
|
||||
size_t hr = fread(&(text->ptr[pos]), 1, avail, fp);
|
||||
pos += hr;
|
||||
}
|
||||
flock(fd, LOCK_UN);
|
||||
fclose(fp);
|
||||
ib_string_resize(text, pos);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// path item
|
||||
//---------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
ib_string *path;
|
||||
int rank;
|
||||
uint32_t timestamp;
|
||||
uint64_t frecence;
|
||||
} PathItem;
|
||||
|
||||
static void item_delete(PathItem *item)
|
||||
{
|
||||
if (item) {
|
||||
if (item->path) {
|
||||
ib_string_delete(item->path);
|
||||
item->path = NULL;
|
||||
}
|
||||
ikmem_free(item);
|
||||
}
|
||||
};
|
||||
|
||||
PathItem* item_new(const char *path, int rank, uint32_t timestamp)
|
||||
{
|
||||
PathItem* item = (PathItem*)ikmem_malloc(sizeof(PathItem));
|
||||
assert(item);
|
||||
item->path = ib_string_new_from(path);
|
||||
item->rank = rank;
|
||||
item->timestamp = timestamp;
|
||||
item->frecence = 0;
|
||||
return item;
|
||||
};
|
||||
|
||||
ib_array* ib_array_new_items(void)
|
||||
{
|
||||
return ib_array_new((void (*)(void*))item_delete);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// load data
|
||||
//---------------------------------------------------------------------
|
||||
ib_array* data_load(const char *filename)
|
||||
{
|
||||
ib_string *content = load_content(filename);
|
||||
if (content == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
ib_array *lines = ib_string_split_c(content, '\n');
|
||||
int size = ib_array_size(lines);
|
||||
int i;
|
||||
ib_array *items = ib_array_new_items();
|
||||
for (i = 0; i < size; i++) {
|
||||
ib_string *text = (ib_string*)ib_array_index(lines, i);
|
||||
int p1 = ib_string_find_c(text, '|', 0);
|
||||
if (p1 >= 0) {
|
||||
int p2 = ib_string_find_c(text, '|', p1 + 1);
|
||||
if (p2 >= 0) {
|
||||
uint32_t timestamp;
|
||||
int rank;
|
||||
text->ptr[p1] = 0;
|
||||
text->ptr[p2] = 0;
|
||||
rank = (int)atoi(text->ptr + p1 + 1);
|
||||
timestamp = (uint32_t)strtoul(text->ptr + p2 + 1, NULL, 10);
|
||||
PathItem *ni = item_new(text->ptr, rank, timestamp);
|
||||
ib_array_push(items, ni);
|
||||
}
|
||||
}
|
||||
}
|
||||
ib_array_delete(lines);
|
||||
return items;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// save data
|
||||
//---------------------------------------------------------------------
|
||||
void data_save(const char *filename, ib_array *items)
|
||||
{
|
||||
ib_string *tmpname = ib_string_new_from(filename);
|
||||
FILE *fp;
|
||||
while (1) {
|
||||
char tmp[100];
|
||||
ib_string_assign(tmpname, filename);
|
||||
sprintf(tmp, ".%u%03u%d", (uint32_t)time(NULL),
|
||||
(uint32_t)(clock() % 1000), rand() % 10000);
|
||||
ib_string_append(tmpname, tmp);
|
||||
if (iposix_path_isdir(tmpname->ptr) < 0) break;
|
||||
}
|
||||
fp = fopen(tmpname->ptr, "w");
|
||||
if (fp) {
|
||||
int size = ib_array_size(items);
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
PathItem *item = (PathItem*)ib_array_index(items, i);
|
||||
fprintf(fp, "%s|%u|%u\n",
|
||||
item->path->ptr, item->rank, item->timestamp);
|
||||
}
|
||||
fclose(fp);
|
||||
#ifdef _WIN32
|
||||
ReplaceFileA(filename, tmpname->ptr, NULL, 2, NULL, NULL);
|
||||
#else
|
||||
rename(tmpname->ptr, filename);
|
||||
#endif
|
||||
}
|
||||
ib_string_delete(tmpname);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// save data
|
||||
//---------------------------------------------------------------------
|
||||
void data_write(const char *filename, ib_array *items)
|
||||
{
|
||||
FILE *fp;
|
||||
int fd;
|
||||
fp = fopen(filename, "w+");
|
||||
if (fp) {
|
||||
int size = ib_array_size(items);
|
||||
int i;
|
||||
fd = fileno(fp);
|
||||
flock(fd, LOCK_EX);
|
||||
for (i = 0; i < size; i++) {
|
||||
PathItem *item = (PathItem*)ib_array_index(items, i);
|
||||
fprintf(fp, "%s|%u|%u\n",
|
||||
item->path->ptr, item->rank, item->timestamp);
|
||||
}
|
||||
fflush(fp);
|
||||
flock(fd, LOCK_UN);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// insert data
|
||||
//---------------------------------------------------------------------
|
||||
void data_add(ib_array *items, const char *path)
|
||||
{
|
||||
ib_string *target = ib_string_new_from(path);
|
||||
int i = 0, size, found = 0;
|
||||
#if defined(_WIN32)
|
||||
for (i = 0; i < target->size; i++) {
|
||||
if (target->ptr[i] == '/') target->ptr[i] = '\\';
|
||||
else {
|
||||
target->ptr[i] = (char)tolower(target->ptr[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
size = ib_array_size(items);
|
||||
for (i = 0; i < size; i++) {
|
||||
PathItem *item = (PathItem*)ib_array_index(items, i);
|
||||
int equal = 0;
|
||||
#if defined(_WIN32)
|
||||
if (item->path->size == target->size) {
|
||||
char *src = item->path->ptr;
|
||||
char *dst = target->ptr;
|
||||
int avail = target->size;
|
||||
for (; avail > 0; src++, dst++, avail--) {
|
||||
if (tolower(src[0]) != dst[0]) break;
|
||||
}
|
||||
equal = (avail == 0)? 1 : 0;
|
||||
}
|
||||
#else
|
||||
if (ib_string_compare(item->path, target) == 0) {
|
||||
equal = 1;
|
||||
}
|
||||
#endif
|
||||
if (equal) {
|
||||
found = 1;
|
||||
item->rank++;
|
||||
item->timestamp = (uint32_t)time(NULL);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
PathItem *ni = item_new(target->ptr, 1, (uint32_t)time(NULL));
|
||||
ib_array_push(items, ni);
|
||||
}
|
||||
ib_string_delete(target);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//
|
||||
//---------------------------------------------------------------------
|
||||
void z_insert(const char *newpath)
|
||||
{
|
||||
static char tmpname[PATH_MAX + 10];
|
||||
static char text[PATH_MAX + 100];
|
||||
const char *data = "/home/skywind/.zlua";
|
||||
FILE *fin = fopen(data, "r");
|
||||
FILE *fout;
|
||||
#if 0
|
||||
while (1) {
|
||||
char tmp[100];
|
||||
sprintf(tmp, ".%u%03u%d", (uint32_t)time(NULL),
|
||||
(uint32_t)(clock() % 1000), rand() % 10000);
|
||||
sprintf(tmpname, "%s%s", data, tmp);
|
||||
if (iposix_path_isdir(tmpname) < 0) break;
|
||||
}
|
||||
#else
|
||||
sprintf(tmpname, "%s.1", data);
|
||||
#endif
|
||||
fout = fopen(tmpname, "w");
|
||||
if (fin) {
|
||||
int found = 0;
|
||||
while (!feof(fin)) {
|
||||
uint32_t rank, ts;
|
||||
text[0] = 0;
|
||||
fgets(text, PATH_MAX + 100, fin);
|
||||
char *p1 = strchr(text, '|');
|
||||
if (p1 == NULL) continue;
|
||||
*p1++ = 0;
|
||||
char *p2 = strchr(p1, '|');
|
||||
if (p2 == NULL) continue;
|
||||
*p2++ = 0;
|
||||
if (strcmp(text, newpath) == 0) {
|
||||
found = 1;
|
||||
sscanf(p1, "%u", &rank);
|
||||
sscanf(p2, "%u", &ts);
|
||||
rank++;
|
||||
ts = (uint32_t)time(NULL);
|
||||
fprintf(fout, "%s|%u|%u\n", text, rank, ts);
|
||||
}
|
||||
else {
|
||||
fprintf(fout, "%s|%s|%s\n", text, p1, p2);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fprintf(fout, "%s|1|%u\n", newpath, (uint32_t)time(NULL));
|
||||
}
|
||||
fclose(fin);
|
||||
}
|
||||
else {
|
||||
fprintf(fout, "%s|1|%u\n", newpath, (uint32_t)time(NULL));
|
||||
}
|
||||
fclose(fout);
|
||||
rename(tmpname, data);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// add to database
|
||||
//---------------------------------------------------------------------
|
||||
void z_add(const char *newpath)
|
||||
{
|
||||
const char *data = get_data_file();
|
||||
ib_array *items = data_load(data);
|
||||
if (items == NULL) {
|
||||
items = ib_array_new_items();
|
||||
}
|
||||
data_add(items, newpath);
|
||||
#if 0
|
||||
data_save(data, items);
|
||||
#else
|
||||
data_write(data, items);
|
||||
#endif
|
||||
ib_array_delete(items);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// main entry
|
||||
//---------------------------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 1) {
|
||||
int i;
|
||||
printf("begin\n");
|
||||
clock_t ts = (uint64_t)clock();
|
||||
for (i = 0; i < 1000; i++) {
|
||||
// z_add("/tmp");
|
||||
z_insert("/tmp");
|
||||
}
|
||||
ts = clock() - ts;
|
||||
ts = (ts * 1000) / CLOCKS_PER_SEC;
|
||||
printf("finished: %d ms\n", (int)ts);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[1], "--add") == 0) {
|
||||
if (argc >= 3) {
|
||||
#if 1
|
||||
z_add(argv[2]);
|
||||
#else
|
||||
z_insert(argv[2]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
2320
czmod/imembase.c
2320
czmod/imembase.c
File diff suppressed because it is too large
Load Diff
916
czmod/imembase.h
916
czmod/imembase.h
@@ -1,916 +0,0 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* imembase.h - basic interface of memory operation
|
||||
* skywind3000 (at) gmail.com, 2006-2016
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __IMEMBASE_H__
|
||||
#define __IMEMBASE_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* 32BIT INTEGER DEFINITION
|
||||
**********************************************************************/
|
||||
#ifndef __INTEGER_32_BITS__
|
||||
#define __INTEGER_32_BITS__
|
||||
#if defined(__UINT32_TYPE__) && defined(__UINT32_TYPE__)
|
||||
typedef __UINT32_TYPE__ ISTDUINT32;
|
||||
typedef __INT32_TYPE__ ISTDINT32;
|
||||
#elif defined(__UINT_FAST32_TYPE__) && defined(__INT_FAST32_TYPE__)
|
||||
typedef __UINT_FAST32_TYPE__ ISTDUINT32;
|
||||
typedef __INT_FAST32_TYPE__ ISTDINT32;
|
||||
#elif defined(_WIN64) || defined(WIN64) || defined(__amd64__) || \
|
||||
defined(__x86_64) || defined(__x86_64__) || defined(_M_IA64) || \
|
||||
defined(_M_AMD64)
|
||||
typedef unsigned int ISTDUINT32;
|
||||
typedef int ISTDINT32;
|
||||
#elif defined(_WIN32) || defined(WIN32) || defined(__i386__) || \
|
||||
defined(__i386) || defined(_M_X86)
|
||||
typedef unsigned long ISTDUINT32;
|
||||
typedef long ISTDINT32;
|
||||
#elif defined(__MACOS__)
|
||||
typedef UInt32 ISTDUINT32;
|
||||
typedef SInt32 ISTDINT32;
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
#include <sys/types.h>
|
||||
typedef u_int32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#elif defined(__BEOS__)
|
||||
#include <sys/inttypes.h>
|
||||
typedef u_int32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#elif (defined(_MSC_VER) || defined(__BORLANDC__)) && (!defined(__MSDOS__))
|
||||
typedef unsigned __int32 ISTDUINT32;
|
||||
typedef __int32 ISTDINT32;
|
||||
#elif defined(__GNUC__) && (__GNUC__ > 3)
|
||||
#include <stdint.h>
|
||||
typedef uint32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#else
|
||||
#include <limits.h>
|
||||
#if UINT_MAX == 0xFFFFU
|
||||
typedef unsigned long ISTDUINT32;
|
||||
typedef long ISTDINT32;
|
||||
#else
|
||||
typedef unsigned int ISTDUINT32;
|
||||
typedef int ISTDINT32;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Global Macros
|
||||
**********************************************************************/
|
||||
#ifndef __IUINT8_DEFINED
|
||||
#define __IUINT8_DEFINED
|
||||
typedef unsigned char IUINT8;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT8_DEFINED
|
||||
#define __IINT8_DEFINED
|
||||
typedef signed char IINT8;
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT16_DEFINED
|
||||
#define __IUINT16_DEFINED
|
||||
typedef unsigned short IUINT16;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT16_DEFINED
|
||||
#define __IINT16_DEFINED
|
||||
typedef signed short IINT16;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT32_DEFINED
|
||||
#define __IINT32_DEFINED
|
||||
typedef ISTDINT32 IINT32;
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT32_DEFINED
|
||||
#define __IUINT32_DEFINED
|
||||
typedef ISTDUINT32 IUINT32;
|
||||
#endif
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* INLINE */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#ifndef INLINE
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
|
||||
#define INLINE __inline__ __attribute__((always_inline))
|
||||
#else
|
||||
#define INLINE __inline__
|
||||
#endif
|
||||
|
||||
#elif (defined(_MSC_VER) || defined(__WATCOMC__))
|
||||
#define INLINE __inline
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (!defined(__cplusplus)) && (!defined(inline))
|
||||
#define inline INLINE
|
||||
#endif
|
||||
|
||||
/* you can change this by config.h or predefined macro */
|
||||
#ifndef ASSERTION
|
||||
#define ASSERTION(x) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IULONG/ILONG (ensure sizeof(iulong) == sizeof(void*)) */
|
||||
/*====================================================================*/
|
||||
#ifndef __IULONG_DEFINED
|
||||
#define __IULONG_DEFINED
|
||||
typedef ptrdiff_t ilong;
|
||||
typedef size_t iulong;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IALLOCATOR */
|
||||
/*====================================================================*/
|
||||
struct IALLOCATOR
|
||||
{
|
||||
void *(*alloc)(struct IALLOCATOR *, size_t);
|
||||
void (*free)(struct IALLOCATOR *, void *);
|
||||
void *(*realloc)(struct IALLOCATOR *, void *, size_t);
|
||||
void *udata;
|
||||
};
|
||||
|
||||
void* internal_malloc(struct IALLOCATOR *allocator, size_t size);
|
||||
void internal_free(struct IALLOCATOR *allocator, void *ptr);
|
||||
void* internal_realloc(struct IALLOCATOR *allocator, void *ptr, size_t size);
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IKMEM INTERFACE */
|
||||
/*====================================================================*/
|
||||
extern struct IALLOCATOR *ikmem_allocator;
|
||||
|
||||
void* ikmem_malloc(size_t size);
|
||||
void* ikmem_realloc(void *ptr, size_t size);
|
||||
void ikmem_free(void *ptr);
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IVECTOR */
|
||||
/*====================================================================*/
|
||||
struct IVECTOR
|
||||
{
|
||||
unsigned char *data;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
struct IALLOCATOR *allocator;
|
||||
};
|
||||
|
||||
void iv_init(struct IVECTOR *v, struct IALLOCATOR *allocator);
|
||||
void iv_destroy(struct IVECTOR *v);
|
||||
int iv_resize(struct IVECTOR *v, size_t newsize);
|
||||
int iv_reserve(struct IVECTOR *v, size_t newsize);
|
||||
|
||||
size_t iv_pop(struct IVECTOR *v, void *data, size_t size);
|
||||
int iv_push(struct IVECTOR *v, const void *data, size_t size);
|
||||
int iv_insert(struct IVECTOR *v, size_t pos, const void *data, size_t size);
|
||||
int iv_erase(struct IVECTOR *v, size_t pos, size_t size);
|
||||
|
||||
#define iv_size(v) ((v)->size)
|
||||
#define iv_data(v) ((v)->data)
|
||||
|
||||
#define iv_entry(v, type) ((type*)iv_data(v))
|
||||
|
||||
#define iv_obj_index(v, type, index) (iv_entry(v, type)[index])
|
||||
#define iv_obj_push(v, type, objptr) iv_push(v, objptr, sizeof(type))
|
||||
#define iv_obj_pop(v, type, objptr) iv_pop(v, objptr, sizeof(type))
|
||||
#define iv_obj_size(v, type) (((v)->size) / sizeof(type))
|
||||
#define iv_obj_capacity(v, type) (((v)->capacity) / sizeof(type))
|
||||
#define iv_obj_resize(v, type, count) iv_resize(v, (count) * sizeof(type))
|
||||
#define iv_obj_reserve(v, type, count) iv_reserve(v, (count) * sizeof(type))
|
||||
|
||||
#define iv_obj_insert(v, type, pos, objptr) \
|
||||
iv_insert(v, (pos) * sizeof(type), objptr, sizeof(type))
|
||||
|
||||
#define iv_obj_erase(v, type, pos, count) \
|
||||
iv_erase(v, (pos) * sizeof(type), (count) * sizeof(type))
|
||||
|
||||
|
||||
#define IROUND_SIZE(b) (((size_t)1) << (b))
|
||||
#define IROUND_UP(s, n) (((s) + (n) - 1) & ~(((size_t)(n)) - 1))
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IMEMNODE */
|
||||
/*====================================================================*/
|
||||
struct IMEMNODE
|
||||
{
|
||||
struct IALLOCATOR *allocator; /* memory allocator */
|
||||
|
||||
struct IVECTOR vprev; /* prev node link vector */
|
||||
struct IVECTOR vnext; /* next node link vector */
|
||||
struct IVECTOR vnode; /* node information data */
|
||||
struct IVECTOR vdata; /* node data buffer vector */
|
||||
struct IVECTOR vmode; /* mode of allocation */
|
||||
ilong *mprev; /* prev node array */
|
||||
ilong *mnext; /* next node array */
|
||||
ilong *mnode; /* node info array */
|
||||
void **mdata; /* node data array */
|
||||
ilong *mmode; /* node mode array */
|
||||
ilong *extra; /* extra user data */
|
||||
ilong node_free; /* number of free nodes */
|
||||
ilong node_used; /* number of allocated */
|
||||
ilong node_max; /* number of all nodes */
|
||||
ilong grow_limit; /* limit of growing */
|
||||
|
||||
ilong node_size; /* node data fixed size */
|
||||
ilong node_shift; /* node data size shift */
|
||||
|
||||
struct IVECTOR vmem; /* mem-pages in the pool */
|
||||
char **mmem; /* mem-pages array */
|
||||
ilong mem_max; /* max num of memory pages */
|
||||
ilong mem_count; /* number of mem-pages */
|
||||
|
||||
ilong list_open; /* the entry of open-list */
|
||||
ilong list_close; /* the entry of close-list */
|
||||
ilong total_mem; /* total memory size */
|
||||
};
|
||||
|
||||
|
||||
void imnode_init(struct IMEMNODE *mn, ilong nodesize, struct IALLOCATOR *ac);
|
||||
void imnode_destroy(struct IMEMNODE *mnode);
|
||||
ilong imnode_new(struct IMEMNODE *mnode);
|
||||
void imnode_del(struct IMEMNODE *mnode, ilong index);
|
||||
ilong imnode_head(const struct IMEMNODE *mnode);
|
||||
ilong imnode_next(const struct IMEMNODE *mnode, ilong index);
|
||||
ilong imnode_prev(const struct IMEMNODE *mnode, ilong index);
|
||||
void*imnode_data(struct IMEMNODE *mnode, ilong index);
|
||||
const void* imnode_data_const(const struct IMEMNODE *mnode, ilong index);
|
||||
|
||||
#define IMNODE_NODE(mnodeptr, i) ((mnodeptr)->mnode[i])
|
||||
#define IMNODE_PREV(mnodeptr, i) ((mnodeptr)->mprev[i])
|
||||
#define IMNODE_NEXT(mnodeptr, i) ((mnodeptr)->mnext[i])
|
||||
#define IMNODE_DATA(mnodeptr, i) ((mnodeptr)->mdata[i])
|
||||
#define IMNODE_MODE(mnodeptr, i) ((mnodeptr)->mmode[i])
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* LIST DEFINITION */
|
||||
/*====================================================================*/
|
||||
#ifndef __ILIST_DEF__
|
||||
#define __ILIST_DEF__
|
||||
|
||||
struct ILISTHEAD {
|
||||
struct ILISTHEAD *next, *prev;
|
||||
};
|
||||
|
||||
typedef struct ILISTHEAD ilist_head;
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* list init */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#define ILIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
#define ILIST_HEAD(name) \
|
||||
struct ILISTHEAD name = ILIST_HEAD_INIT(name)
|
||||
|
||||
#define ILIST_INIT(ptr) ( \
|
||||
(ptr)->next = (ptr), (ptr)->prev = (ptr))
|
||||
|
||||
#define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
||||
#define ICONTAINEROF(ptr, type, member) ( \
|
||||
(type*)( ((char*)((type*)ptr)) - IOFFSETOF(type, member)) )
|
||||
|
||||
#define ILIST_ENTRY(ptr, type, member) ICONTAINEROF(ptr, type, member)
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* list operation */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#define ILIST_ADD(node, head) ( \
|
||||
(node)->prev = (head), (node)->next = (head)->next, \
|
||||
(head)->next->prev = (node), (head)->next = (node))
|
||||
|
||||
#define ILIST_ADD_TAIL(node, head) ( \
|
||||
(node)->prev = (head)->prev, (node)->next = (head), \
|
||||
(head)->prev->next = (node), (head)->prev = (node))
|
||||
|
||||
#define ILIST_DEL_BETWEEN(p, n) ((n)->prev = (p), (p)->next = (n))
|
||||
|
||||
#define ILIST_DEL(entry) (\
|
||||
(entry)->next->prev = (entry)->prev, \
|
||||
(entry)->prev->next = (entry)->next, \
|
||||
(entry)->next = 0, (entry)->prev = 0)
|
||||
|
||||
#define ILIST_DEL_INIT(entry) do { \
|
||||
ILIST_DEL(entry); ILIST_INIT(entry); } while (0)
|
||||
|
||||
#define ILIST_IS_EMPTY(entry) ((entry) == (entry)->next)
|
||||
|
||||
#define ilist_init ILIST_INIT
|
||||
#define ilist_entry ILIST_ENTRY
|
||||
#define ilist_add ILIST_ADD
|
||||
#define ilist_add_tail ILIST_ADD_TAIL
|
||||
#define ilist_del ILIST_DEL
|
||||
#define ilist_del_init ILIST_DEL_INIT
|
||||
#define ilist_is_empty ILIST_IS_EMPTY
|
||||
|
||||
#define ILIST_FOREACH(iterator, head, TYPE, MEMBER) \
|
||||
for ((iterator) = ilist_entry((head)->next, TYPE, MEMBER); \
|
||||
&((iterator)->MEMBER) != (head); \
|
||||
(iterator) = ilist_entry((iterator)->MEMBER.next, TYPE, MEMBER))
|
||||
|
||||
#define ilist_foreach(iterator, head, TYPE, MEMBER) \
|
||||
ILIST_FOREACH(iterator, head, TYPE, MEMBER)
|
||||
|
||||
#define ilist_foreach_entry(pos, head) \
|
||||
for( (pos) = (head)->next; (pos) != (head) ; (pos) = (pos)->next )
|
||||
|
||||
|
||||
#define __ilist_splice(list, head) do { \
|
||||
ilist_head *first = (list)->next, *last = (list)->prev; \
|
||||
ilist_head *at = (head)->next; \
|
||||
(first)->prev = (head), (head)->next = (first); \
|
||||
(last)->next = (at), (at)->prev = (last); } while (0)
|
||||
|
||||
#define ilist_splice(list, head) do { \
|
||||
if (!ilist_is_empty(list)) __ilist_splice(list, head); } while (0)
|
||||
|
||||
#define ilist_splice_init(list, head) do { \
|
||||
ilist_splice(list, head); ilist_init(list); } while (0)
|
||||
|
||||
#define ilist_replace(oldnode, newnode) ( \
|
||||
(newnode)->next = (oldnode)->next, \
|
||||
(newnode)->next->prev = (newnode), \
|
||||
(newnode)->prev = (oldnode)->prev, \
|
||||
(newnode)->prev->next = (newnode))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4311)
|
||||
#pragma warning(disable:4312)
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IMUTEX - mutex interfaces */
|
||||
/*====================================================================*/
|
||||
#ifndef IMUTEX_TYPE
|
||||
|
||||
#ifndef IMUTEX_DISABLE
|
||||
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64))
|
||||
#if ((!defined(_M_PPC)) && (!defined(_M_PPC_BE)) && (!defined(_XBOX)))
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#else
|
||||
#ifndef _XBOX
|
||||
#define _XBOX
|
||||
#endif
|
||||
#include <xtl.h>
|
||||
#endif
|
||||
|
||||
#define IMUTEX_TYPE CRITICAL_SECTION
|
||||
#define IMUTEX_INIT(m) InitializeCriticalSection((CRITICAL_SECTION*)(m))
|
||||
#define IMUTEX_DESTROY(m) DeleteCriticalSection((CRITICAL_SECTION*)(m))
|
||||
#define IMUTEX_LOCK(m) EnterCriticalSection((CRITICAL_SECTION*)(m))
|
||||
#define IMUTEX_UNLOCK(m) LeaveCriticalSection((CRITICAL_SECTION*)(m))
|
||||
|
||||
#elif defined(__unix) || defined(__unix__) || defined(__MACH__)
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#define IMUTEX_TYPE pthread_mutex_t
|
||||
#define IMUTEX_INIT(m) pthread_mutex_init((pthread_mutex_t*)(m), 0)
|
||||
#define IMUTEX_DESTROY(m) pthread_mutex_destroy((pthread_mutex_t*)(m))
|
||||
#define IMUTEX_LOCK(m) pthread_mutex_lock((pthread_mutex_t*)(m))
|
||||
#define IMUTEX_UNLOCK(m) pthread_mutex_unlock((pthread_mutex_t*)(m))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IMUTEX_TYPE
|
||||
#define IMUTEX_TYPE int
|
||||
#define IMUTEX_INIT(m) { (*(m)) = (*(m)); }
|
||||
#define IMUTEX_DESTROY(m) { (*(m)) = (*(m)); }
|
||||
#define IMUTEX_LOCK(m) { (*(m)) = (*(m)); }
|
||||
#define IMUTEX_UNLOCK(m) { (*(m)) = (*(m)); }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* IVECTOR / IMEMNODE MANAGEMENT */
|
||||
/*====================================================================*/
|
||||
|
||||
typedef struct IVECTOR ib_vector;
|
||||
typedef struct IMEMNODE ib_memnode;
|
||||
|
||||
ib_vector *iv_create(void);
|
||||
void iv_delete(ib_vector *vec);
|
||||
|
||||
ib_memnode *imnode_create(ilong nodesize, int grow_limit);
|
||||
void imnode_delete(ib_memnode *);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* Collection - Array */
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
||||
struct ib_array;
|
||||
typedef struct ib_array ib_array;
|
||||
|
||||
ib_array *ib_array_new(void (*destroy_func)(void*));
|
||||
void ib_array_delete(ib_array *array);
|
||||
void ib_array_reserve(ib_array *array, size_t new_size);
|
||||
size_t ib_array_size(const ib_array *array);
|
||||
void** ib_array_ptr(ib_array *array);
|
||||
void* ib_array_index(ib_array *array, size_t index);
|
||||
const void* ib_array_const_index(const ib_array *array, size_t index);
|
||||
void ib_array_push(ib_array *array, void *item);
|
||||
void ib_array_push_left(ib_array *array, void *item);
|
||||
void ib_array_replace(ib_array *array, size_t index, void *item);
|
||||
void* ib_array_pop(ib_array *array);
|
||||
void* ib_array_pop_left(ib_array *array);
|
||||
void ib_array_remove(ib_array *array, size_t index);
|
||||
void ib_array_insert_before(ib_array *array, size_t index, void *item);
|
||||
void* ib_array_pop_at(ib_array *array, size_t index);
|
||||
void ib_array_for_each(ib_array *array, void (*iterator)(void *item));
|
||||
|
||||
void ib_array_sort(ib_array *array,
|
||||
int (*compare)(const void*, const void*));
|
||||
|
||||
ilong ib_array_search(const ib_array *array,
|
||||
int (*compare)(const void*, const void*),
|
||||
const void *item,
|
||||
ilong start_pos);
|
||||
|
||||
ilong ib_array_bsearch(const ib_array *array,
|
||||
int (*compare)(const void*, const void*),
|
||||
const void *item);
|
||||
|
||||
|
||||
/*====================================================================*/
|
||||
/* ib_node - binary search tree (can be used in rbtree & avl) */
|
||||
/* color/balance won't be packed (can work without alignment) */
|
||||
/*====================================================================*/
|
||||
struct ib_node
|
||||
{
|
||||
struct ib_node *left; /* left child */
|
||||
struct ib_node *right; /* right child */
|
||||
struct ib_node *parent; /* pointing to node itself for empty node */
|
||||
int height; /* equals to 1 + max height in childs */
|
||||
};
|
||||
|
||||
struct ib_root
|
||||
{
|
||||
struct ib_node *node; /* root node */
|
||||
};
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* NODE MACROS */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#define IB_OFFSET(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
||||
#define IB_NODE2DATA(n, o) ((void *)((size_t)(n) - (o)))
|
||||
#define IB_DATA2NODE(d, o) ((struct ib_node*)((size_t)(d) + (o)))
|
||||
|
||||
#define IB_ENTRY(ptr, type, member) \
|
||||
((type*)IB_NODE2DATA(ptr, IB_OFFSET(type, member)))
|
||||
|
||||
#define ib_node_init(node) do { ((node)->parent) = (node); } while (0)
|
||||
#define ib_node_empty(node) ((node)->parent == (node))
|
||||
|
||||
#define IB_LEFT_HEIGHT(node) (((node)->left)? ((node)->left)->height : 0)
|
||||
#define IB_RIGHT_HEIGHT(node) (((node)->right)? ((node)->right)->height : 0)
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* binary search tree - node manipulation */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_node *ib_node_first(struct ib_root *root);
|
||||
struct ib_node *ib_node_last(struct ib_root *root);
|
||||
struct ib_node *ib_node_next(struct ib_node *node);
|
||||
struct ib_node *ib_node_prev(struct ib_node *node);
|
||||
|
||||
void ib_node_replace(struct ib_node *victim, struct ib_node *newnode,
|
||||
struct ib_root *root);
|
||||
|
||||
static inline void ib_node_link(struct ib_node *node, struct ib_node *parent,
|
||||
struct ib_node **ib_link) {
|
||||
node->parent = parent;
|
||||
node->height = 1;
|
||||
node->left = node->right = NULL;
|
||||
ib_link[0] = node;
|
||||
}
|
||||
|
||||
|
||||
/* avl insert rebalance and erase */
|
||||
void ib_node_post_insert(struct ib_node *node, struct ib_root *root);
|
||||
void ib_node_erase(struct ib_node *node, struct ib_root *root);
|
||||
|
||||
/* avl nodes destroy: fast tear down the whole tree */
|
||||
struct ib_node* ib_node_tear(struct ib_root *root, struct ib_node **next);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* avl - node templates */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#define ib_node_find(root, what, compare_fn, res_node) do {\
|
||||
struct ib_node *__n = (root)->node; \
|
||||
(res_node) = NULL; \
|
||||
while (__n) { \
|
||||
int __hr = (compare_fn)(what, __n); \
|
||||
if (__hr == 0) { (res_node) = __n; break; } \
|
||||
else if (__hr < 0) { __n = __n->left; } \
|
||||
else { __n = __n->right; } \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define ib_node_add(root, newnode, compare_fn, duplicate_node) do { \
|
||||
struct ib_node **__link = &((root)->node); \
|
||||
struct ib_node *__parent = NULL; \
|
||||
struct ib_node *__duplicate = NULL; \
|
||||
int __hr = 1; \
|
||||
while (__link[0]) { \
|
||||
__parent = __link[0]; \
|
||||
__hr = (compare_fn)(newnode, __parent); \
|
||||
if (__hr == 0) { __duplicate = __parent; break; } \
|
||||
else if (__hr < 0) { __link = &(__parent->left); } \
|
||||
else { __link = &(__parent->right); } \
|
||||
} \
|
||||
(duplicate_node) = __duplicate; \
|
||||
if (__duplicate == NULL) { \
|
||||
ib_node_link(newnode, __parent, __link); \
|
||||
ib_node_post_insert(newnode, root); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* avltree - friendly interface */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_tree
|
||||
{
|
||||
struct ib_root root; /* avl root */
|
||||
size_t offset; /* node offset in user data structure */
|
||||
size_t size; /* size of user data structure */
|
||||
size_t count; /* node count */
|
||||
/* returns 0 for equal, -1 for n1 < n2, 1 for n1 > n2 */
|
||||
int (*compare)(const void *n1, const void *n2);
|
||||
};
|
||||
|
||||
|
||||
/* initialize avltree, use IB_OFFSET(type, member) for "offset"
|
||||
* eg:
|
||||
* ib_tree_init(&mytree, mystruct_compare,
|
||||
* sizeof(struct mystruct_t),
|
||||
* IB_OFFSET(struct mystruct_t, node));
|
||||
*/
|
||||
void ib_tree_init(struct ib_tree *tree,
|
||||
int (*compare)(const void*, const void*), size_t size, size_t offset);
|
||||
|
||||
void *ib_tree_first(struct ib_tree *tree);
|
||||
void *ib_tree_last(struct ib_tree *tree);
|
||||
void *ib_tree_next(struct ib_tree *tree, void *data);
|
||||
void *ib_tree_prev(struct ib_tree *tree, void *data);
|
||||
|
||||
/* require a temporary user structure (data) which contains the key */
|
||||
void *ib_tree_find(struct ib_tree *tree, const void *data);
|
||||
void *ib_tree_nearest(struct ib_tree *tree, const void *data);
|
||||
|
||||
/* returns NULL for success, otherwise returns conflict node with same key */
|
||||
void *ib_tree_add(struct ib_tree *tree, void *data);
|
||||
|
||||
void ib_tree_remove(struct ib_tree *tree, void *data);
|
||||
void ib_tree_replace(struct ib_tree *tree, void *victim, void *newdata);
|
||||
|
||||
void ib_tree_clear(struct ib_tree *tree, void (*destroy)(void *data));
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* fastbin - fixed size object allocator */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_fastbin
|
||||
{
|
||||
size_t obj_size;
|
||||
size_t page_size;
|
||||
size_t maximum;
|
||||
char *start;
|
||||
char *endup;
|
||||
void *next;
|
||||
void *pages;
|
||||
};
|
||||
|
||||
|
||||
#define IB_NEXT(ptr) (((void**)(ptr))[0])
|
||||
|
||||
void ib_fastbin_init(struct ib_fastbin *fb, size_t obj_size);
|
||||
void ib_fastbin_destroy(struct ib_fastbin *fb);
|
||||
|
||||
void* ib_fastbin_new(struct ib_fastbin *fb);
|
||||
void ib_fastbin_del(struct ib_fastbin *fb, void *ptr);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* string */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_string;
|
||||
typedef struct ib_string ib_string;
|
||||
|
||||
#ifndef IB_STRING_SSO
|
||||
#define IB_STRING_SSO 14
|
||||
#endif
|
||||
|
||||
struct ib_string
|
||||
{
|
||||
char *ptr;
|
||||
int size;
|
||||
int capacity;
|
||||
char sso[IB_STRING_SSO + 2];
|
||||
};
|
||||
|
||||
#define ib_string_ptr(str) ((str)->ptr)
|
||||
#define ib_string_size(str) ((str)->size)
|
||||
|
||||
ib_string* ib_string_new(void);
|
||||
ib_string* ib_string_new_from(const char *text);
|
||||
ib_string* ib_string_new_size(const char *text, int size);
|
||||
|
||||
void ib_string_delete(ib_string *str);
|
||||
|
||||
ib_string* ib_string_resize(ib_string *str, int newsize);
|
||||
|
||||
ib_string* ib_string_assign(ib_string *str, const char *src);
|
||||
ib_string* ib_string_assign_size(ib_string *str, const char *src, int size);
|
||||
|
||||
ib_string* ib_string_erase(ib_string *str, int pos, int size);
|
||||
ib_string* ib_string_insert(ib_string *str, int pos,
|
||||
const void *data, int size);
|
||||
|
||||
ib_string* ib_string_append(ib_string *str, const char *src);
|
||||
ib_string* ib_string_append_size(ib_string *str, const char *src, int size);
|
||||
ib_string* ib_string_append_c(ib_string *str, char c);
|
||||
|
||||
ib_string* ib_string_prepend(ib_string *str, const char *src);
|
||||
ib_string* ib_string_prepend_size(ib_string *str, const char *src, int size);
|
||||
ib_string* ib_string_prepend_c(ib_string *str, char c);
|
||||
|
||||
ib_string* ib_string_rewrite(ib_string *str, int pos, const char *src);
|
||||
ib_string* ib_string_rewrite_size(ib_string *str, int pos,
|
||||
const char *src, int size);
|
||||
|
||||
int ib_string_compare(const struct ib_string *a, const struct ib_string *b);
|
||||
|
||||
int ib_string_find(const ib_string *str, const char *src, int len, int start);
|
||||
int ib_string_find_c(const ib_string *str, char ch, int start);
|
||||
|
||||
ib_array* ib_string_split(const ib_string *str, const char *sep, int len);
|
||||
ib_array* ib_string_split_c(const ib_string *str, char sep);
|
||||
|
||||
ib_string* ib_string_strip(ib_string *str, const char *seps);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* static hash table (closed hash table with avlnode) */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_hash_node
|
||||
{
|
||||
struct ib_node avlnode;
|
||||
void *key;
|
||||
size_t hash;
|
||||
};
|
||||
|
||||
struct ib_hash_index
|
||||
{
|
||||
struct ILISTHEAD node;
|
||||
struct ib_root avlroot;
|
||||
};
|
||||
|
||||
#define IB_HASH_INIT_SIZE 8
|
||||
|
||||
struct ib_hash_table
|
||||
{
|
||||
size_t count;
|
||||
size_t index_size;
|
||||
size_t index_mask;
|
||||
size_t (*hash)(const void *key);
|
||||
int (*compare)(const void *key1, const void *key2);
|
||||
struct ILISTHEAD head;
|
||||
struct ib_hash_index *index;
|
||||
struct ib_hash_index init[IB_HASH_INIT_SIZE];
|
||||
};
|
||||
|
||||
|
||||
void ib_hash_init(struct ib_hash_table *ht,
|
||||
size_t (*hash)(const void *key),
|
||||
int (*compare)(const void *key1, const void *key2));
|
||||
|
||||
struct ib_hash_node* ib_hash_node_first(struct ib_hash_table *ht);
|
||||
struct ib_hash_node* ib_hash_node_last(struct ib_hash_table *ht);
|
||||
|
||||
struct ib_hash_node* ib_hash_node_next(struct ib_hash_table *ht,
|
||||
struct ib_hash_node *node);
|
||||
|
||||
struct ib_hash_node* ib_hash_node_prev(struct ib_hash_table *ht,
|
||||
struct ib_hash_node *node);
|
||||
|
||||
static inline void ib_hash_node_key(struct ib_hash_table *ht,
|
||||
struct ib_hash_node *node, void *key) {
|
||||
node->key = key;
|
||||
node->hash = ht->hash(key);
|
||||
}
|
||||
|
||||
struct ib_hash_node* ib_hash_find(struct ib_hash_table *ht,
|
||||
const struct ib_hash_node *node);
|
||||
|
||||
struct ib_node** ib_hash_track(struct ib_hash_table *ht,
|
||||
const struct ib_hash_node *node, struct ib_node **parent);
|
||||
|
||||
struct ib_hash_node* ib_hash_add(struct ib_hash_table *ht,
|
||||
struct ib_hash_node *node);
|
||||
|
||||
void ib_hash_erase(struct ib_hash_table *ht, struct ib_hash_node *node);
|
||||
|
||||
void ib_hash_replace(struct ib_hash_table *ht,
|
||||
struct ib_hash_node *victim, struct ib_hash_node *newnode);
|
||||
|
||||
void ib_hash_clear(struct ib_hash_table *ht,
|
||||
void (*destroy)(struct ib_hash_node *node));
|
||||
|
||||
/* re-index nbytes must be: sizeof(struct ib_hash_index) * n */
|
||||
void* ib_hash_swap(struct ib_hash_table *ht, void *index, size_t nbytes);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* fast inline search, compare function will be expanded inline here */
|
||||
/*--------------------------------------------------------------------*/
|
||||
#define ib_hash_search(ht, srcnode, result, compare) do { \
|
||||
size_t __hash = (srcnode)->hash; \
|
||||
const void *__key = (srcnode)->key; \
|
||||
struct ib_hash_index *__index = \
|
||||
&((ht)->index[__hash & ((ht)->index_mask)]); \
|
||||
struct ib_node *__anode = __index->avlroot.node; \
|
||||
(result) = NULL; \
|
||||
while (__anode) { \
|
||||
struct ib_hash_node *__snode = \
|
||||
IB_ENTRY(__anode, struct ib_hash_node, avlnode); \
|
||||
size_t __shash = __snode->hash; \
|
||||
if (__hash == __shash) { \
|
||||
int __hc = (compare)(__key, __snode->key); \
|
||||
if (__hc == 0) { (result) = __snode; break; } \
|
||||
__anode = (__hc < 0)? __anode->left : __anode->right; \
|
||||
} else { \
|
||||
__anode = (__hash < __shash)? __anode->left:__anode->right;\
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* hash map, wrapper of ib_hash_table to support direct key/value */
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct ib_hash_entry
|
||||
{
|
||||
struct ib_hash_node node;
|
||||
void *value;
|
||||
};
|
||||
|
||||
struct ib_hash_map
|
||||
{
|
||||
size_t count;
|
||||
int insert;
|
||||
int fixed;
|
||||
int builtin;
|
||||
void* (*key_copy)(void *key);
|
||||
void (*key_destroy)(void *key);
|
||||
void* (*value_copy)(void *value);
|
||||
void (*value_destroy)(void *value);
|
||||
struct ib_fastbin fb;
|
||||
struct ib_hash_table ht;
|
||||
};
|
||||
|
||||
|
||||
#define ib_hash_key(entry) ((entry)->node.key)
|
||||
#define ib_hash_value(entry) ((entry)->value)
|
||||
|
||||
void ib_map_init(struct ib_hash_map *hm, size_t (*hash)(const void*),
|
||||
int (*compare)(const void *, const void *));
|
||||
|
||||
void ib_map_destroy(struct ib_hash_map *hm);
|
||||
|
||||
struct ib_hash_entry* ib_map_first(struct ib_hash_map *hm);
|
||||
struct ib_hash_entry* ib_map_last(struct ib_hash_map *hm);
|
||||
|
||||
struct ib_hash_entry* ib_map_next(struct ib_hash_map *hm,
|
||||
struct ib_hash_entry *n);
|
||||
struct ib_hash_entry* ib_map_prev(struct ib_hash_map *hm,
|
||||
struct ib_hash_entry *n);
|
||||
|
||||
struct ib_hash_entry* ib_map_find(struct ib_hash_map *hm, const void *key);
|
||||
void* ib_map_lookup(struct ib_hash_map *hm, const void *key, void *defval);
|
||||
|
||||
|
||||
struct ib_hash_entry* ib_map_add(struct ib_hash_map *hm,
|
||||
void *key, void *value, int *success);
|
||||
|
||||
struct ib_hash_entry* ib_map_set(struct ib_hash_map *hm,
|
||||
void *key, void *value);
|
||||
|
||||
void* ib_map_get(struct ib_hash_map *hm, const void *key);
|
||||
|
||||
void ib_map_erase(struct ib_hash_map *hm, struct ib_hash_entry *entry);
|
||||
|
||||
|
||||
/* returns 0 for success, -1 for key mismatch */
|
||||
int ib_map_remove(struct ib_hash_map *hm, const void *key);
|
||||
|
||||
void ib_map_clear(struct ib_hash_map *hm);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* fast inline search template */
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
||||
#define ib_map_search(hm, srckey, hash_func, cmp_func, result) do { \
|
||||
size_t __hash = (hash_func)(srckey); \
|
||||
struct ib_hash_index *__index = \
|
||||
&((hm)->ht.index[__hash & ((hm)->ht.index_mask)]); \
|
||||
struct ib_node *__anode = __index->avlroot.node; \
|
||||
(result) = NULL; \
|
||||
while (__anode) { \
|
||||
struct ib_hash_node *__snode = \
|
||||
IB_ENTRY(__anode, struct ib_hash_node, avlnode); \
|
||||
size_t __shash = __snode->hash; \
|
||||
if (__hash == __shash) { \
|
||||
int __hc = (cmp_func)((srckey), __snode->key); \
|
||||
if (__hc == 0) { \
|
||||
(result) = IB_ENTRY(__snode, \
|
||||
struct ib_hash_entry, node);\
|
||||
break; \
|
||||
} \
|
||||
__anode = (__hc < 0)? __anode->left : __anode->right; \
|
||||
} else { \
|
||||
__anode = (__hash < __shash)? __anode->left:__anode->right;\
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/* common type hash */
|
||||
/*--------------------------------------------------------------------*/
|
||||
size_t ib_hash_func_uint(const void *key);
|
||||
int ib_hash_compare_uint(const void *key1, const void *key2);
|
||||
|
||||
size_t ib_hash_func_int(const void *key);
|
||||
int ib_hash_compare_int(const void *key1, const void *key2);
|
||||
|
||||
size_t ib_hash_func_str(const void *key);
|
||||
int ib_hash_compare_str(const void *key1, const void *key2);
|
||||
|
||||
size_t ib_hash_func_cstr(const void *key);
|
||||
int ib_hash_compare_cstr(const void *key1, const void *key2);
|
||||
|
||||
|
||||
struct ib_hash_entry *ib_map_find_uint(struct ib_hash_map *hm, iulong key);
|
||||
struct ib_hash_entry *ib_map_find_int(struct ib_hash_map *hm, ilong key);
|
||||
struct ib_hash_entry *ib_map_find_str(struct ib_hash_map *hm, const ib_string *key);
|
||||
struct ib_hash_entry *ib_map_find_cstr(struct ib_hash_map *hm, const char *key);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
1059
czmod/iposix.c
1059
czmod/iposix.c
File diff suppressed because it is too large
Load Diff
401
czmod/iposix.h
401
czmod/iposix.h
@@ -1,401 +0,0 @@
|
||||
//=====================================================================
|
||||
//
|
||||
// iposix.h - posix file system accessing
|
||||
//
|
||||
// NOTE:
|
||||
// for more information, please see the readme file.
|
||||
//
|
||||
//=====================================================================
|
||||
#ifndef __IPOSIX_H__
|
||||
#define __IPOSIX_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------*/
|
||||
/* C99 Compatible */
|
||||
/*-------------------------------------------------------------------*/
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#ifdef _POSIX_C_SOURCE
|
||||
#if _POSIX_C_SOURCE < 200112L
|
||||
#undef _POSIX_C_SOURCE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
#undef _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#ifdef _BSD_SOURCE
|
||||
#undef _BSD_SOURCE
|
||||
#endif
|
||||
|
||||
#ifdef __BSD_VISIBLE
|
||||
#undef __BSD_VISIBLE
|
||||
#endif
|
||||
|
||||
#ifdef _XOPEN_SOURCE
|
||||
#undef _XOPEN_SOURCE
|
||||
#endif
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#define _BSD_SOURCE 1
|
||||
#define __BSD_VISIBLE 1
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef IDISABLE_FILE_SYSTEM_ACCESS
|
||||
//---------------------------------------------------------------------
|
||||
// Global Definition
|
||||
//---------------------------------------------------------------------
|
||||
#ifndef __INTEGER_32_BITS__
|
||||
#define __INTEGER_32_BITS__
|
||||
#if defined(__UINT32_TYPE__) && defined(__UINT32_TYPE__)
|
||||
typedef __UINT32_TYPE__ ISTDUINT32;
|
||||
typedef __INT32_TYPE__ ISTDINT32;
|
||||
#elif defined(__UINT_FAST32_TYPE__) && defined(__INT_FAST32_TYPE__)
|
||||
typedef __UINT_FAST32_TYPE__ ISTDUINT32;
|
||||
typedef __INT_FAST32_TYPE__ ISTDINT32;
|
||||
#elif defined(_WIN64) || defined(WIN64) || defined(__amd64__) || \
|
||||
defined(__x86_64) || defined(__x86_64__) || defined(_M_IA64) || \
|
||||
defined(_M_AMD64)
|
||||
typedef unsigned int ISTDUINT32;
|
||||
typedef int ISTDINT32;
|
||||
#elif defined(_WIN32) || defined(WIN32) || defined(__i386__) || \
|
||||
defined(__i386) || defined(_M_X86)
|
||||
typedef unsigned long ISTDUINT32;
|
||||
typedef long ISTDINT32;
|
||||
#elif defined(__MACOS__)
|
||||
typedef UInt32 ISTDUINT32;
|
||||
typedef SInt32 ISTDINT32;
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
#include <sys/types.h>
|
||||
typedef u_int32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#elif defined(__BEOS__)
|
||||
#include <sys/inttypes.h>
|
||||
typedef u_int32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#elif (defined(_MSC_VER) || defined(__BORLANDC__)) && (!defined(__MSDOS__))
|
||||
typedef unsigned __int32 ISTDUINT32;
|
||||
typedef __int32 ISTDINT32;
|
||||
#elif defined(__GNUC__) && (__GNUC__ > 3)
|
||||
#include <stdint.h>
|
||||
typedef uint32_t ISTDUINT32;
|
||||
typedef int32_t ISTDINT32;
|
||||
#else
|
||||
typedef unsigned long ISTDUINT32;
|
||||
typedef long ISTDINT32;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOS__)
|
||||
#ifndef __unix
|
||||
#define __unix 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__unix__) || defined(unix) || defined(__linux)
|
||||
#ifndef __unix
|
||||
#define __unix 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef __unix
|
||||
#include <unistd.h>
|
||||
#define IPATHSEP '/'
|
||||
#else
|
||||
#include <direct.h>
|
||||
#if defined(_WIN32)
|
||||
#define IPATHSEP '\\'
|
||||
#else
|
||||
#define IPATHSEP '/'
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef __IINT8_DEFINED
|
||||
#define __IINT8_DEFINED
|
||||
typedef char IINT8;
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT8_DEFINED
|
||||
#define __IUINT8_DEFINED
|
||||
typedef unsigned char IUINT8;
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT16_DEFINED
|
||||
#define __IUINT16_DEFINED
|
||||
typedef unsigned short IUINT16;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT16_DEFINED
|
||||
#define __IINT16_DEFINED
|
||||
typedef short IINT16;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT32_DEFINED
|
||||
#define __IINT32_DEFINED
|
||||
typedef ISTDINT32 IINT32;
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT32_DEFINED
|
||||
#define __IUINT32_DEFINED
|
||||
typedef ISTDUINT32 IUINT32;
|
||||
#endif
|
||||
|
||||
#ifndef __IINT64_DEFINED
|
||||
#define __IINT64_DEFINED
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 IINT64;
|
||||
#else
|
||||
typedef long long IINT64;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __IUINT64_DEFINED
|
||||
#define __IUINT64_DEFINED
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 IUINT64;
|
||||
#else
|
||||
typedef unsigned long long IUINT64;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
#ifndef _WIN32
|
||||
#define _WIN32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Posix Stat
|
||||
//---------------------------------------------------------------------
|
||||
#define ISTAT_IFMT 0170000 // file type mask
|
||||
#define ISTAT_IFIFO 0010000 // named pipe (fifo)
|
||||
#define ISTAT_IFCHR 0020000 // charactor special
|
||||
#define ISTAT_IFDIR 0040000 // directory
|
||||
#define ISTAT_IFBLK 0060000 // block special
|
||||
#define ISTAT_IFREG 0100000 // regular
|
||||
#define ISTAT_IFLNK 0120000 // symbolic link
|
||||
#define ISTAT_IFSOCK 0140000 // socket
|
||||
#define ISTAT_IFWHT 0160000 // whiteout
|
||||
#define ISTAT_ISUID 0004000 // set user id on execution
|
||||
#define ISTAT_ISGID 0002000 // set group id on execution
|
||||
#define ISTAT_ISVXT 0001000 // swapped text even after use
|
||||
#define ISTAT_IRWXU 0000700 // owner RWX mask
|
||||
#define ISTAT_IRUSR 0000400 // owner read permission
|
||||
#define ISTAT_IWUSR 0000200 // owner writer permission
|
||||
#define ISTAT_IXUSR 0000100 // owner execution permission
|
||||
#define ISTAT_IRWXG 0000070 // group RWX mask
|
||||
#define ISTAT_IRGRP 0000040 // group read permission
|
||||
#define ISTAT_IWGRP 0000020 // group write permission
|
||||
#define ISTAT_IXGRP 0000010 // group execution permission
|
||||
#define ISTAT_IRWXO 0000007 // other RWX mask
|
||||
#define ISTAT_IROTH 0000004 // other read permission
|
||||
#define ISTAT_IWOTH 0000002 // other writer permission
|
||||
#define ISTAT_IXOTH 0000001 // other execution permission
|
||||
|
||||
#define ISTAT_ISFMT(m, t) (((m) & ISTAT_IFMT) == (t))
|
||||
#define ISTAT_ISDIR(m) ISTAT_ISFMT(m, ISTAT_IFDIR)
|
||||
#define ISTAT_ISCHR(m) ISTAT_ISFMT(m, ISTAT_IFCHR)
|
||||
#define ISTAT_ISBLK(m) ISTAT_ISFMT(m, ISTAT_IFBLK)
|
||||
#define ISTAT_ISREG(m) ISTAT_ISFMT(m, ISTAT_IFREG)
|
||||
#define ISTAT_ISFIFO(m) ISTAT_ISFMT(m, ISTAT_IFIFO)
|
||||
#define ISTAT_ISLNK(m) ISTAT_ISFMT(m, ISTAT_IFLNK)
|
||||
#define ISTAT_ISSOCK(m) ISTAT_ISFMT(m, ISTAT_IFSOCK)
|
||||
#define ISTAT_ISWHT(m) ISTAT_ISFMT(m, ISTAT_IFWHT)
|
||||
|
||||
struct IPOSIX_STAT
|
||||
{
|
||||
IUINT32 st_mode;
|
||||
IUINT64 st_ino;
|
||||
IUINT32 st_dev;
|
||||
IUINT32 st_nlink;
|
||||
IUINT32 st_uid;
|
||||
IUINT32 st_gid;
|
||||
IUINT64 st_size;
|
||||
IUINT32 atime;
|
||||
IUINT32 mtime;
|
||||
IUINT32 ctime;
|
||||
IUINT32 st_blocks;
|
||||
IUINT32 st_blksize;
|
||||
IUINT32 st_rdev;
|
||||
IUINT32 st_flags;
|
||||
};
|
||||
|
||||
typedef struct IPOSIX_STAT iposix_stat_t;
|
||||
|
||||
#define IPOSIX_MAXPATH 1024
|
||||
#define IPOSIX_MAXBUFF ((IPOSIX_MAXPATH) + 8)
|
||||
|
||||
|
||||
// returns 0 for success, -1 for error
|
||||
int iposix_stat(const char *path, iposix_stat_t *ostat);
|
||||
|
||||
// returns 0 for success, -1 for error
|
||||
int iposix_lstat(const char *path, iposix_stat_t *ostat);
|
||||
|
||||
// returns 0 for success, -1 for error
|
||||
int iposix_fstat(int fd, iposix_stat_t *ostat);
|
||||
|
||||
// get current directory
|
||||
char *iposix_getcwd(char *path, int size);
|
||||
|
||||
// create directory
|
||||
int iposix_mkdir(const char *path, int mode);
|
||||
|
||||
// change directory
|
||||
int iposix_chdir(const char *path);
|
||||
|
||||
#ifndef F_OK
|
||||
#define F_OK 0
|
||||
#endif
|
||||
|
||||
#ifndef X_OK
|
||||
#define X_OK 1
|
||||
#endif
|
||||
|
||||
#ifndef W_OK
|
||||
#define W_OK 2
|
||||
#endif
|
||||
|
||||
#ifndef R_OK
|
||||
#define R_OK 4
|
||||
#endif
|
||||
|
||||
// check access
|
||||
int iposix_access(const char *path, int mode);
|
||||
|
||||
|
||||
// returns 1 for true 0 for false, -1 for not exist
|
||||
int iposix_path_isdir(const char *path);
|
||||
|
||||
// returns 1 for true 0 for false, -1 for not exist
|
||||
int iposix_path_isfile(const char *path);
|
||||
|
||||
// returns 1 for true 0 for false, -1 for not exist
|
||||
int iposix_path_islink(const char *path);
|
||||
|
||||
// returns 1 for true 0 for false
|
||||
int iposix_path_exists(const char *path);
|
||||
|
||||
// returns file size, -1 for error
|
||||
IINT64 iposix_path_getsize(const char *path);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Posix Path
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// 是否是绝对路径,如果是的话返回1,否则返回0
|
||||
int iposix_path_isabs(const char *path);
|
||||
|
||||
// 绝对路径
|
||||
char *iposix_path_abspath(const char *srcpath, char *path, int maxsize);
|
||||
|
||||
// 归一化路径:去掉重复斜杠,以及处理掉".", ".."等。
|
||||
char *iposix_path_normal(const char *srcpath, char *path, int maxsize);
|
||||
|
||||
// 连接路径
|
||||
char *iposix_path_join(const char *p1, const char *p2, char *path, int len);
|
||||
|
||||
// 路径分割:从右向左找到第一个"/"分成两个字符串
|
||||
int iposix_path_split(const char *path, char *p1, int l1, char *p2, int l2);
|
||||
|
||||
// 扩展分割:分割文件主名与扩展名
|
||||
int iposix_path_splitext(const char *path, char *p1, int l1,
|
||||
char *p2, int l2);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// platform special
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// 取得进程可执行文件的文件名
|
||||
int iposix_path_exepath(char *ptr, int size);
|
||||
|
||||
// 取得进程可执行文件的目录
|
||||
int iposix_path_execwd(char *ptr, int size);
|
||||
|
||||
// 递归创建路径
|
||||
int iposix_path_mkdir(const char *path, int mode);
|
||||
|
||||
// 精简版取得可执行路径
|
||||
const char *iposix_get_exepath(void);
|
||||
|
||||
// 精简版取得可执行目录
|
||||
const char *iposix_get_execwd(void);
|
||||
|
||||
|
||||
// 文件路径格式化:
|
||||
// out - 输出路径,长度不小于 IPOSIX_MAXPATH
|
||||
// root - 根路径
|
||||
// ... - 后续的相对路径
|
||||
// 返回 - out
|
||||
// 假设可执行路径位于 /home/abc/work,那么:
|
||||
// iposix_path_format(out, iposix_get_execwd(), "images/%s", "abc.jpg")
|
||||
// 结果就是 /home/abc/work/images/abc.jpg
|
||||
char *iposix_path_format(char *out, const char *root, const char *fmt, ...);
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// System Utilities
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#ifndef IDISABLE_SHARED_LIBRARY
|
||||
|
||||
/* LoadLibraryA */
|
||||
void *iposix_shared_open(const char *dllname);
|
||||
|
||||
/* GetProcAddress */
|
||||
void *iposix_shared_get(void *shared, const char *name);
|
||||
|
||||
/* FreeLibrary */
|
||||
void iposix_shared_close(void *shared);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef IDISABLE_FILE_SYSTEM_ACCESS
|
||||
|
||||
/* load file content, use free to dispose */
|
||||
void *iposix_file_load_content(const char *filename, long *size);
|
||||
|
||||
/* save file content */
|
||||
int iposix_file_save_content(const char *filename, const void *data, long size);
|
||||
|
||||
/* cross os GetModuleFileName, returns size for success, -1 for error */
|
||||
int iposix_get_proc_pathname(char *ptr, int size);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user