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 |
1.1 --- a/ucx/logging.c Tue Oct 09 15:02:40 2012 +0200 1.2 +++ b/ucx/logging.c Tue Oct 09 16:46:29 2012 +0200 1.3 @@ -1,19 +1,19 @@ 1.4 -#include "logging.h" 1.5 -#include <stdlib.h> 1.6 - 1.7 -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level) { 1.8 - UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger)); 1.9 - if (logger != NULL) { 1.10 - logger->stream = stream; 1.11 - logger->level = level; 1.12 - } 1.13 - 1.14 - return logger; 1.15 -} 1.16 - 1.17 -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message) { 1.18 - if (level <= logger->level) { 1.19 - fwrite(message.ptr, 1, message.length, logger->stream); 1.20 - fflush(logger->stream); 1.21 - } 1.22 -} 1.23 +#include "logging.h" 1.24 +#include <stdlib.h> 1.25 + 1.26 +UcxLogger *ucx_logger_new(FILE *stream, unsigned int level) { 1.27 + UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger)); 1.28 + if (logger != NULL) { 1.29 + logger->stream = stream; 1.30 + logger->level = level; 1.31 + } 1.32 + 1.33 + return logger; 1.34 +} 1.35 + 1.36 +void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message) { 1.37 + if (level <= logger->level) { 1.38 + fwrite(message.ptr, 1, message.length, logger->stream); 1.39 + fflush(logger->stream); 1.40 + } 1.41 +}
2.1 --- a/ucx/logging.h Tue Oct 09 15:02:40 2012 +0200 2.2 +++ b/ucx/logging.h Tue Oct 09 16:46:29 2012 +0200 2.3 @@ -1,35 +1,35 @@ 2.4 -#ifndef LOGGING_H 2.5 -#define LOGGING_H 2.6 - 2.7 -#include "string.h" 2.8 -#include <stdio.h> 2.9 - 2.10 -#ifdef __cplusplus 2.11 -extern "C" { 2.12 -#endif 2.13 - 2.14 -/* leave enough space for custom log levels */ 2.15 -#define UCX_LOGGER_ERROR 0x00 2.16 -#define UCX_LOGGER_WARN 0x10 2.17 -#define UCX_LOGGER_INFO 0x20 2.18 -#define UCX_LOGGER_TRACE 0x30 2.19 - 2.20 -typedef struct { 2.21 - FILE *stream; 2.22 - unsigned int level; 2.23 -} UcxLogger; 2.24 - 2.25 -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); 2.26 -/* neither provide a free function nor a parameter for an allocator */ 2.27 - 2.28 -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message); 2.29 -#define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) 2.30 -#define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) 2.31 -#define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m) 2.32 -#define ucx_logger_trace(l,m) ucx_logger_log(l, UCX_LOGGER_TRACE, m) 2.33 - 2.34 -#ifdef __cplusplus 2.35 -} 2.36 -#endif 2.37 - 2.38 -#endif /* LOGGING_H */ 2.39 +#ifndef LOGGING_H 2.40 +#define LOGGING_H 2.41 + 2.42 +#include "string.h" 2.43 +#include <stdio.h> 2.44 + 2.45 +#ifdef __cplusplus 2.46 +extern "C" { 2.47 +#endif 2.48 + 2.49 +/* leave enough space for custom log levels */ 2.50 +#define UCX_LOGGER_ERROR 0x00 2.51 +#define UCX_LOGGER_WARN 0x10 2.52 +#define UCX_LOGGER_INFO 0x20 2.53 +#define UCX_LOGGER_TRACE 0x30 2.54 + 2.55 +typedef struct { 2.56 + FILE *stream; 2.57 + unsigned int level; 2.58 +} UcxLogger; 2.59 + 2.60 +UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); 2.61 +/* neither provide a free function nor a parameter for an allocator */ 2.62 + 2.63 +void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message); 2.64 +#define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) 2.65 +#define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) 2.66 +#define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m) 2.67 +#define ucx_logger_trace(l,m) ucx_logger_log(l, UCX_LOGGER_TRACE, m) 2.68 + 2.69 +#ifdef __cplusplus 2.70 +} 2.71 +#endif 2.72 + 2.73 +#endif /* LOGGING_H */
3.1 --- a/ucx/mempool.c Tue Oct 09 15:02:40 2012 +0200 3.2 +++ b/ucx/mempool.c Tue Oct 09 16:46:29 2012 +0200 3.3 @@ -5,7 +5,6 @@ 3.4 #include <stdlib.h> 3.5 #include <string.h> 3.6 #include <stdio.h> 3.7 -#include <errno.h> 3.8 3.9 #include "mempool.h" 3.10 3.11 @@ -42,7 +41,7 @@ 3.12 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { 3.13 void **data = realloc(pool->data, newcap*sizeof(void*)); 3.14 if (data == NULL) { 3.15 - return ENOMEM; 3.16 + return 1; 3.17 } else { 3.18 pool->data = data; 3.19 pool->size = newcap;
4.1 --- a/ucx/memstream.c Tue Oct 09 15:02:40 2012 +0200 4.2 +++ b/ucx/memstream.c Tue Oct 09 16:46:29 2012 +0200 4.3 @@ -3,14 +3,14 @@ 4.4 #include <stdlib.h> 4.5 #include <string.h> 4.6 4.7 -struct _UcxMemstream { 4.8 +struct UcxMemstream { 4.9 void *space; 4.10 - size_t pos; 4.11 + off_t pos; 4.12 size_t length; 4.13 _Bool autofree; 4.14 }; 4.15 4.16 -UcxMemstream *ucx_memopen(void* space, size_t length) { 4.17 +UcxMemstream *ucx_memopen(void *space, size_t length) { 4.18 UcxMemstream *stream = (UcxMemstream*) malloc(sizeof(UcxMemstream)); 4.19 if (stream) { 4.20 if (!space) { 4.21 @@ -40,8 +40,8 @@ 4.22 free(stream); 4.23 } 4.24 4.25 -int ucx_memseek(UcxMemstream *stream, long offset, int whence) { 4.26 - size_t npos; 4.27 +int ucx_memseek(UcxMemstream *stream, off_t offset, int whence) { 4.28 + off_t npos; 4.29 switch (whence) { 4.30 case SEEK_SET: 4.31 npos = 0; 4.32 @@ -95,9 +95,9 @@ 4.33 } 4.34 4.35 if (read) { 4.36 - memcpy(d, m->space+m->pos, len); 4.37 + memcpy(d, (char*)m->space+m->pos, len); 4.38 } else { 4.39 - memcpy(m->space+m->pos, d, len); 4.40 + memcpy((char*)m->space+m->pos, d, len); 4.41 } 4.42 m->pos += len; 4.43 4.44 @@ -128,7 +128,7 @@ 4.45 int ucx_memprintf(UcxMemstream *stream, const char* format, ...) { 4.46 va_list v; 4.47 va_start(v, format); 4.48 - int r = vsprintf(stream->space+stream->pos, format, v); 4.49 + int r = vsprintf((char*)stream->space+stream->pos, format, v); 4.50 va_end(v); 4.51 4.52 stream->pos += r; 4.53 @@ -143,7 +143,7 @@ 4.54 4.55 va_list v; 4.56 va_start(v, format); 4.57 - int r = vsscanf(stream->space+stream->pos, format, v); 4.58 + int r = vsscanf((char*)stream->space+stream->pos, format, v); 4.59 va_end(v); 4.60 4.61 stream->pos += r;
5.1 --- a/ucx/memstream.h Tue Oct 09 15:02:40 2012 +0200 5.2 +++ b/ucx/memstream.h Tue Oct 09 16:46:29 2012 +0200 5.3 @@ -11,8 +11,7 @@ 5.4 5.5 5.6 /* as FILE is opaque, we don't do evil hacks but provide an alternative */ 5.7 -struct _UcxMemstream; /* cauz we are mad about it, we make it opaque, too */ 5.8 -typedef struct _UcxMemstream UcxMemstream; 5.9 +typedef struct UcxMemstream UcxMemstream; 5.10 5.11 UcxMemstream *ucx_memopen(void *space, size_t length); 5.12 void ucx_memclose(UcxMemstream* stream); 5.13 @@ -29,7 +28,7 @@ 5.14 * remains unchanged. 5.15 * 5.16 */ 5.17 -int ucx_memseek(UcxMemstream *stream, long offset, int whence); 5.18 +int ucx_memseek(UcxMemstream *stream, off_t offset, int whence); 5.19 size_t ucx_memtell(UcxMemstream *stream); 5.20 5.21 /*