added libimago
[eradicate] / libs / imago / libpng / pngerror.c
diff --git a/libs/imago/libpng/pngerror.c b/libs/imago/libpng/pngerror.c
new file mode 100644 (file)
index 0000000..17b137f
--- /dev/null
@@ -0,0 +1,345 @@
+\r
+/* pngerror.c - stub functions for i/o and memory allocation\r
+ *\r
+ * Last changed in libpng 1.2.30 [August 15, 2008]\r
+ * For conditions of distribution and use, see copyright notice in png.h\r
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson\r
+ * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\r
+ * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\r
+ *\r
+ * This file provides a location for all error handling.  Users who\r
+ * need special error handling are expected to write replacement functions\r
+ * and use png_set_error_fn() to use those functions.  See the instructions\r
+ * at each function.\r
+ */\r
+\r
+#define PNG_INTERNAL\r
+#include "png.h"\r
+#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\r
+\r
+static void /* PRIVATE */\r
+png_default_error PNGARG((png_structp png_ptr,\r
+  png_const_charp error_message));\r
+#ifndef PNG_NO_WARNINGS\r
+static void /* PRIVATE */\r
+png_default_warning PNGARG((png_structp png_ptr,\r
+  png_const_charp warning_message));\r
+#endif /* PNG_NO_WARNINGS */\r
+\r
+/* This function is called whenever there is a fatal error.  This function\r
+ * should not be changed.  If there is a need to handle errors differently,\r
+ * you should supply a replacement error function and use png_set_error_fn()\r
+ * to replace the error function at run-time.\r
+ */\r
+#ifndef PNG_NO_ERROR_TEXT\r
+void PNGAPI\r
+png_error(png_structp png_ptr, png_const_charp error_message)\r
+{\r
+#ifdef PNG_ERROR_NUMBERS_SUPPORTED\r
+   char msg[16];\r
+   if (png_ptr != NULL)\r
+   {\r
+     if (png_ptr->flags&\r
+       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))\r
+     {\r
+       if (*error_message == '#')\r
+       {\r
+         /* Strip "#nnnn " from beginning of error message. */\r
+           int offset;\r
+           for (offset = 1; offset<15; offset++)\r
+              if (error_message[offset] == ' ')\r
+                  break;\r
+           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)\r
+           {\r
+              int i;\r
+              for (i = 0; i < offset - 1; i++)\r
+                 msg[i] = error_message[i + 1];\r
+              msg[i - 1] = '\0';\r
+              error_message = msg;\r
+           }\r
+           else\r
+              error_message += offset;\r
+       }\r
+       else\r
+       {\r
+           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)\r
+           {\r
+              msg[0] = '0';\r
+              msg[1] = '\0';\r
+              error_message = msg;\r
+           }\r
+       }\r
+     }\r
+   }\r
+#endif\r
+   if (png_ptr != NULL && png_ptr->error_fn != NULL)\r
+      (*(png_ptr->error_fn))(png_ptr, error_message);\r
+\r
+   /* If the custom handler doesn't exist, or if it returns,\r
+      use the default handler, which will not return. */\r
+   png_default_error(png_ptr, error_message);\r
+}\r
+#else\r
+void PNGAPI\r
+png_err(png_structp png_ptr)\r
+{\r
+   if (png_ptr != NULL && png_ptr->error_fn != NULL)\r
+      (*(png_ptr->error_fn))(png_ptr, '\0');\r
+\r
+   /* If the custom handler doesn't exist, or if it returns,\r
+      use the default handler, which will not return. */\r
+   png_default_error(png_ptr, '\0');\r
+}\r
+#endif /* PNG_NO_ERROR_TEXT */\r
+\r
+#ifndef PNG_NO_WARNINGS\r
+/* This function is called whenever there is a non-fatal error.  This function\r
+ * should not be changed.  If there is a need to handle warnings differently,\r
+ * you should supply a replacement warning function and use\r
+ * png_set_error_fn() to replace the warning function at run-time.\r
+ */\r
+void PNGAPI\r
+png_warning(png_structp png_ptr, png_const_charp warning_message)\r
+{\r
+   int offset = 0;\r
+   if (png_ptr != NULL)\r
+   {\r
+#ifdef PNG_ERROR_NUMBERS_SUPPORTED\r
+   if (png_ptr->flags&\r
+     (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))\r
+#endif\r
+     {\r
+       if (*warning_message == '#')\r
+       {\r
+           for (offset = 1; offset < 15; offset++)\r
+              if (warning_message[offset] == ' ')\r
+                  break;\r
+       }\r
+     }\r
+     if (png_ptr != NULL && png_ptr->warning_fn != NULL)\r
+        (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);\r
+   }\r
+   else\r
+      png_default_warning(png_ptr, warning_message + offset);\r
+}\r
+#endif /* PNG_NO_WARNINGS */\r
+\r
+\r
+/* These utilities are used internally to build an error message that relates\r
+ * to the current chunk.  The chunk name comes from png_ptr->chunk_name,\r
+ * this is used to prefix the message.  The message is limited in length\r
+ * to 63 bytes, the name characters are output as hex digits wrapped in []\r
+ * if the character is invalid.\r
+ */\r
+#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))\r
+static PNG_CONST char png_digit[16] = {\r
+   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
+   'A', 'B', 'C', 'D', 'E', 'F'\r
+};\r
+\r
+#define PNG_MAX_ERROR_TEXT 64\r
+\r
+#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)\r
+static void /* PRIVATE */\r
+png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp\r
+   error_message)\r
+{\r
+   int iout = 0, iin = 0;\r
+\r
+   while (iin < 4)\r
+   {\r
+      int c = png_ptr->chunk_name[iin++];\r
+      if (isnonalpha(c))\r
+      {\r
+         buffer[iout++] = '[';\r
+         buffer[iout++] = png_digit[(c & 0xf0) >> 4];\r
+         buffer[iout++] = png_digit[c & 0x0f];\r
+         buffer[iout++] = ']';\r
+      }\r
+      else\r
+      {\r
+         buffer[iout++] = (png_byte)c;\r
+      }\r
+   }\r
+\r
+   if (error_message == NULL)\r
+      buffer[iout] = '\0';\r
+   else\r
+   {\r
+      buffer[iout++] = ':';\r
+      buffer[iout++] = ' ';\r
+      png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);\r
+      buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';\r
+   }\r
+}\r
+\r
+#ifdef PNG_READ_SUPPORTED\r
+void PNGAPI\r
+png_chunk_error(png_structp png_ptr, png_const_charp error_message)\r
+{\r
+   char msg[18+PNG_MAX_ERROR_TEXT];\r
+   if (png_ptr == NULL)\r
+     png_error(png_ptr, error_message);\r
+   else\r
+   {\r
+     png_format_buffer(png_ptr, msg, error_message);\r
+     png_error(png_ptr, msg);\r
+   }\r
+}\r
+#endif /* PNG_READ_SUPPORTED */\r
+#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */\r
+\r
+#ifndef PNG_NO_WARNINGS\r
+void PNGAPI\r
+png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)\r
+{\r
+   char msg[18+PNG_MAX_ERROR_TEXT];\r
+   if (png_ptr == NULL)\r
+     png_warning(png_ptr, warning_message);\r
+   else\r
+   {\r
+     png_format_buffer(png_ptr, msg, warning_message);\r
+     png_warning(png_ptr, msg);\r
+   }\r
+}\r
+#endif /* PNG_NO_WARNINGS */\r
+\r
+\r
+/* This is the default error handling function.  Note that replacements for\r
+ * this function MUST NOT RETURN, or the program will likely crash.  This\r
+ * function is used by default, or if the program supplies NULL for the\r
+ * error function pointer in png_set_error_fn().\r
+ */\r
+static void /* PRIVATE */\r
+png_default_error(png_structp png_ptr, png_const_charp error_message)\r
+{\r
+#ifndef PNG_NO_CONSOLE_IO\r
+#ifdef PNG_ERROR_NUMBERS_SUPPORTED\r
+   if (*error_message == '#')\r
+   {\r
+     /* Strip "#nnnn " from beginning of warning message. */\r
+     int offset;\r
+     char error_number[16];\r
+     for (offset = 0; offset<15; offset++)\r
+     {\r
+         error_number[offset] = error_message[offset + 1];\r
+         if (error_message[offset] == ' ')\r
+             break;\r
+     }\r
+     if ((offset > 1) && (offset < 15))\r
+     {\r
+       error_number[offset - 1] = '\0';\r
+       fprintf(stderr, "libpng error no. %s: %s\n", error_number,\r
+          error_message + offset + 1);\r
+     }\r
+     else\r
+       fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);\r
+   }\r
+   else\r
+#endif\r
+   fprintf(stderr, "libpng error: %s\n", error_message);\r
+#endif\r
+\r
+#ifdef PNG_SETJMP_SUPPORTED\r
+   if (png_ptr)\r
+   {\r
+#  ifdef USE_FAR_KEYWORD\r
+   {\r
+      jmp_buf jmpbuf;\r
+      png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));\r
+      longjmp(jmpbuf, 1);\r
+   }\r
+#  else\r
+   longjmp(png_ptr->jmpbuf, 1);\r
+#  endif\r
+   }\r
+#else\r
+   PNG_ABORT();\r
+#endif\r
+#ifdef PNG_NO_CONSOLE_IO\r
+   error_message = error_message; /* make compiler happy */\r
+#endif\r
+}\r
+\r
+#ifndef PNG_NO_WARNINGS\r
+/* This function is called when there is a warning, but the library thinks\r
+ * it can continue anyway.  Replacement functions don't have to do anything\r
+ * here if you don't want them to.  In the default configuration, png_ptr is\r
+ * not used, but it is passed in case it may be useful.\r
+ */\r
+static void /* PRIVATE */\r
+png_default_warning(png_structp png_ptr, png_const_charp warning_message)\r
+{\r
+#ifndef PNG_NO_CONSOLE_IO\r
+#  ifdef PNG_ERROR_NUMBERS_SUPPORTED\r
+   if (*warning_message == '#')\r
+   {\r
+     int offset;\r
+     char warning_number[16];\r
+     for (offset = 0; offset < 15; offset++)\r
+     {\r
+        warning_number[offset] = warning_message[offset + 1];\r
+        if (warning_message[offset] == ' ')\r
+            break;\r
+     }\r
+     if ((offset > 1) && (offset < 15))\r
+     {\r
+       warning_number[offset + 1] = '\0';\r
+       fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,\r
+          warning_message + offset);\r
+     }\r
+     else\r
+       fprintf(stderr, "libpng warning: %s\n", warning_message);\r
+   }\r
+   else\r
+#  endif\r
+     fprintf(stderr, "libpng warning: %s\n", warning_message);\r
+#else\r
+   warning_message = warning_message; /* make compiler happy */\r
+#endif\r
+   png_ptr = png_ptr; /* make compiler happy */\r
+}\r
+#endif /* PNG_NO_WARNINGS */\r
+\r
+/* This function is called when the application wants to use another method\r
+ * of handling errors and warnings.  Note that the error function MUST NOT\r
+ * return to the calling routine or serious problems will occur.  The return\r
+ * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)\r
+ */\r
+void PNGAPI\r
+png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,\r
+   png_error_ptr error_fn, png_error_ptr warning_fn)\r
+{\r
+   if (png_ptr == NULL)\r
+      return;\r
+   png_ptr->error_ptr = error_ptr;\r
+   png_ptr->error_fn = error_fn;\r
+   png_ptr->warning_fn = warning_fn;\r
+}\r
+\r
+\r
+/* This function returns a pointer to the error_ptr associated with the user\r
+ * functions.  The application should free any memory associated with this\r
+ * pointer before png_write_destroy and png_read_destroy are called.\r
+ */\r
+png_voidp PNGAPI\r
+png_get_error_ptr(png_structp png_ptr)\r
+{\r
+   if (png_ptr == NULL)\r
+      return NULL;\r
+   return ((png_voidp)png_ptr->error_ptr);\r
+}\r
+\r
+\r
+#ifdef PNG_ERROR_NUMBERS_SUPPORTED\r
+void PNGAPI\r
+png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)\r
+{\r
+   if (png_ptr != NULL)\r
+   {\r
+     png_ptr->flags &=\r
+       ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);\r
+   }\r
+}\r
+#endif\r
+#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */\r