Reputation: 3214
I was reading libcurl and I ran into one unclear thing. There is one function 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)
But I can't get, what for?
Standard functions of C language are supported everywhere/on all platforms, where C language is supported.
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?
Upvotes: 3
Views: 252
Reputation: 4446
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 -):
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);
}
Upvotes: 4
Reputation: 92311
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.
Upvotes: 1