Simple utilities sink - stuff that doesn't fit anywhere else / objects in plain C Snapshot
Defines | Functions | Variables
errorp.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "errorp.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Go to the source code of this file.

Defines

#define ERROR_TOKEN   "ERROR: "
#define STACK_FRAMES   30
#define STACK_START   "*** start stack ***\n"
#define STACK_EOF   "\n*** eof stack ***\n\n"
#define TOKENS_COUNT   6
#define TOKENS_ADDRESS   0
#define TOKENS_PERMISSIONS   1
#define TOKENS_FILEOFFSET   2
#define TOKENS_PATH   5

Functions

int errorp_is_file_open ()
int errorp_open_file (const char *file)
void errorp_close_file ()
void errorp (int rval, const char *fmt,...)
void error_dump_string (const char *msg, char *buff, size_t buff_size)

Variables

static int FD_OUT = 2
static int FD_ASSIGNED = 0

Define Documentation

#define ERROR_TOKEN   "ERROR: "

Definition at line 16 of file errorp.c.

#define STACK_EOF   "\n*** eof stack ***\n\n"

Definition at line 21 of file errorp.c.

#define STACK_FRAMES   30

Definition at line 18 of file errorp.c.

#define STACK_START   "*** start stack ***\n"

Definition at line 20 of file errorp.c.

#define TOKENS_ADDRESS   0

Definition at line 124 of file errorp.c.

#define TOKENS_COUNT   6

Definition at line 123 of file errorp.c.

#define TOKENS_FILEOFFSET   2

Definition at line 126 of file errorp.c.

#define TOKENS_PATH   5

Definition at line 127 of file errorp.c.

#define TOKENS_PERMISSIONS   1

Definition at line 125 of file errorp.c.


Function Documentation

void error_dump_string ( const char *  msg,
char *  buff,
size_t  buff_size 
)

Definition at line 98 of file errorp.c.

{
 #if __linux__
  void *sframes[ STACK_FRAMES + 1 ];
  int nframes, i;
#endif


  write( FD_OUT , msg , strlen( msg ) );

#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, buff_size,  "frame %d ip: %p\n", i, sframes[ i ]);
    write( FD_OUT , buff, strlen( buff ) );
  }

  dump_modules( buff, buff_size );
  write( FD_OUT, STACK_EOF, strlen( STACK_EOF ) );
#endif
}

Variable Documentation

int FD_ASSIGNED = 0 [static]

Definition at line 25 of file errorp.c.

int FD_OUT = 2 [static]

Definition at line 24 of file errorp.c.