.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka .\" all rights reserved. .\" Translated 1997-12-16, HIROFUMI Nishizuka .\" Updated & Modified 2002-03-24, Yuichi SATO .\" Updated & Modified 2003-11-27, Yuichi SATO .\" Updated 2008-08-11, Akihiro MOTOKI .\" .\" 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. .\" .\" Modified Mon Apr 12 12:49:57 1993, David Metcalfe .\" Modified Sat Jul 24 18:56:22 1993, Rik Faith (faith@cs.unc.edu) .\" Modified Wed Feb 20 21:09:36 2002, Ian Redfern (redferni@logica.com) .\" 2008-07-09, mtk, add rawmemchr() .\" .TH MEMCHR 3 2009-12-04 "" "Linux Programmer's Manual" .SH 名前 memchr, memrchr, rawmemchr \- 文字を探すためにメモリをスキャンする .SH 書式 .nf .B #include .BI "void *memchr(const void *" s ", int " c ", size_t " n ); .BI "void *memrchr(const void *" s ", int " c ", size_t " n ); .BI "void *rawmemchr(const void *" s ", int " c ); .fi .sp .in -4n glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR memrchr (): .BR rawmemchr (): _GNU_SOURCE .SH 説明 .BR memchr () 関数は、ポインタ \fIs\fP が指し示すメモリブロックの 先頭の \fIn\fP バイトから文字 \fIc\fP を探す。 最初に \fIc\fP (unsigned char と解釈される) が見つかった時点で動作が停止する。 .PP .BR memrchr () 関数は .BR memchr () 関数に似ているが、 先頭から順方向に探すのではなく、 ポインタ \fIs\fP が指し示す \fIn\fP バイトのメモリブロックの 末尾から逆向きに探す。 .BR rawmemchr () 関数は .BR memchr () と同様だが、 文字 .I c が文字列 .I s 内のどこかにあることを前提にして (つまり、プログラマはそのことを知っている)、 最適化した方法で文字 .I c の検索を実行する (すなわち、終端の NULL バイトのチェックも行われないし、 検索範囲の上限を示す引き数 .I n も使用されない)。 文字 .I c が文字列 .I s 内にない場合、 .BR rawmemchr () は文字列末尾を越えて検索を実行するかもしれず、結果は不定である。 次に示す呼び出しは、文字列終端の NULL バイトの位置を特定する 高速な手段である。 .in +4n .nf char *p = rawmemchr(s,\ \(aq\\0\(aq); .fi .in .SH 返り値 .BR memchr () 関数と .BR memrchr () 関数は一致する文字へのポインタを返し、 もし文字が指定メモリ領域に現れない場合は NULL を返す。 .BR rawmemchr () 関数はマッチするバイトが見つかった場合はマッチしたバイトへのポインタを返す。 マッチするバイトが見つからなかった場合、結果は不定である。 .SH バージョン .BR rawmemchr () は glibc バージョン 2.1 で初めて登場した。 .BR memrchr () は glibc バージョン 2.2 で初めて登場した。 .SH 準拠 .BR memchr () 関数は SVr4, 4.3BSD, C89, C99, POSIX.1-2001 に準拠する。 .BR memrchr () 関数は GNU 拡張であり、glibc 2.1.91 から使用可能である。 .BR rawmemchr () 関数は GNU 拡張であり、glibc 2.1 から使用可能である。 .SH 関連項目 .BR ffs (3), .BR index (3), .BR rindex (3), .BR strchr (3), .BR strpbrk (3), .BR strrchr (3), .BR strsep (3), .BR strspn (3), .BR strstr (3), .BR wmemchr (3)