Changeset 1106 in MondoRescue for trunk/mondo/src/lib


Ignore:
Timestamp:
Feb 7, 2007, 11:55:11 PM (17 years ago)
Author:
Bruno Cornec
Message:

merge -r1082:1105 $SVN_M/branches/stable

Location:
trunk/mondo/src/lib
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/lib/Makefile.am

    r900 r1106  
    77noinst_LIBRARIES = libmr.a
    88
    9 libmr_a_SOURCES  = mr_conf.c mr_str.c mr_mem.c mr_err.c mr_msg.c
     9libmr_a_SOURCES  = mr_conf.c mr_str.c mr_mem.c mr_err.c mr_msg.c mr_file.c
  • trunk/mondo/src/lib/mr_err.c

    r1074 r1106  
    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 }
  • trunk/mondo/src/lib/mr_mem.c

    r1074 r1106  
    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}
  • trunk/mondo/src/lib/mr_msg.c

    r1074 r1106  
    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);
  • trunk/mondo/src/lib/mr_str.c

    r1079 r1106  
    88#include <stdio.h>
    99#include <string.h>
     10#include <time.h>
    1011
    1112#include "mr_mem.h"
     
    105106    return retstr;
    106107}
     108
     109/* Return a string containing the date */
     110char *mr_date(void) {
     111   
     112    time_t tcurr;
     113
     114    tcurr = time(NULL);
     115    return(ctime(&tcurr));
     116}
     117
Note: See TracChangeset for help on using the changeset viewer.