< prev index next >

src/java.desktop/share/native/liblcms/cmserr.c

Print this page




  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 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2017 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------
  54 
  55 #include "lcms2_internal.h"
  56 
  57 
  58 // This function is here to help applications to prevent mixing lcms versions on header and shared objects.
  59 int CMSEXPORT cmsGetEncodedCMMversion(void)
  60 {
  61        return LCMS_VERSION;
  62 }
  63 
  64 // I am so tired about incompatibilities on those functions that here are some replacements
  65 // that hopefully would be fully portable.
  66 
  67 // compare two strings ignoring case
  68 int CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2)
  69 {
  70     register const unsigned char *us1 = (const unsigned char *)s1,
  71                                  *us2 = (const unsigned char *)s2;
  72 
  73     while (toupper(*us1) == toupper(*us2++))
  74         if (*us1++ == '\0')
  75             return 0;
  76 
  77     return (toupper(*us1) - toupper(*--us2));
  78 }
  79 
  80 // long int because C99 specifies ftell in such way (7.19.9.2)
  81 long int CMSEXPORT cmsfilelength(FILE* f)
  82 {
  83     long int p , n;
  84 
  85     p = ftell(f); // register current file position
  86     if (p == -1L)
  87         return -1L;
  88 
  89     if (fseek(f, 0, SEEK_END) != 0) {
  90         return -1L;


 447     // Dup of null pointer is also NULL
 448     if (ptr == NULL)
 449         return NULL;
 450 
 451     NewPtr = _cmsSubAlloc(s, size);
 452 
 453     if (ptr != NULL && NewPtr != NULL) {
 454         memcpy(NewPtr, ptr, size);
 455     }
 456 
 457     return NewPtr;
 458 }
 459 
 460 
 461 
 462 // Error logging ******************************************************************
 463 
 464 // There is no error handling at all. When a function fails, it returns proper value.
 465 // For example, all create functions does return NULL on failure. Other return FALSE
 466 // It may be interesting, for the developer, to know why the function is failing.
 467 // for that reason, lcms2 does offer a logging function. This function does recive
 468 // a ENGLISH string with some clues on what is going wrong. You can show this
 469 // info to the end user, or just create some sort of log.
 470 // The logging function should NOT terminate the program, as this obviously can leave
 471 // resources. It is the programmer's responsibility to check each function return code
 472 // to make sure it didn't fail.
 473 
 474 // Error messages are limited to MAX_ERROR_MESSAGE_LEN
 475 
 476 #define MAX_ERROR_MESSAGE_LEN   1024
 477 
 478 // ---------------------------------------------------------------------------------------------------------
 479 
 480 // This is our default log error
 481 static void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
 482 
 483 // Context0 storage, which is global
 484 _cmsLogErrorChunkType _cmsLogErrorChunk = { DefaultLogErrorHandlerFunction };
 485 
 486 // Allocates and inits error logger container for a given context. If src is NULL, only initializes the value
 487 // to the default. Otherwise, it duplicates the value. The interface is standard across all context clients




  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 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2020 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------
  54 
  55 #include "lcms2_internal.h"
  56 
  57 
  58 // This function is here to help applications to prevent mixing lcms versions on header and shared objects.
  59 int CMSEXPORT cmsGetEncodedCMMversion(void)
  60 {
  61        return LCMS_VERSION;
  62 }
  63 
  64 // I am so tired about incompatibilities on those functions that here are some replacements
  65 // that hopefully would be fully portable.
  66 
  67 // compare two strings ignoring case
  68 int CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2)
  69 {
  70     CMSREGISTER const unsigned char *us1 = (const unsigned char *)s1,
  71                                  *us2 = (const unsigned char *)s2;
  72 
  73     while (toupper(*us1) == toupper(*us2++))
  74         if (*us1++ == '\0')
  75             return 0;
  76 
  77     return (toupper(*us1) - toupper(*--us2));
  78 }
  79 
  80 // long int because C99 specifies ftell in such way (7.19.9.2)
  81 long int CMSEXPORT cmsfilelength(FILE* f)
  82 {
  83     long int p , n;
  84 
  85     p = ftell(f); // register current file position
  86     if (p == -1L)
  87         return -1L;
  88 
  89     if (fseek(f, 0, SEEK_END) != 0) {
  90         return -1L;


 447     // Dup of null pointer is also NULL
 448     if (ptr == NULL)
 449         return NULL;
 450 
 451     NewPtr = _cmsSubAlloc(s, size);
 452 
 453     if (ptr != NULL && NewPtr != NULL) {
 454         memcpy(NewPtr, ptr, size);
 455     }
 456 
 457     return NewPtr;
 458 }
 459 
 460 
 461 
 462 // Error logging ******************************************************************
 463 
 464 // There is no error handling at all. When a function fails, it returns proper value.
 465 // For example, all create functions does return NULL on failure. Other return FALSE
 466 // It may be interesting, for the developer, to know why the function is failing.
 467 // for that reason, lcms2 does offer a logging function. This function does receive
 468 // a ENGLISH string with some clues on what is going wrong. You can show this
 469 // info to the end user, or just create some sort of log.
 470 // The logging function should NOT terminate the program, as this obviously can leave
 471 // resources. It is the programmer's responsibility to check each function return code
 472 // to make sure it didn't fail.
 473 
 474 // Error messages are limited to MAX_ERROR_MESSAGE_LEN
 475 
 476 #define MAX_ERROR_MESSAGE_LEN   1024
 477 
 478 // ---------------------------------------------------------------------------------------------------------
 479 
 480 // This is our default log error
 481 static void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
 482 
 483 // Context0 storage, which is global
 484 _cmsLogErrorChunkType _cmsLogErrorChunk = { DefaultLogErrorHandlerFunction };
 485 
 486 // Allocates and inits error logger container for a given context. If src is NULL, only initializes the value
 487 // to the default. Otherwise, it duplicates the value. The interface is standard across all context clients


< prev index next >