简体   繁体   English

curl_getenv()写这个函数的原因

[英]curl_getenv() reasons of writing this function

I was reading libcurl and I ran into one unclear thing. 我正在阅读libcurl,我遇到了一个不清楚的事情。 There is one function curl_getenv(). 有一个函数curl_getenv()。 It's written that it was done with idea in mind to be a wrapper for the function genenv() from stdlib.h ( full description of this function ) 它写的是为了成为stdlib.h中函数genenv()的包装而完成的想法( 完整描述了这个函数

But I can't get, what for? 但我无法得到,为了什么?
Standard functions of C language are supported everywhere/on all platforms, where C language is supported. 在支持C语言的所有平台上/所有平台上都支持C语言的标准功能。

So, what's the reason to write a wrapper that has the same parameters and doesn't simplify the work with it? 那么,编写具有相同参数但不简化工作的包装器的原因是什么? Isn't it a useless? 这不是没用的吗?

the curl_getenv function is not the same as getenv from c lib, you can see it from the code, i think it's clear -): curl_getenv函数与来自c lib的getenv ,你可以从代码中看到它,我认为很清楚 - ):

static
char *GetEnv(const char *variable)
{
#ifdef _WIN32_WCE
  return NULL;
#else
#ifdef WIN32
  char env[MAX_PATH]; /* MAX_PATH is from windef.h */
  char *temp = getenv(variable);
  env[0] = '\0';
  if(temp != NULL)
    ExpandEnvironmentStringsA(temp, env, sizeof(env));
  return (env[0] != '\0')?strdup(env):NULL;
#else
  char *env = getenv(variable);
#ifdef __VMS
  if(env && strcmp("HOME",variable) == 0)
    env = decc_translate_vms(env);
#endif
  return (env && env[0])?strdup(env):NULL;
#endif
#endif
}

char *curl_getenv(const char *v)
{
  return GetEnv(v);
}

What if the names of the environment variables, or the strings they hold, are slightly different for each platform? 如果每个平台的环境变量名称或它们所包含的字符串略有不同,该怎么办? Then using a wrapper could enable you to hide the differences. 然后使用包装器可以隐藏差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM