[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.1

1.1     ! briggs      1: .\"    $NetBSD$
        !             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
        !            45: .Fd #include <stdio.h>
        !            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
        !            66: passed at run-time.  In some cases, like
        !            67: .Xr catgets 3 ,
        !            68: it is useful or necessary to use a user-supplied format string with no
        !            69: guarantee that the format string matches the specified parameters.
        !            70: .Pp
        !            71: The
        !            72: .Nm
        !            73: function was designed to be used in these cases, as in:
        !            74: .Bd -literal -offset indent
        !            75: printf(fmtcheck(user_format, standard_format), arg1, arg2);
        !            76: .Ed
        !            77: .Pp
        !            78: In the check, field widths, fillers, precisions, etc. are ignored (unless
        !            79: the field width or precision is an asterisk
        !            80: .Ql *
        !            81: instead of a digit string).  Also, any text other than the format specifiers
        !            82: is completely ignored.
        !            83: .Pp
        !            84: Note that the formats may be quite different as long as they accept the
        !            85: same parameters.  For example, ".Dq %p %o %30s %#llx %-10.*e %n" is
        !            86: compatible with "This number %lu %d%% and string %s has %qd numbers
        !            87: and %.*g floats (%n)."  However, "%o" is not equivalent to "%lx" because
        !            88: the first requires an integer and the second requires a long.
        !            89: .Sh RETURN VALUES
        !            90: If
        !            91: .Fa fmt_suspect
        !            92: is a valid format and consumes the same argument types as
        !            93: .Fa fmt_default ,
        !            94: then the
        !            95: .Nm
        !            96: function will return
        !            97: .Fa fmt_suspect .
        !            98: Otherwise, it will return
        !            99: .Fa fmt_default .
        !           100: .Sh SEE ALSO
        !           101: .Xr printf 3

CVSweb <webmaster@jp.NetBSD.org>