_dupenv_s_dbg, _wdupenv_s_dbg

获取当前环境的值。 随 _malloc_dbg 的内存提供额外的调试信息 _dupenv_s, _wdupenv_s 的版本。

errno_t _dupenv_s_dbg(
   char **buffer,
   size_t *numberOfElements,
   const char *varname,
   int blockType,
   const char *filename,
   int linenumber
);
errno_t _wdupenv_s_dbg(
   wchar_t **buffer,
   size_t * numberOfElements,
   const wchar_t *varname,
   int blockType,
   const char *filename,
   int linenumber
);

参数

  • buffer
    存储变量值的缓冲区。

  • numberOfElements
    buffer的大小。

  • varname
    环境变量名称。

  • blockType
    请求的内存块类型: _CLIENT_BLOCK 或 _NORMAL_BLOCK。

  • filename
    对源文件或 NULL名称的指针。

  • linenumber
    在源文件级别或 NULL的行号。

返回值

在成功的零,在失败时的错误代码。

这些功能验证方法的参数;如果 buffer 或 varname 是 NULL,无效参数调用处理程序 参数验证如中所述。 如果执行允许继续,对 EINVAL 的功能集 errno 和返回 EINVAL。

如果这些函数不能分配足够的内存,这些设置 buffer 到 NULL 和 numberOfElements 为 0,并返回 ENOMEM。

备注

_dupenv_s_dbg 和 _wdupenv_s_dbg 功能与 _dupenv_s 和 _wdupenv_s 相同,区别在于,那么,当 _DEBUG 定义时,这些功能使用 malloc_malloc_dbg的调试版本,分配环境变量的值的内存。 有关 _malloc_dbg的信息调试功能,请参见 _malloc_dbg

您不需要显式调用这些函数在许多情况下。 相反,您可以定义标志 _CRTDBG_MAP_ALLOC。 当 _CRTDBG_MAP_ALLOC 定义时,对 _dupenv_s,并 _wdupenv_s 已重新映射到 _dupenv_s_dbg 和 _wdupenv_s_dbg,分别,并 blockType 设置为 _NORMAL_BLOCK。 因此,,除非要标记堆块作为 _CLIENT_BLOCK,则无需显式调用这些函数。 有关的更多信息块类型,请参见 调试堆中的块类型

一般文本例程映射

TCHAR.H 实例

未定义的 _UNICODE _MBCS

定义的 _MBCS

定义的 _UNICODE

_tdupenv_s_dbg

_dupenv_s_dbg

_dupenv_s_dbg

_wdupenv_s_dbg

要求

实例

必需的头

_dupenv_s_dbg

crtdbg.h

_wdupenv_s_dbg

crtdbg.h

有关其他的兼容性信息,请参见中介绍的 兼容性

示例

// crt_dupenv_s_dbg.c
#include  <stdlib.h>
#include <crtdbg.h>

int main( void )
{
   char *pValue;
   size_t len;
   errno_t err = _dupenv_s_dbg( &pValue, &len, "pathext",
      _NORMAL_BLOCK, __FILE__, __LINE__ );
   if ( err ) return -1;
   printf( "pathext = %s\n", pValue );
   free( pValue );
   err = _dupenv_s_dbg( &pValue, &len, "nonexistentvariable",
      _NORMAL_BLOCK, __FILE__, __LINE__ );
   if ( err ) return -1;
   printf( "nonexistentvariable = %s\n", pValue );
   free( pValue ); // It's OK to call free with NULL
}

示例输出

pathext = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.pl
nonexistentvariable = (null)

.NET Framework 等效项

系统:: 环境:: GetEnvironmentVariable

请参见

参考

处理和环境控件

环境常数

getenv_s, _wgetenv_s

_putenv_s, _wputenv_s