Simple utilities sink - stuff that doesn't fit anywhere else / objects in plain C Snapshot
Functions
ERRORP

error logging with stack trace (not the symbols, just the addresses). More...

Functions

int errorp_open_file (const char *file)
int errorp_is_file_open ()
void errorp_close_file ()
void errorp (int rval, const char *fmt,...)

Detailed Description

error logging with stack trace (not the symbols, just the addresses).


Function Documentation

void errorp ( int  rval,
const char *  fmt,
  ... 
)

Definition at line 57 of file errorp.c.

{
  char buff[ 512 ];
  char *p, *eof;
  va_list ap;
  int len, n;
#if __linux__
  void *sframes[ STACK_FRAMES + 1 ];
  int nframes, i;
#endif

 
  p = buff;
  eof = p + sizeof( buff );

  strcpy( p, ERROR_TOKEN );
  p += strlen( ERROR_TOKEN );

  va_start( ap, fmt );
  len =  vsnprintf( p, eof - p - 1, fmt, ap );
  va_end( ap );
  p += len;

  n = snprintf(p, eof - p - 1, ". returns %d errno %d\n", rval, errno );
  p += n;

#if __linux__
  nframes = backtrace( sframes, STACK_FRAMES + 1); \
  write( FD_OUT, STACK_START, strlen( STACK_START ) );
  
  nframes =  backtrace( sframes, STACK_FRAMES );
  for (i=0; i<nframes; i++) {
    snprintf( buff, sizeof(buff),  "frame %d ip: %p\n", i, sframes[ i ]);
    write( FD_OUT , buff, strlen( buff ) );
  }

  dump_modules( buff, sizeof(buff) );
  write( FD_OUT, STACK_EOF, strlen( STACK_EOF ) );
#endif
}
void errorp_close_file ( )

Definition at line 48 of file errorp.c.

{
  if (FD_ASSIGNED != 1) {
    close( FD_OUT );
    FD_OUT = 2;
    FD_ASSIGNED = 0;
  }
}
int errorp_is_file_open ( )

Definition at line 31 of file errorp.c.

{  
  return FD_ASSIGNED;
}
int errorp_open_file ( const char *  file)

Definition at line 36 of file errorp.c.

{
  int fd;

  fd = open( file , O_CREAT | O_APPEND | O_RDWR, S_IWUSR  | S_IRUSR );
  if (fd != -1) {
    FD_OUT = fd;
    FD_ASSIGNED = 1;
  }
  return fd;
}