鱼C论坛

 找回密码
 立即注册
查看: 2677|回复: 1

printf.c定义完全看不懂

[复制链接]
发表于 2021-5-11 09:41:25 | 显示全部楼层 |阅读模式
50鱼币
/***
*printf.c - print formatted
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       defines printf() - print formatted data
*
*******************************************************************************/

#include <cruntime.h>
#include <stdio.h>
#include <dbgint.h>
#include <stdarg.h>
#include <file2.h>
#include <internal.h>
#include <mtdll.h>
#include <stddef.h>
#include <process.h>

/***
*int printf(format, ...) - print formatted data
Int printf (format,...)-打印格式化数据
*
*Purpose:
目的
*       Prints formatted data on stdout using the format string to
*       format data and getting as many arguments as called for
*       Uses temporary buffering to improve efficiency.
                使用格式化字符串格式化数据并获取所需的参数,以便使用临时缓冲提高效率,从而在标准输出上打印格式化数据。
*       _output does the real work here
                输出在这里做真正的工作
*
*Entry:
条目
*       char *format - format string to control data format/number of arguments
*       followed by list of arguments, number and type controlled by
*       format string
                Char * format-format 字符串,用于控制数据格式/参数数量,后面是参数列表、参数数量和由格式字符串控制的类型
*
*Exit:
出口
*       returns number of characters printed
                返回打印的字符数
*
*Exceptions:
例外
*
*******************************************************************************/

int __cdecl printf (const char *format,...)
/*
__cdecl 是 C Declaration  的缩写,表示 C 语言默认的函数调用方法:
所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈。
被调用函数不会要求调用者传递多少参数,调用者传递过多或者过少的参数,甚至完全不同的参数都不会产生编译阶段的错误
------------------------------------------------
(const char *format,...)
const :声明只读变量
只读 char 型 *format 指针参数,
...可变参数
*/
/*
* stdout 'PRINT', 'F'ormatted
*/
{
        va_list arglist;
/*
        va_list 是在C语言中解决变参问题的一组宏,所在头文件:#include <stdarg.h>,用于获取不确定个数的参数
*/
        int buffing;
        int retval;

        第一句就懵逼了...希望有大神能讲解下越详细越好,学习学习大家都认可的函数是怎么编写的
        劳烦了...


        _VALIDATE_RETURN((format != NULL), EINVAL, -1);
        va_start(arglist, format);
        _lock_str2(1, stdout);
               
        __try
        {
        buffing = _stbuf(stdout);
        retval = _output_l(stdout,format,NULL,arglist);
        _ftbuf(buffing, stdout);
        }

                __finally
        {
                        _unlock_str2(1, stdout);
        }
        return(retval);
}

int __cdecl _printf_l (const char *format,_locale_t plocinfo,...)
{
    va_list arglist;
    va_start(arglist, plocinfo);
    return _vprintf_l(format, plocinfo, arglist);
}


int __cdecl _printf_s_l (const char *format,_locale_t plocinfo,...)
{
    va_list arglist;
    va_start(arglist, plocinfo);
    return _vprintf_s_l(format, plocinfo, arglist);
}

int __cdecl printf_s (const char *format,...)
{
    va_list arglist;
    va_start(arglist, format);
    return _vprintf_s_l(format, NULL, arglist);
}

int __cdecl _printf_p_l (const char *format,_locale_t plocinfo,...)
{
    va_list arglist;
    va_start(arglist, plocinfo);
    return _vprintf_p_l(format, plocinfo, arglist);
}

int __cdecl _printf_p (const char *format,...)
{
    va_list arglist;
    va_start(arglist, format);
    return _vprintf_p_l(format, NULL, arglist);
}

static UINT_PTR __enable_percent_n = 0;

/***
*int _set_printf_count_output(int)
*
*Purpose:
*   Enables or disables %n format specifier for printf family functions
*
*Internals:
*   __enable_percent_n is set to (__security_cookie|1) for security reasons;
*   if set to a static value, an attacker could first modify __enable_percent_n
*   and then provide a malicious %n specifier.  The cookie is ORed with 1
*   because a zero cookie is a possibility.
******************************************************************************/
int __cdecl _set_printf_count_output(int value)
{
    int old = (__enable_percent_n == (__security_cookie | 1));
    __enable_percent_n = (value ? (__security_cookie | 1) : 0);
    return old;
}

/***
*int _get_printf_count_output()
*
*Purpose:
*   Checks whether %n format specifier for printf family functions is enabled
******************************************************************************/
int __cdecl _get_printf_count_output()
{
    return ( __enable_percent_n == (__security_cookie | 1));
}

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-5-11 11:22:39 | 显示全部楼层
看不懂还能怎么办?
看不懂是因为你的等级还不够
继续 “打怪升级” 吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 11:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表