Re: [zfs] Mounting from (...) failed with error 19

From: Garrett Cooper <gcooper_at_FreeBSD.org>
Date: Wed, 20 Oct 2010 13:39:25 -0700
On Wed, Oct 20, 2010 at 12:45 PM, Peter Jeremy <peterjeremy_at_acm.org> wrote:
> On 2010-Oct-20 10:50:38 +0400, KOT MATPOCKuH <matpockuh_at_gmail.com> wrote:
>>> I fixed it with attached patch.
>>Omg... Why You are using strcmp, but not strncmp(fs, "zfs", strlen("zfs"))?
>
> Can you explain why you think it should be strncmp() please.

I'd say that strcmp is perfectly fine because zfs is a 3 character (4
if you count NUL) string. The comparison logic is dang near the same:

/*
 * Compare strings.
 */
int
strcmp(const char *s1, const char *s2)
{
        while (*s1 == *s2++)
                if (*s1++ == '\0')
                        return (0);
        return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
}

int
strncmp(const char *s1, const char *s2, size_t n)
{

        if (n == 0)
                return (0);
        do {
                if (*s1 != *s2++)
                        return (*(const unsigned char *)s1 -
                                *(const unsigned char *)(s2 - 1));
                if (*s1++ == '\0')
                        break;
        } while (--n != 0);
        return (0);
}

Weird how n == 0 with strcmp returns 0...

-Garrett
Received on Wed Oct 20 2010 - 18:39:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:08 UTC