"Fossies" - the Fresh Open Source Software Archive

Member "ffe-0.3.9/src/xmalloc.c" (23 May 2008, 2096 Bytes) of package /linux/privat/ffe-0.3.9.tar.gz:


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. For more information about "xmalloc.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *    ffe - flat file extractor
    3  *
    4  *    Copyright (C) 2006 Timo Savinen
    5  *    This file is part of ffe.
    6  * 
    7  *    ffe is free software; you can redistribute it and/or modify
    8  *    it under the terms of the GNU General Public License as published by
    9  *    the Free Software Foundation; either version 2 of the License, or
   10  *    (at your option) any later version.
   11  *
   12  *    ffe is distributed in the hope that it will be useful,
   13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  *    GNU General Public License for more details.
   16  *
   17  *    You should have received a copy of the GNU General Public License
   18  *    along with ffe; if not, write to the Free Software
   19  *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20  *
   21  */
   22 
   23 /* $Id: xmalloc.c,v 1.11 2008-05-23 06:43:22 timo Exp $ */
   24 
   25 #include "ffe.h"
   26 #include <stdlib.h>
   27 #include <string.h>
   28 #ifdef HAVE_CONFIG_H
   29 #include <config.h>
   30 #endif
   31 
   32 void *
   33 xmalloc (size_t size)
   34 {
   35     register void *value = malloc(size);
   36     if (value == NULL) panic("Out of memory",NULL,NULL);
   37     return value;
   38 }
   39 
   40 char *
   41 xstrdup(char *str)
   42 {
   43     register char *ret = strdup(str);
   44     if (ret == NULL) panic("Out of memory",NULL,NULL);
   45     return ret;
   46 }
   47 
   48 void *
   49 xrealloc (void *ptr, size_t size)
   50 {
   51     register void *value = realloc(ptr,size);
   52     if (value == NULL) panic("Out of memory",NULL,NULL);
   53     return value;
   54 }
   55 
   56 FILE *
   57 xxfopen(char *name, char *mode, char bin_asc)
   58 {
   59     register FILE *ret;
   60 
   61     ret = fopen(name,mode);
   62     if(ret == NULL) panic("Error in opening file",name,strerror(errno));
   63 
   64 #if defined(HAVE_SETMODE) && defined(WIN32)
   65     if(bin_asc == 'a') setmode(fileno(ret),O_TEXT);
   66     if(bin_asc == 'b') setmode(fileno(ret),O_BINARY);
   67 #endif
   68     return ret;
   69 }
   70 
   71 FILE *
   72 xfopen(char *name, char *mode)
   73 {
   74     return xxfopen(name,mode,'a');
   75 }
   76 
   77 FILE *
   78 xfopenb(char *name, char *mode)
   79 {
   80     return xxfopen(name,mode,'b'); 
   81 }
   82 
   83 void
   84 file_to_text(FILE *fp)
   85 {
   86 #if defined(HAVE_SETMODE) && defined(WIN32)
   87     setmode(fileno(fp),O_TEXT);
   88 #endif
   89 }
   90 
   91