Changeset 1104 in MondoRescue for branches/stable/mondo/src/lib


Ignore:
Timestamp:
Feb 7, 2007, 8:00:23 PM (17 years ago)
Author:
Bruno Cornec
Message:

Improvement of the low level library (Usage of LINE and FILE and simplified interfaces using macros)

Location:
branches/stable/mondo/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/lib/mr_err.c

    r1064 r1104  
    2727        /* We have to properly end newt */
    2828        /* We have to remind people of log files */
     29        mr_msg_close();
    2930}
    3031
     
    3839    exit(errorcode);
    3940}
    40 
    41 void mr_log_exit(int errorcode, const char *message) {
    42     mr_msg(0, message);
    43     mr_exit(errorcode, message);
    44 }
  • branches/stable/mondo/src/lib/mr_mem.c

    r1064 r1104  
    2222/*
    2323 * Function that frees memory if necessary
     24 * A pointer to the memory pointed is passed to it.
     25 * *allocated variable points then to the original content
     26 * pointed to by the caller
    2427 */
    25 void mr_free(void *allocated) {
     28void mr_free_int(void **allocated, int line, const char *file) {
    2629
    2730    /* free man pages says that if allocated is NULL
    2831     * nothing happens
    2932     */
    30     free(allocated);
    31     allocated = NULL;
     33    if (*allocated != NULL) {
     34        free(*allocated);
     35        *allocated = NULL;
     36    } else {
     37        mr_msg_int(0,line,file,"Attempt to reference NULL pointer\nExiting...");
     38        mr_exit(-1,"Attempt to reference NULL pointer");
     39    }
    3240}
    3341
    3442/* encapsulation function for malloc */
    35 void *mr_malloc(size_t size) {
     43void *mr_malloc_int(size_t size, int line, const char *file) {
    3644   
    3745    void *ret;
     
    3947    ret = malloc(size);
    4048    if (ret == NULL) {
    41         mr_log_exit(-1,"Unable to alloc memory in mr_malloc\nExiting...");
     49        mr_msg_int(0,line,file,"Unable to alloc memory in mr_malloc\nExiting...");
     50        mr_exit(-1,"Unable to alloc memory in mr_malloc");
    4251    }
    4352    return(ret);
     
    4554
    4655/* encapsulation function for getline */
    47 void mr_getline(char **lineptr, size_t *n, FILE *stream) {
     56void mr_getline_int(char **lineptr, size_t *n, FILE *stream, int line, const char *file) {
    4857   
    4958    ssize_t ret;
     
    5160    ret = getline(lineptr,n,stream);
    5261    if (ret == -1) {
    53         mr_log_exit(-1,"Unable to alloc memory in mr_getline\nExiting...");
     62        mr_msg_int(0,line,file,"Unable to alloc memory in mr_getline\nExiting...",line,file);
     63        mr_exit(-1,"Unable to alloc memory in mr_getline");
    5464    }
    5565}
    5666
    5767/* encapsulation function for asprintf */
    58 void mr_asprintf(char **strp, const char *fmt, ...) {
     68void mr_asprintf_int(char **strp, int line, const char *file, const char *fmt, ...) {
    5969
    6070    int res = 0;
     
    6474    res = vasprintf(strp, fmt, args);
    6575    if (res == -1) {
    66         mr_log_exit(-1,"Unable to alloc memory in mr_asprintf\nExiting...");
     76        mr_msg_int(0,line,file,"Unable to alloc memory in mr_asprintf\nExiting...",line,file);
     77        mr_exit(-1,"Unable to alloc memory in mr_asprintf");
    6778    }
    6879    va_end(args);
     
    7384 * freeing it before in any case
    7485 */
    75 void mr_allocstr(char *alloc, const char *orig) {
     86void mr_allocstr_int(char *alloc, const char *orig, int line, const char *file) {
    7687
    77     mr_free((void *)alloc);
    78     mr_asprintf(&alloc, orig);
     88    mr_free_int((void **)&alloc, line, file);
     89    mr_asprintf_int(&alloc, line, file, orig);
    7990}
  • branches/stable/mondo/src/lib/mr_msg.c

    r1065 r1104  
    5252 * Function that log a message. Not called directly
    5353 * but through other functions
     54 * fmt needs to be just before ...
    5455 */
    55 void mr_msg(int debug, const char *fmt, ...) {
     56void mr_msg_int(int debug, int line, const char *file, const char *fmt, ...) {
    5657
    5758    int i = 0;
     
    7475            for (i = 1; i < debug; i++)
    7576                fprintf(fout, "  ");
    76             fprintf(fout, "%s->%s#%d: ", __FILE__, __FUNCTION__, __LINE__);
     77            fprintf(fout, "%s #%d: ", file, line);
    7778        }
    7879        va_start(args,fmt);
Note: See TracChangeset for help on using the changeset viewer.