Changeset 14 in libcf for trunk/src


Ignore:
Timestamp:
01/31/13 22:55:37 (11 years ago)
Author:
cheese
Message:

#1 add test code and fix debug and logging error

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_debug.c

    r12 r14  
    4949} S_CF_DEBUG_CTX, CF_DEBUG_CTX;
    5050
    51 void
     51int
    5252CF_Debug_Local_Print (CF_DEBUG_CTX  * ctx,
    5353                      const char    * fmt,
    5454                      va_list       valist)
    5555{
    56     fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s %s(%d)] ",
     56    fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s:%d][%s] ",
    5757                                    ctx->file,
    58                                     ctx->func,
    59                                     ctx->line);
     58                                    ctx->line,
     59                                    ctx->func);
    6060    vfprintf (GET_CTX_OSTREAM (ctx), fmt, valist);
     61
     62    return CF_OK;
    6163}
    6264
     
    129131        return CF_ERROR_DEBUG_SET_OUTPUT_FD;
    130132    }
     133
     134    return CF_OK;
     135}
     136
     137int
     138CF_Debug_UpdateCtx (CF_Debug_Ctx    ctx,
     139                    const char      * file,
     140                    const char      * func,
     141                    const int       line)
     142{
     143    CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx;
     144
     145    CHECK_INVALID_CTX (ctx);
     146
     147    strncpy (context->file, file, strlen (file));
     148    strncpy (context->func, func, strlen (func));
     149    context->line = line;
    131150
    132151    return CF_OK;
     
    154173                   const char           * fmt, ...)
    155174{
    156     int             i, j;
    157     va_list         valist;
    158     FILE            * fp = GET_CTX_OSTREAM (ctx);
    159 
    160     CHECK_INVALID_CTX (ctx);
     175    int     i, j;
     176    va_list valist;
     177    FILE    * fp = NULL;
     178
     179    CHECK_INVALID_CTX (ctx);
     180    fp = GET_CTX_OSTREAM (ctx);
    161181
    162182    va_start (valist, fmt);
     
    210230    context->callstack.caller = push;
    211231
    212     /* set current context */
    213     sprintf (context->file, "%s", file);
    214     sprintf (context->func, "%s", func);
    215     context->line = line;
     232    CF_Debug_UpdateCtx (ctx, file, func, line);
    216233
    217234    return CF_OK;
     
    233250    if (callstack != NULL)
    234251    {
     252        sprintf (callstack->file    , "%s", pop->file);
    235253        sprintf (callstack->function, "%s", pop->func);
    236254        callstack->line = pop->line;
     
    244262    if (pop->caller != NULL)
    245263    {
    246         sprintf (context->file, "%s", pop->caller->file);
    247         sprintf (context->func, "%s", pop->caller->func);
    248         context->line = pop->caller->line;
    249         context->callstack.caller = pop->caller;
    250     }
    251 
     264        CF_Debug_UpdateCtx (ctx,
     265                            pop->caller->file,
     266                            pop->caller->func,
     267                            pop->caller->line);
     268    }
     269
     270    context->callstack.caller = pop->caller;
    252271    free (pop);
    253272
  • trunk/src/cf_file.c

    r5 r14  
    55
    66#ifdef _WIN32
     7# include <stdio.h>
    78# include <io.h>
    8 # include <stdio.h>
     9# include <sys/stat.h>
     10
     11# define S_IWUSR        _S_IWRITE
     12# define S_IRUSR        _S_IREAD
     13# define S_IXUSR        _S_IEXEC
     14# define S_IRGRP        0x00000000
     15# define S_IWGRP        0x00000000
     16# define S_IXGRP        0x00000000
     17# define S_IROTH        0x00000000
     18# define S_IWOTH        0x00000000
     19# define S_IXOTH        0x00000000
    920#else // #ifdef _WIN32
    1021# include <unistd.h>
     
    2637CF_File_Create (const char * path)
    2738{
    28     int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, 0);
     39    int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
    2940
    3041    if (result < 0)
  • trunk/src/cf_log.c

    r13 r14  
    22 * cf_log.c
    33 */
     4#ifdef _WIN32
     5# define _USE_32BIT_TIME_T
     6#endif
     7
    48#include "cf_log.h"
    59#include "cf_file.h"
     
    1418
    1519#ifdef _WIN32
     20# define snprintf       _snprintf
    1621# include <Windows.h>
    1722#else // #ifdef _WIN32
     
    2429
    2530#define LOCK_LOG_CTX(__ctx)                     \
    26     if (CF_Mutex_Lock (&__ctx->mutex) < 0)      \
    27         return CF_ERROR_LOG_LOCK_CTX
     31    CF_Mutex_Lock (&__ctx->mutex)
    2832
    2933#define UNLOCK_LOG_CTX(__ctx)                   \
    30     if (CF_Mutex_Unlock (&__ctx->mutex) < 0)    \
    31         return CF_ERROR_LOG_UNLOCK_CTX
     34    CF_Mutex_Unlock (&__ctx->mutex)
    3235
    3336#define CF_LOG_BUFFER_DEFAULT_SIZE      128 * 1024
     
    146149    CF_Log_Local_GetTime (&dt);
    147150
    148     sprintf (buffer, "%02d-%02d-%02d %02d:%02d:%02d.%03d",
    149                      dt.year, dt.month, dt.day,
    150                      dt.hour, dt.min, dt.sec, dt.usec);
     151   
     152
     153    snprintf (buffer, strlen ("0000-00-00 00:00:00.000"),
     154              "%02d-%02d-%02d %02d:%02d:%02d.%03d",
     155              dt.year, dt.month, dt.day,
     156              dt.hour, dt.min, dt.sec, dt.usec);
    151157
    152158    return CF_OK;
     
    287293    if (context->buffer != NULL)
    288294    {
    289         /* FIXME : write residual data in buffer */
    290 
     295        CF_Log_Flush (ctx);
    291296        free (context->buffer);
    292297        context->buffer = NULL;
  • trunk/src/makefile

    r10 r14  
    4343                    cf_log          \
    4444
    45 LIB_NAME        = cf
     45TARGET_NAME     = cf
    4646
    4747CC              = gcc
     
    5757TARGET_PATH     = ../_build
    5858OBJ_PATH        = ../_obj
    59 TARGET          = $(TARGET_PATH)/lib$(LIB_NAME).$(EXT_SHARED)
     59TARGET          = $(TARGET_PATH)/lib$(TARGET_NAME).$(EXT_SHARED)
    6060SRCS            = $(addsuffix .$(SOURCE_TYPE),$(FILES))
    6161OBJS            = $(addprefix $(OBJ_PATH)/,$(addsuffix .o,$(FILES)))
Note: See TracChangeset for help on using the changeset viewer.