Cleanup SHLVL variable
This commit is contained in:
parent
175249b455
commit
eca2100312
35
env.cpp
35
env.cpp
@ -637,35 +637,16 @@ void env_init()
|
|||||||
Set up SHLVL variable
|
Set up SHLVL variable
|
||||||
*/
|
*/
|
||||||
const env_var_t shlvl_str = env_get_string( L"SHLVL" );
|
const env_var_t shlvl_str = env_get_string( L"SHLVL" );
|
||||||
const wchar_t *shlvl = shlvl_str.missing() ? NULL : shlvl_str.c_str();
|
wcstring nshlvl_str = L"1";
|
||||||
|
if (! shlvl_str.missing())
|
||||||
if ( shlvl )
|
|
||||||
{
|
{
|
||||||
wchar_t *nshlvl, **end_nshlvl;
|
long shlvl_i = wcstol(shlvl_str.c_str(), NULL, 10);
|
||||||
/* add an extra space for digit dump (9+1=10) */
|
if (shlvl_i >= 0)
|
||||||
size_t i = wcslen( shlvl ) + 2 * sizeof(wchar_t);
|
{
|
||||||
|
nshlvl_str = format_string(L"%ld", 1 + shlvl_i);
|
||||||
nshlvl = (wchar_t *)malloc(i);
|
}
|
||||||
end_nshlvl = (wchar_t **)calloc( 1, sizeof(nshlvl) );
|
|
||||||
if ( !nshlvl || !end_nshlvl )
|
|
||||||
DIE_MEM();
|
|
||||||
|
|
||||||
if ( nshlvl && swprintf( nshlvl, i,
|
|
||||||
L"%ld", wcstoul( shlvl, end_nshlvl, 10 )+1 ) != -1 )
|
|
||||||
{
|
|
||||||
env_set( L"SHLVL",
|
|
||||||
nshlvl,
|
|
||||||
ENV_GLOBAL | ENV_EXPORT );
|
|
||||||
}
|
|
||||||
free( end_nshlvl );
|
|
||||||
free( nshlvl );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
env_set( L"SHLVL",
|
|
||||||
L"1",
|
|
||||||
ENV_GLOBAL | ENV_EXPORT );
|
|
||||||
}
|
}
|
||||||
|
env_set(L"SHLVL", nshlvl_str.c_str(), ENV_GLOBAL | ENV_EXPORT );
|
||||||
|
|
||||||
/* Set correct defaults for e.g. USER and HOME variables */
|
/* Set correct defaults for e.g. USER and HOME variables */
|
||||||
env_set_defaults();
|
env_set_defaults();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user