[BACK]Return to fmtcheck.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Annotation of src/lib/libc/gen/fmtcheck.3, Revision 1.4

1.4     ! wiz         1: .\"    $NetBSD: fmtcheck.3,v 1.3 2002/10/01 16:48:34 wiz Exp $
1.1       briggs      2: .\"
                      3: .\" Copyright (c) 2000 The NetBSD Foundation, Inc.
                      4: .\" All rights reserved.
                      5: .\"
                      6: .\" This file was contributed to The NetBSD Foundation by Allen Briggs.
                      7: .\"
                      8: .\" Redistribution and use in source and binary forms, with or without
                      9: .\" modification, are permitted provided that the following conditions
                     10: .\" are met:
                     11: .\" 1. Redistributions of source code must retain the above copyright
                     12: .\"    notice, this list of conditions and the following disclaimer.
                     13: .\" 2. Redistributions in binary form must reproduce the above copyright
                     14: .\"    notice, this list of conditions and the following disclaimer in the
                     15: .\"    documentation and/or other materials provided with the distribution.
                     16: .\" 3. All advertising materials mentioning features or use of this software
                     17: .\"    must display the following acknowledgement:
                     18: .\"        This product includes software developed by the NetBSD
                     19: .\"        Foundation, Inc. and its contributors.
                     20: .\" 4. Neither the name of The NetBSD Foundation nor the names of its
                     21: .\"    contributors may be used to endorse or promote products derived
                     22: .\"    from this software without specific prior written permission.
                     23: .\"
                     24: .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     25: .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     26: .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     27: .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     28: .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     29: .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     30: .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     31: .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     32: .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     33: .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     34: .\" POSSIBILITY OF SUCH DAMAGE.
                     35: .\"
                     36: .Dd October 17, 2000
                     37: .Os
                     38: .Dt FMTCHECK 3
                     39: .Sh NAME
                     40: .Nm fmtcheck
                     41: .Nd sanitizes user-supplied printf(3)-style format string
                     42: .Sh LIBRARY
                     43: .Lb libc
                     44: .Sh SYNOPSIS
1.2       ross       45: .Fd #include \*[Lt]stdio.h\*[Gt]
1.1       briggs     46: .Ft const char *
                     47: .Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
                     48: .Sh DESCRIPTION
                     49: The
                     50: .Nm
                     51: function scans
                     52: .Fa fmt_suspect
                     53: and
                     54: .Fa fmt_default
                     55: to determine if
                     56: .Fa fmt_suspect
                     57: will consume the same argument types as
                     58: .Fa fmt_default
                     59: and to ensure that
                     60: .Fa fmt_suspect
                     61: is a valid format string.
                     62: .Pp
                     63: The
                     64: .Xr printf 3
                     65: family of functions can not verify the types of arguments that they are
1.3       wiz        66: passed at run-time.
                     67: In some cases, like
1.1       briggs     68: .Xr catgets 3 ,
                     69: it is useful or necessary to use a user-supplied format string with no
                     70: guarantee that the format string matches the specified parameters.
                     71: .Pp
                     72: The
                     73: .Nm
                     74: function was designed to be used in these cases, as in:
                     75: .Bd -literal -offset indent
                     76: printf(fmtcheck(user_format, standard_format), arg1, arg2);
                     77: .Ed
                     78: .Pp
                     79: In the check, field widths, fillers, precisions, etc. are ignored (unless
                     80: the field width or precision is an asterisk
                     81: .Ql *
1.3       wiz        82: instead of a digit string).
                     83: Also, any text other than the format specifiers is completely ignored.
1.1       briggs     84: .Pp
                     85: Note that the formats may be quite different as long as they accept the
1.3       wiz        86: same parameters.
1.4     ! wiz        87: For example, "%p %o %30s %#llx %-10.*e %n" is
1.1       briggs     88: compatible with "This number %lu %d%% and string %s has %qd numbers
1.3       wiz        89: and %.*g floats (%n)."
                     90: However, "%o" is not equivalent to "%lx" because
1.1       briggs     91: the first requires an integer and the second requires a long.
                     92: .Sh RETURN VALUES
                     93: If
                     94: .Fa fmt_suspect
                     95: is a valid format and consumes the same argument types as
                     96: .Fa fmt_default ,
                     97: then the
                     98: .Nm
                     99: function will return
                    100: .Fa fmt_suspect .
                    101: Otherwise, it will return
                    102: .Fa fmt_default .
                    103: .Sh SEE ALSO
                    104: .Xr printf 3

CVSweb <webmaster@jp.NetBSD.org>