.\" Copyright (C) 2001 Andries Brouwer .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2002 Akihiro MOTOKI .\" all rights reserved. .\" Translated Sat Sep 21 08:34:42 2002 .\" by Akihiro MOTOKI .\" Updated 2013-05-01, Akihiro MOTOKI .\" .TH STRVERSCMP 3 2001\-12\-19 GNU "Linux Programmer's Manual" .SH 名前 strverscmp \- 2つのバージョン文字列を比較する .SH 書式 .nf \fB#define _GNU_SOURCE\fP /* feature_test_macros(7) 参照 */ .br \fB#include \fP .sp \fBint strverscmp(const char *\fP\fIs1\fP\fB, const char *\fP\fIs2\fP\fB);\fP .fi .SH 説明 .\" classical solution: "rename jan jan0 jan?" \fIjan1\fP, \fIjan2\fP, ..., \fIjan9\fP, \fIjan10\fP, ... といった名前のファイルがある状況はよくあるが、 \fBls\fP(1) を実行したときに \fIjan1\fP, \fIjan10\fP, ..., \fIjan2\fP, ..., \fIjan9\fP の順番で表示されるのには違和感がある。 これを修正するために、GNU は \fBls\fP(1) に \fI\-v\fP オプションを導入した。 この機能は \fBversionsort\fP(3) を使って実装されているが、この中で \fBstrverscmp\fP() が使用されている。 このように \fBstrverscmp\fP() の役目は2つの文字列を比較して「正しい」順序を探すことである。 これに対して \fBstrcmp\fP(3) は辞書順だけで比較した結果を返す。 関数 \fBstrverscmp\fP() はロケールのカテゴリーである \fBLC_COLLATE\fP を使用しない。 このことから、この関数が主にアスキー文字から成る文字列を 想定していることが分かる。 この関数の動作は以下の通りである。 両方の文字列が等しい場合、0 を返す。 それ以外の場合、その直前までは両方の文字列が等しく、 その直後のバイトで両者に違いがあるような、バイトの境界を探す。 見つかったバイト境界を含む数字列(数字だけの文字列)の最長一致検索を行う。 (数字列は境界から始まっていても、境界で終わっていてもよい)。 2つの文字列から得られた数字列の一方または両方が空であれば、 \fBstrcmp\fP(3) が返した結果を関数の返り値として返す。 すなわち、バイト値を比較した結果を返す。 それ以外の(数字列が両方とも空でない)場合、両方の数字列を数字順で比較する。 このとき、1つ以上の 0 が先頭にある数字列は、前に小数点がついているものと 解釈される。(先頭に 0 が多くある数字列ほど前に来ることになる) この結果、順序は次のようになる: \fI000\fP, \fI00\fP, \fI01\fP, \fI010\fP, \fI09\fP, \fI0\fP, \fI1\fP, \fI9\fP, \fI10\fP .SH 返り値 関数 \fBstrverscmp\fP() は、ゼロよりも 1)小さい、2)等しい、3)大きいのいずれかの整数を返す。 それぞれは、\fIs1\fP が \fIs2\fP よりも、 1)小さい、2)等しい、3)大きい ことを示す。 .SH 準拠 この関数は GNU による拡張である。 .SH 関連項目 \fBrename\fP(1), \fBstrcasecmp\fP(3), \fBstrcmp\fP(3), \fBstrcoll\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。