Changeset 1104 in MondoRescue
- Timestamp:
- Feb 7, 2007, 8:00:23 PM (18 years ago)
- Location:
- branches/stable/mondo/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/include/mr_err.h
r1064 r1104 9 9 #define MR_ERR_H 10 10 11 #include "mr_msg.h" 12 11 13 /* functions (public methods) */ 12 14 13 15 extern inline void mr_exit(int errorcode, const char *message); 14 extern inline void mr_log_exit(int errorcode, const char *message); 16 #define mr_log_exit(x,y) {mr_msg(0,y); mr_exit(x, y);} 15 17 16 18 #endif /* MR_ERR_H */ -
branches/stable/mondo/src/include/mr_mem.h
r1096 r1104 17 17 /* functions (public methods) */ 18 18 19 extern inline void mr_free(char *allocated); 20 extern inline void mr_allocstr(char *alloc, const char *orig); 21 extern inline void mr_asprintf(char **alloc, const char *fmt, ...); 22 extern inline void mr_getline(char **lineptr, size_t *n, FILE *stream); 23 extern inline void *mr_malloc(size_t size); 19 #define mr_free(x) mr_free_int((void **)&x,__LINE__,__FILE__) 20 #define mr_allocstr(x,y) mr_allocstr_int(x, y,__LINE__,__FILE__) 21 #define mr_asprintf(x,y,args...) mr_asprintf_int(x,__LINE__,__FILE__, y, ## args) 22 #define mr_getline(x,y,z) mr_getline_int(x, y,z,__LINE__,__FILE__) 23 #define mr_malloc(x) mr_malloc_int((size_t)x,__LINE__,__FILE__) 24 25 /* Internal function bringing debuging info 26 * called indirectly through macros */ 27 extern inline void mr_free_int(void **allocated, int line, char *file); 28 extern inline void mr_allocstr_int(char *alloc, const char *orig, int line, char *file); 29 extern inline void mr_asprintf_int(char **alloc, int line, char *file, const char *fmt, ...); 30 extern inline void mr_getline_int(char **lineptr, size_t *n, FILE *stream, int line, char *file); 31 extern inline void *mr_malloc_int(size_t size, int line, char *file); 24 32 25 33 #endif /* MR_MEM_H */ -
branches/stable/mondo/src/include/mr_msg.h
r1064 r1104 16 16 /* functions (public methods) */ 17 17 18 extern inline void mr_msg(int debug, const char *fmt, ...); 18 #define mr_msg(x,y,args...) {mr_msg_int(x,__LINE__,__FILE__,y,## args);} 19 19 extern void mr_msg_init(const char *configfile, int loglevel); 20 20 extern void mr_msg_close(void); 21 21 22 /* Internal function bringing debuging info 23 * called indirectly through macros */ 24 extern inline void mr_msg_int(int debug,int line, const char *file, const char *fmt, ...); 25 22 26 #endif /* MR_MSG_H */ -
branches/stable/mondo/src/lib/mr_err.c
r1064 r1104 27 27 /* We have to properly end newt */ 28 28 /* We have to remind people of log files */ 29 mr_msg_close(); 29 30 } 30 31 … … 38 39 exit(errorcode); 39 40 } 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 22 22 /* 23 23 * 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 24 27 */ 25 void mr_free (void *allocated) {28 void mr_free_int(void **allocated, int line, const char *file) { 26 29 27 30 /* free man pages says that if allocated is NULL 28 31 * nothing happens 29 32 */ 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 } 32 40 } 33 41 34 42 /* encapsulation function for malloc */ 35 void *mr_malloc (size_t size) {43 void *mr_malloc_int(size_t size, int line, const char *file) { 36 44 37 45 void *ret; … … 39 47 ret = malloc(size); 40 48 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"); 42 51 } 43 52 return(ret); … … 45 54 46 55 /* encapsulation function for getline */ 47 void mr_getline (char **lineptr, size_t *n, FILE *stream) {56 void mr_getline_int(char **lineptr, size_t *n, FILE *stream, int line, const char *file) { 48 57 49 58 ssize_t ret; … … 51 60 ret = getline(lineptr,n,stream); 52 61 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"); 54 64 } 55 65 } 56 66 57 67 /* encapsulation function for asprintf */ 58 void mr_asprintf (char **strp, const char *fmt, ...) {68 void mr_asprintf_int(char **strp, int line, const char *file, const char *fmt, ...) { 59 69 60 70 int res = 0; … … 64 74 res = vasprintf(strp, fmt, args); 65 75 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"); 67 78 } 68 79 va_end(args); … … 73 84 * freeing it before in any case 74 85 */ 75 void mr_allocstr (char *alloc, const char *orig) {86 void mr_allocstr_int(char *alloc, const char *orig, int line, const char *file) { 76 87 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); 79 90 } -
branches/stable/mondo/src/lib/mr_msg.c
r1065 r1104 52 52 * Function that log a message. Not called directly 53 53 * but through other functions 54 * fmt needs to be just before ... 54 55 */ 55 void mr_msg (int debug, const char *fmt, ...) {56 void mr_msg_int(int debug, int line, const char *file, const char *fmt, ...) { 56 57 57 58 int i = 0; … … 74 75 for (i = 1; i < debug; i++) 75 76 fprintf(fout, " "); 76 fprintf(fout, "%s ->%s#%d: ", __FILE__, __FUNCTION__, __LINE__);77 fprintf(fout, "%s #%d: ", file, line); 77 78 } 78 79 va_start(args,fmt); -
branches/stable/mondo/src/test/mktest
r1065 r1104 7 7 8 8 lib="../lib/mr_conf.c ../lib/mr_msg.c ../lib/mr_err.c ../lib/mr_mem.c" 9 OPT="-Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -Wstrict-prototypes -Wshadow -funsigned-char -Wunused -Winit-self -Wcast-align - O2 -g -I../common -I../include"9 OPT="-Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -Wstrict-prototypes -Wshadow -funsigned-char -Wunused -Winit-self -Wcast-align -fno-strict-aliasing -O2 -g -I../common -I../include" 10 10 11 11 echo "Generating test-msg" … … 15 15 echo "Generating test-conf" 16 16 gcc $OPT test-conf.c $lib -o test-conf 17 echo "Generating test-mem" 18 gcc $OPT test-mem.c $lib -o test-mem 17 19 18 20 echo "Testing against previous run" 19 for f in test-conf test-string test-msg ; do21 for f in test-conf test-string test-msg test-mem; do 20 22 chmod 755 $f 21 23 ./$f > /tmp/$f.res … … 23 25 if [ $? -ne 0 ]; then 24 26 echo "$f test KO !!" 27 else 28 echo "$f test OK" 25 29 fi 26 30 valgrind -q --error-exitcode=1 --leak-check=yes ./$f 2>&1 > /tmp/valgrind-$f.res
Note:
See TracChangeset
for help on using the changeset viewer.