00001 /* 00002 * src/backend/utils/mb/wstrncmp.c 00003 * 00004 * 00005 * Copyright (c) 1989, 1993 00006 * The Regents of the University of California. All rights reserved. 00007 * 00008 * This code is derived from FreeBSD 2.2.1-RELEASE software. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. Neither the name of the University nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 */ 00034 /* can be used in either frontend or backend */ 00035 #include "postgres_fe.h" 00036 00037 #include "mb/pg_wchar.h" 00038 00039 int 00040 pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n) 00041 { 00042 if (n == 0) 00043 return 0; 00044 do 00045 { 00046 if (*s1 != *s2++) 00047 return (*s1 - *(s2 - 1)); 00048 if (*s1++ == 0) 00049 break; 00050 } while (--n != 0); 00051 return 0; 00052 } 00053 00054 int 00055 pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n) 00056 { 00057 if (n == 0) 00058 return 0; 00059 do 00060 { 00061 if ((pg_wchar) ((unsigned char) *s1) != *s2++) 00062 return ((pg_wchar) ((unsigned char) *s1) - *(s2 - 1)); 00063 if (*s1++ == 0) 00064 break; 00065 } while (--n != 0); 00066 return 0; 00067 } 00068 00069 size_t 00070 pg_wchar_strlen(const pg_wchar *str) 00071 { 00072 const pg_wchar *s; 00073 00074 for (s = str; *s; ++s) 00075 ; 00076 return (s - str); 00077 }