0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// This file is available under and governed by the GNU General Public 0N/A// License version 2 only, as published by the Free Software Foundation. 0N/A// However, the following notice accompanied the original version of this 2693N/A//--------------------------------------------------------------------------------- 2693N/A// Little Color Management System 6271N/A// Copyright (c) 1998-2012 Marti Maria Saguer 0N/A// Permission is hereby granted, free of charge, to any person obtaining 0N/A// a copy of this software and associated documentation files (the "Software"), 0N/A// to deal in the Software without restriction, including without limitation 0N/A// the rights to use, copy, modify, merge, publish, distribute, sublicense, 0N/A// and/or sell copies of the Software, and to permit persons to whom the Software 0N/A// is furnished to do so, subject to the following conditions: 0N/A// The above copyright notice and this permission notice shall be included in 0N/A// all copies or substantial portions of the Software. 0N/A// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0N/A// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 0N/A// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0N/A// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 0N/A// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 0N/A// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0N/A// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2693N/A//--------------------------------------------------------------------------------- 2693N/A// I am so tired about incompatibilities on those functions that here are some replacements 2693N/A// that hopefully would be fully portable. 2693N/A// compare two strings ignoring case 2693N/A register const unsigned char *
us1 = (
const unsigned char *)
s1,
2693N/A// long int because C99 specifies ftell in such way (7.19.9.2) 2693N/A// Memory handling ------------------------------------------------------------------ 2693N/A// This is the interface to low-level memory management routines. By default a simple 2693N/A// amount of memoy that can be reclaimed. This is mostly as a safety feature to 2693N/A// prevent bogus or malintentionated code to allocate huge blocks that otherwise lcms 2693N/A// User may override this behaviour by using a memory plug-in, which basically replaces 2693N/A// the default memory management functions. In this case, no check is performed and it 2693N/A// is up to the plug-in writter to keep in the safe side. There are only three functions 2693N/A// required to be implemented: malloc, realloc and free, although the user may want to 2693N/A// replace the optional mallocZero, calloc and dup as well. 2693N/A// ********************************************************************************* 2693N/A// This is the default memory allocation function. It does a very coarse 2693N/A// check of amout of memory, just to prevent exploits 2693N/A// The default free function. The only check proformed is against NULL pointers 2693N/A // free(NULL) is defined a no-op by C99, therefore it is safe to 2693N/A // avoid the check, but it is here just in case... 2693N/A// The default realloc function. Again it check for exploits. If Ptr is NULL, 2693N/A// realloc behaves the same way as malloc and allocates a new block of size bytes. 2693N/A// The default calloc function. Allocates an array of num elements, each one of size bytes 2693N/A// all memory is initialized to zero. 6271N/A // Preserve calloc behaviour 6271N/A // Safe check for overflow. 2693N/A// Generic block duplication 2693N/A// Pointers to malloc and _cmsFree functions in current environment 2693N/A// Plug-in replacement entry 2693N/A // NULL forces to reset to defaults 2693N/A // Check for required callbacks 2693N/A // Set replacement functions 2693N/A// Generic block duplication 2693N/A// ******************************************************************************************** 2693N/A// Sub allocation takes care of many pointers of small size. The memory allocated in 2693N/A// this way have be freed at once. Next function allocates a single chunk for linked list 2693N/A// I prefer this method over realloc due to the big inpact on xput realloc may have if 6271N/A// memory is being swapped to disk. This approach is safer (although that may not be true on all platforms) 2693N/A// The suballocated is nothing but a pointer to the first element in the list. We also keep 2693N/A// the thread ID in this structure. 2693N/A// Get rid of whole linked list 2693N/A// Get a pointer to small memory block. 2693N/A // Check for memory. If there is no room, allocate a new chunk of double memory size. 2693N/A// Error logging ****************************************************************** 2693N/A// There is no error handling at all. When a funtion fails, it returns proper value. 2693N/A// For example, all create functions does return NULL on failure. Other return FALSE 2693N/A// It may be interesting, for the developer, to know why the function is failing. 2693N/A// for that reason, lcms2 does offer a logging function. This function does recive 2693N/A// a ENGLISH string with some clues on what is going wrong. You can show this 2693N/A// info to the end user, or just create some sort of log. 2693N/A// The logging function should NOT terminate the program, as this obviously can leave 2693N/A// resources. It is the programmer's responsability to check each function return code 2693N/A// to make sure it didn't fail. 2693N/A// Error messages are limited to MAX_ERROR_MESSAGE_LEN 2693N/A// --------------------------------------------------------------------------------------------------------- 2693N/A// This is our default log error 2693N/A// The current handler in actual environment 2693N/A// The default error logger does nothing. 2693N/A // fprintf(stderr, "[lcms]: %s\n", Text); 2693N/A// ErrorText is a text holding an english description of error. 2693N/A// Utility function to print signatures