1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*****************************************************************************
  26  *   "Gif-Lib" - Yet another gif library.
  27  *
  28  * Written by:  Gershon Elber            IBM PC Ver 0.1,    Jun. 1989
  29  *****************************************************************************
  30  * Handle error reporting for the GIF library.
  31  *****************************************************************************
  32  * History:
  33  * 17 Jun 89 - Version 1.0 by Gershon Elber.
  34  ****************************************************************************/
  35 
  36 #ifdef HAVE_CONFIG_H
  37 #include <config.h>
  38 #endif
  39 
  40 #include <stdio.h>
  41 #include "gif_lib.h"
  42 
  43 int _GifError = 0;
  44 
  45 /*****************************************************************************
  46  * Return the last GIF error (0 if none) and reset the error.
  47  ****************************************************************************/
  48 int
  49 GifLastError(void) {
  50     int i = _GifError;
  51 
  52     _GifError = 0;
  53 
  54     return i;
  55 }
  56 
  57 /*****************************************************************************
  58  * Print the last GIF error to stderr.
  59  ****************************************************************************/
  60 void
  61 PrintGifError(void) {
  62     char *Err;
  63 
  64     switch (_GifError) {
  65       case D_GIF_ERR_OPEN_FAILED:
  66         Err = "Failed to open given file";
  67         break;
  68       case D_GIF_ERR_READ_FAILED:
  69         Err = "Failed to Read from given file";
  70         break;
  71       case D_GIF_ERR_NOT_GIF_FILE:
  72         Err = "Given file is NOT GIF file";
  73         break;
  74       case D_GIF_ERR_NO_SCRN_DSCR:
  75         Err = "No Screen Descriptor detected";
  76         break;
  77       case D_GIF_ERR_NO_IMAG_DSCR:
  78         Err = "No Image Descriptor detected";
  79         break;
  80       case D_GIF_ERR_NO_COLOR_MAP:
  81         Err = "Neither Global Nor Local color map";
  82         break;
  83       case D_GIF_ERR_WRONG_RECORD:
  84         Err = "Wrong record type detected";
  85         break;
  86       case D_GIF_ERR_DATA_TOO_BIG:
  87         Err = "#Pixels bigger than Width * Height";
  88         break;
  89       case D_GIF_ERR_NOT_ENOUGH_MEM:
  90         Err = "Fail to allocate required memory";
  91         break;
  92       case D_GIF_ERR_CLOSE_FAILED:
  93         Err = "Failed to close given file";
  94         break;
  95       case D_GIF_ERR_NOT_READABLE:
  96         Err = "Given file was not opened for read";
  97         break;
  98       case D_GIF_ERR_IMAGE_DEFECT:
  99         Err = "Image is defective, decoding aborted";
 100         break;
 101       case D_GIF_ERR_EOF_TOO_SOON:
 102         Err = "Image EOF detected, before image complete";
 103         break;
 104       default:
 105         Err = NULL;
 106         break;
 107     }
 108     if (Err != NULL)
 109         fprintf(stderr, "\nGIF-LIB error: %s.\n", Err);
 110     else
 111         fprintf(stderr, "\nGIF-LIB undefined error %d.\n", _GifError);
 112 }