Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Oct 2010 13:40:11 -0700
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Peter Jeremy <peterjeremy@acm.org>
Cc:        KOT MATPOCKuH <matpockuh@gmail.com>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: [zfs] Mounting from (...) failed with error 19
Message-ID:  <AANLkTin_iYL1OF5BnGSdC7CaH6OybMVCXU103u-Yd5fi@mail.gmail.com>
In-Reply-To: <AANLkTino7DLY2Cj%2BnAsR1rM9KMEPvoSSxrqqyNDX9jLj@mail.gmail.com>
References:  <4CBCDD3A.9070404@delphij.net> <4CBD26B4.2020205@yandex.ru> <4CBDB17C.4040607@yandex.ru> <AANLkTimhCU%2BppQncCNJicH1AjuM25Z6GH3Jmqckprn=H@mail.gmail.com> <20101020194547.GA94244@server.vk2pj.dyndns.org> <AANLkTino7DLY2Cj%2BnAsR1rM9KMEPvoSSxrqqyNDX9jLj@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 20, 2010 at 1:39 PM, Garrett Cooper <gcooper@freebsd.org> wrote=
:
> On Wed, Oct 20, 2010 at 12:45 PM, Peter Jeremy <peterjeremy@acm.org> wrot=
e:
>> On 2010-Oct-20 10:50:38 +0400, KOT MATPOCKuH <matpockuh@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:
>
> /*
> =A0* Compare strings.
> =A0*/
> int
> strcmp(const char *s1, const char *s2)
> {
> =A0 =A0 =A0 =A0while (*s1 =3D=3D *s2++)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (*s1++ =3D=3D '\0')
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0);
> =A0 =A0 =A0 =A0return (*(const unsigned char *)s1 - *(const unsigned char=
 *)(s2 - 1));
> }
>
> int
> strncmp(const char *s1, const char *s2, size_t n)
> {
>
> =A0 =A0 =A0 =A0if (n =3D=3D 0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0);
> =A0 =A0 =A0 =A0do {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (*s1 !=3D *s2++)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (*(const unsigned c=
har *)s1 -
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*(const un=
signed char *)(s2 - 1));
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (*s1++ =3D=3D '\0')
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> =A0 =A0 =A0 =A0} while (--n !=3D 0);
> =A0 =A0 =A0 =A0return (0);
> }
>
> Weird how n =3D=3D 0 with strcmp returns 0...

s/strcmp/strncmp/

-Garrett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTin_iYL1OF5BnGSdC7CaH6OybMVCXU103u-Yd5fi>