MCPcopy Create free account
hub / github.com/Tencent/libco / setenv

Function setenv

co_hook_sys_call.cpp:772–803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

770}
771
772int setenv(const char *n, const char *value, int overwrite)
773{
774 HOOK_SYS_FUNC( setenv )
775 if( co_is_enable_sys_hook() && g_co_sysenv.data )
776 {
777 stCoRoutine_t *self = co_self();
778 if( self )
779 {
780 if( !self->pvEnv )
781 {
782 self->pvEnv = dup_co_sysenv_arr( &g_co_sysenv );
783 }
784 stCoSysEnvArr_t *arr = (stCoSysEnvArr_t*)(self->pvEnv);
785
786 stCoSysEnv_t name = { (char*)n,0 };
787
788 stCoSysEnv_t *e = (stCoSysEnv_t*)bsearch( &name,arr->data,arr->cnt,sizeof(name),co_sysenv_comp );
789
790 if( e )
791 {
792 if( overwrite || !e->value )
793 {
794 if( e->value ) free( e->value );
795 e->value = ( value ? strdup( value ) : 0 );
796 }
797 return 0;
798 }
799 }
800
801 }
802 return g_sys_setenv_func( n,value,overwrite );
803}
804int unsetenv(const char *n)
805{
806 HOOK_SYS_FUNC( unsetenv )

Callers 1

SetAndGetEnvFunction · 0.85

Calls 3

co_is_enable_sys_hookFunction · 0.85
co_selfFunction · 0.85
dup_co_sysenv_arrFunction · 0.85

Tested by

no test coverage detected