"Fossies" - the Fresh Open Source Software Archive

Member "mlmmj-1.3.0/contrib/receivestrip/mlmmj_src/memory.c" (6 Jul 2010, 2253 Bytes) of package /linux/privat/mlmmj-1.3.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
    2  *
    3  * $Id$
    4  *
    5  * Permission is hereby granted, free of charge, to any person obtaining a copy
    6  * of this software and associated documentation files (the "Software"), to
    7  * deal in the Software without restriction, including without limitation the
    8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    9  * sell copies of the Software, and to permit persons to whom the Software is
   10  * furnished to do so, subject to the following conditions:
   11  *
   12  * The above copyright notice and this permission notice shall be included in
   13  * all copies or substantial portions of the Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   21  * IN THE SOFTWARE.
   22  */
   23 
   24 /* define _MEMORY_C so we can use the libc memory functions -- see mlmmj.h */
   25 #define _MEMORY_C   1
   26 
   27 #include <stdlib.h>
   28 #include <string.h>
   29 
   30 #include "mlmmj.h"
   31 #include "memory.h"
   32 #include "log_error.h"
   33 
   34 
   35 /* TODO add a debug mode with canaries and other goodies */
   36 
   37 
   38 void *__mymalloc(const char *file, int line, size_t size)
   39 {
   40     void *ret;
   41     
   42     ret = malloc(size);
   43     if (ret == NULL) {
   44         log_error(file, line, strerror(errno),
   45                 "malloc(%d) failed! Bailing out!", size);
   46         exit(EXIT_FAILURE);
   47     }
   48 
   49     return ret;
   50 }
   51 
   52 
   53 void *__myrealloc(const char *file, int line, void *ptr, size_t size)
   54 {
   55     void *ret;
   56     
   57     ret = realloc(ptr, size);
   58     if (ret == NULL) {
   59         log_error(file, line, strerror(errno),
   60                 "realloc(%p, %d) failed! Bailing out!",
   61                 ptr, size);
   62         exit(EXIT_FAILURE);
   63     }
   64 
   65     return ret;
   66 }
   67 
   68 
   69 void __myfree(const char *file, int line, void *ptr)
   70 {
   71     free(ptr);
   72 }
   73 
   74 
   75 char *__mystrdup(const char *file, int line, const char *str)
   76 {
   77     void *ret;
   78     
   79     ret = strdup(str);
   80     if (ret == NULL) {
   81         log_error(file, line, strerror(errno),
   82                 "strdup() failed! Bailing out!");
   83         exit(EXIT_FAILURE);
   84     }
   85 
   86     return ret;
   87 }