1*05c9a015SAymeric Wibo.\" SPDX-License-Identifier: BSD-2-Clause 2*05c9a015SAymeric Wibo.\" Copyright (c) 2022 Aymeric Wibo <obiwac@gmail.com> 3*05c9a015SAymeric Wibo.Dd July 11, 2022 4*05c9a015SAymeric Wibo.Dt STRVERSCMP 3 5*05c9a015SAymeric Wibo.Os 6*05c9a015SAymeric Wibo.Sh NAME 7*05c9a015SAymeric Wibo.Nm strverscmp 8*05c9a015SAymeric Wibo.Nd compare strings according to natural order 9*05c9a015SAymeric Wibo.Sh LIBRARY 10*05c9a015SAymeric Wibo.Lb libc 11*05c9a015SAymeric Wibo.Sh SYNOPSIS 12*05c9a015SAymeric Wibo.In string.h 13*05c9a015SAymeric Wibo.Ft int 14*05c9a015SAymeric Wibo.Fn strverscmp "const char *s1" "const char *s2" 15*05c9a015SAymeric Wibo.Sh DESCRIPTION 16*05c9a015SAymeric WiboThe 17*05c9a015SAymeric Wibo.Fn strverscmp 18*05c9a015SAymeric Wibofunction 19*05c9a015SAymeric Wibocompares the null-terminated strings 20*05c9a015SAymeric Wibo.Fa s1 21*05c9a015SAymeric Wiboand 22*05c9a015SAymeric Wibo.Fa s2 23*05c9a015SAymeric Wiboaccording to their natural order 24*05c9a015SAymeric Wiboand returns an integer greater than, equal to, or less than 0, 25*05c9a015SAymeric Wibodepending on whether 26*05c9a015SAymeric Wibo.Fa s1 27*05c9a015SAymeric Wibois greater than, equal to, or less than 28*05c9a015SAymeric Wibo.Fa s2 . 29*05c9a015SAymeric Wibo.Pp 30*05c9a015SAymeric WiboMore specifically, this natural order is found by iterating over both 31*05c9a015SAymeric Wibostrings until a difference is found. 32*05c9a015SAymeric WiboIf the difference is between non-decimal characters, 33*05c9a015SAymeric Wibo.Fn strverscmp 34*05c9a015SAymeric Wiboacts like 35*05c9a015SAymeric Wibo.Xr strcmp 3 36*05c9a015SAymeric Wibo(thus, the ordering would be "a", "b", "train"). 37*05c9a015SAymeric WiboIf a decimal digit is found, the whole number is read and compared 38*05c9a015SAymeric Wibo(thus, the ordering would be "9", "10", "420" which is different to lexicographic order, 39*05c9a015SAymeric Wibowhat 40*05c9a015SAymeric Wibo.Xr strcmp 3 41*05c9a015SAymeric Wibowould have done). 42*05c9a015SAymeric WiboNumbers with leading zeroes are interpreted as fractional parts (even without a decimal point), 43*05c9a015SAymeric Wiboand numbers with more leading zeroes are placed before numbers with fewer leading zeroes 44*05c9a015SAymeric Wibo(thus, the ordering would be "000", "00", "01", "010", "09", "0", "1", "9", "10"). 45*05c9a015SAymeric Wibo.Sh SEE ALSO 46*05c9a015SAymeric Wibo.Xr strcmp 3 , 47*05c9a015SAymeric Wibo.Xr versionsort 3 48*05c9a015SAymeric Wibo.Sh STANDARDS 49*05c9a015SAymeric WiboThe 50*05c9a015SAymeric Wibo.Fn strverscmp 51*05c9a015SAymeric Wibofunction is a GNU extension and conforms to no standard. 52*05c9a015SAymeric Wibo.Sh HISTORY 53*05c9a015SAymeric WiboThe 54*05c9a015SAymeric Wibo.Fn strverscmp 55*05c9a015SAymeric Wibofunction was added in 56*05c9a015SAymeric Wibo.Fx 14.0 . 57