3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync/* $Id$ */
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync/** @file
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * IPRT - RTStrNCmp.
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync */
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync/*
4073e7205169ef2f852dee7894e901411c5c394fvboxsync * Copyright (C) 2006-2013 Oracle Corporation
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync *
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * available from http://www.virtualbox.org. This file is free software;
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * General Public License (GPL) as published by the Free Software
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync *
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * The contents of this file may alternatively be used under the terms
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * of the Common Development and Distribution License Version 1.0
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * VirtualBox OSE distribution, in which case the provisions of the
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * CDDL are applicable instead of those of the GPL.
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync *
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * You may elect to license modified versions of this file under the
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync * terms and conditions of either the GPL or the CDDL or both.
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync */
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync/*******************************************************************************
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync* Header Files *
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync*******************************************************************************/
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync#include <iprt/string.h>
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync#include "internal/iprt.h"
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsyncRTDECL(int) RTStrNCmp(const char *psz1, const char *psz2, size_t cchMax)
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync{
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync if (psz1 == psz2)
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync return 0;
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync if (!psz1)
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync return -1;
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync if (!psz2)
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync return 1;
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync
4073e7205169ef2f852dee7894e901411c5c394fvboxsync#ifdef RT_OS_SOLARIS
4073e7205169ef2f852dee7894e901411c5c394fvboxsync /* Solaris: tstUtf8 found to fail for some RTSTR_MAX on testboxsh1:
4073e7205169ef2f852dee7894e901411c5c394fvboxsync solaris.amd64 v5.10 (Generic_142901-12 (Assembled 30 March 2009)). */
4073e7205169ef2f852dee7894e901411c5c394fvboxsync while (cchMax-- > 0)
4073e7205169ef2f852dee7894e901411c5c394fvboxsync {
4073e7205169ef2f852dee7894e901411c5c394fvboxsync char ch1 = *psz1++;
4073e7205169ef2f852dee7894e901411c5c394fvboxsync char ch2 = *psz2++;
4073e7205169ef2f852dee7894e901411c5c394fvboxsync if (ch1 != ch2)
4073e7205169ef2f852dee7894e901411c5c394fvboxsync return ch1 > ch2 ? 1 : -1;
4073e7205169ef2f852dee7894e901411c5c394fvboxsync else if (ch1 == 0)
4073e7205169ef2f852dee7894e901411c5c394fvboxsync break;
4073e7205169ef2f852dee7894e901411c5c394fvboxsync }
4073e7205169ef2f852dee7894e901411c5c394fvboxsync return 0;
4073e7205169ef2f852dee7894e901411c5c394fvboxsync#else
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync return strncmp(psz1, psz2, cchMax);
4073e7205169ef2f852dee7894e901411c5c394fvboxsync#endif
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync}
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsyncRT_EXPORT_SYMBOL(RTStrNCmp);
3183efc91c7b8252f1dc50dca3efd2d8ae627813vboxsync