| 770 | } |
| 771 | |
| 772 | int 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 | } |
| 804 | int unsetenv(const char *n) |
| 805 | { |
| 806 | HOOK_SYS_FUNC( unsetenv ) |
no test coverage detected