Tue, 09 Oct 2012 16:46:29 +0200
some fixes
ucx/logging.c | file | annotate | diff | comparison | revisions | |
ucx/logging.h | file | annotate | diff | comparison | revisions | |
ucx/mempool.c | file | annotate | diff | comparison | revisions | |
ucx/memstream.c | file | annotate | diff | comparison | revisions | |
ucx/memstream.h | file | annotate | diff | comparison | revisions |
--- a/ucx/logging.c Tue Oct 09 15:02:40 2012 +0200 +++ b/ucx/logging.c Tue Oct 09 16:46:29 2012 +0200 @@ -1,19 +1,19 @@ -#include "logging.h" -#include <stdlib.h> - -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level) { - UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger)); - if (logger != NULL) { - logger->stream = stream; - logger->level = level; - } - - return logger; -} - -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message) { - if (level <= logger->level) { - fwrite(message.ptr, 1, message.length, logger->stream); - fflush(logger->stream); - } -} +#include "logging.h" +#include <stdlib.h> + +UcxLogger *ucx_logger_new(FILE *stream, unsigned int level) { + UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger)); + if (logger != NULL) { + logger->stream = stream; + logger->level = level; + } + + return logger; +} + +void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message) { + if (level <= logger->level) { + fwrite(message.ptr, 1, message.length, logger->stream); + fflush(logger->stream); + } +}
--- a/ucx/logging.h Tue Oct 09 15:02:40 2012 +0200 +++ b/ucx/logging.h Tue Oct 09 16:46:29 2012 +0200 @@ -1,35 +1,35 @@ -#ifndef LOGGING_H -#define LOGGING_H - -#include "string.h" -#include <stdio.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* leave enough space for custom log levels */ -#define UCX_LOGGER_ERROR 0x00 -#define UCX_LOGGER_WARN 0x10 -#define UCX_LOGGER_INFO 0x20 -#define UCX_LOGGER_TRACE 0x30 - -typedef struct { - FILE *stream; - unsigned int level; -} UcxLogger; - -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); -/* neither provide a free function nor a parameter for an allocator */ - -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message); -#define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) -#define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) -#define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m) -#define ucx_logger_trace(l,m) ucx_logger_log(l, UCX_LOGGER_TRACE, m) - -#ifdef __cplusplus -} -#endif - -#endif /* LOGGING_H */ +#ifndef LOGGING_H +#define LOGGING_H + +#include "string.h" +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* leave enough space for custom log levels */ +#define UCX_LOGGER_ERROR 0x00 +#define UCX_LOGGER_WARN 0x10 +#define UCX_LOGGER_INFO 0x20 +#define UCX_LOGGER_TRACE 0x30 + +typedef struct { + FILE *stream; + unsigned int level; +} UcxLogger; + +UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); +/* neither provide a free function nor a parameter for an allocator */ + +void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message); +#define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) +#define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) +#define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m) +#define ucx_logger_trace(l,m) ucx_logger_log(l, UCX_LOGGER_TRACE, m) + +#ifdef __cplusplus +} +#endif + +#endif /* LOGGING_H */
--- a/ucx/mempool.c Tue Oct 09 15:02:40 2012 +0200 +++ b/ucx/mempool.c Tue Oct 09 16:46:29 2012 +0200 @@ -5,7 +5,6 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <errno.h> #include "mempool.h" @@ -42,7 +41,7 @@ int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { void **data = realloc(pool->data, newcap*sizeof(void*)); if (data == NULL) { - return ENOMEM; + return 1; } else { pool->data = data; pool->size = newcap;
--- a/ucx/memstream.c Tue Oct 09 15:02:40 2012 +0200 +++ b/ucx/memstream.c Tue Oct 09 16:46:29 2012 +0200 @@ -3,14 +3,14 @@ #include <stdlib.h> #include <string.h> -struct _UcxMemstream { +struct UcxMemstream { void *space; - size_t pos; + off_t pos; size_t length; _Bool autofree; }; -UcxMemstream *ucx_memopen(void* space, size_t length) { +UcxMemstream *ucx_memopen(void *space, size_t length) { UcxMemstream *stream = (UcxMemstream*) malloc(sizeof(UcxMemstream)); if (stream) { if (!space) { @@ -40,8 +40,8 @@ free(stream); } -int ucx_memseek(UcxMemstream *stream, long offset, int whence) { - size_t npos; +int ucx_memseek(UcxMemstream *stream, off_t offset, int whence) { + off_t npos; switch (whence) { case SEEK_SET: npos = 0; @@ -95,9 +95,9 @@ } if (read) { - memcpy(d, m->space+m->pos, len); + memcpy(d, (char*)m->space+m->pos, len); } else { - memcpy(m->space+m->pos, d, len); + memcpy((char*)m->space+m->pos, d, len); } m->pos += len; @@ -128,7 +128,7 @@ int ucx_memprintf(UcxMemstream *stream, const char* format, ...) { va_list v; va_start(v, format); - int r = vsprintf(stream->space+stream->pos, format, v); + int r = vsprintf((char*)stream->space+stream->pos, format, v); va_end(v); stream->pos += r; @@ -143,7 +143,7 @@ va_list v; va_start(v, format); - int r = vsscanf(stream->space+stream->pos, format, v); + int r = vsscanf((char*)stream->space+stream->pos, format, v); va_end(v); stream->pos += r;
--- a/ucx/memstream.h Tue Oct 09 15:02:40 2012 +0200 +++ b/ucx/memstream.h Tue Oct 09 16:46:29 2012 +0200 @@ -11,8 +11,7 @@ /* as FILE is opaque, we don't do evil hacks but provide an alternative */ -struct _UcxMemstream; /* cauz we are mad about it, we make it opaque, too */ -typedef struct _UcxMemstream UcxMemstream; +typedef struct UcxMemstream UcxMemstream; UcxMemstream *ucx_memopen(void *space, size_t length); void ucx_memclose(UcxMemstream* stream); @@ -29,7 +28,7 @@ * remains unchanged. * */ -int ucx_memseek(UcxMemstream *stream, long offset, int whence); +int ucx_memseek(UcxMemstream *stream, off_t offset, int whence); size_t ucx_memtell(UcxMemstream *stream); /*