freebsd-src/lib/libc/string/strverscmp.3
Mina Galić 09ec5e67a7 libc: fix history for strverscmp(3) and versionsort(3)
strverscmp(3) and versionsort(3) where first released in 13.2

PR:		273401
Reviewed by:	kib
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D41617
2023-08-31 14:52:31 +03:00

57 lines
1.5 KiB
Groff

.\" SPDX-License-Identifier: BSD-2-Clause
.\" Copyright (c) 2022 Aymeric Wibo <obiwac@gmail.com>
.Dd August 31, 2023
.Dt STRVERSCMP 3
.Os
.Sh NAME
.Nm strverscmp
.Nd compare strings according to natural order
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In string.h
.Ft int
.Fn strverscmp "const char *s1" "const char *s2"
.Sh DESCRIPTION
The
.Fn strverscmp
function
compares the null-terminated strings
.Fa s1
and
.Fa s2
according to their natural order
and returns an integer greater than, equal to, or less than 0,
depending on whether
.Fa s1
is greater than, equal to, or less than
.Fa s2 .
.Pp
More specifically, this natural order is found by iterating over both
strings until a difference is found.
If the difference is between non-decimal characters,
.Fn strverscmp
acts like
.Xr strcmp 3
(thus, the ordering would be "a", "b", "train").
If a decimal digit is found, the whole number is read and compared
(thus, the ordering would be "9", "10", "420" which is different to lexicographic order,
what
.Xr strcmp 3
would have done).
Numbers with leading zeroes are interpreted as fractional parts (even without a decimal point),
and numbers with more leading zeroes are placed before numbers with fewer leading zeroes
(thus, the ordering would be "000", "00", "01", "010", "09", "0", "1", "9", "10").
.Sh SEE ALSO
.Xr strcmp 3 ,
.Xr versionsort 3
.Sh STANDARDS
The
.Fn strverscmp
function is a GNU extension and conforms to no standard.
.Sh HISTORY
The
.Fn strverscmp
function was added in
.Fx 13.2 .