| 85 | PBYTE pData, pValue; |
| 86 | PBYTE pKey; |
| 87 | ULONG ulApp, ulValue; |
| 88 | |
| 89 | // query enumeration data |
| 90 | pData = malloc( ulSize); |
| 91 | ulApp = PrfQueryProfileString( HINI_USERPROFILE, appkey, NULL, "", pData, ulSize); |
| 92 | // size includes also 0-terminator |
| 93 | if (ulApp == 0 || ulApp == 1) { |
| 94 | free( pData); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | // data buffer is a null terminated array (double null at end) |
| 99 | pKey = pData; |
| 100 | while (*pKey) { |
| 101 | |
| 102 | // query key value |
| 103 | if (PrfQueryProfileSize( HINI_USERPROFILE, appkey, pKey, &ulValue) && ulValue) { |
| 104 | pValue = malloc( ulValue); |
| 105 | PrfQueryProfileString( HINI_USERPROFILE, appkey, pKey, "", pValue, ulValue); |
| 106 | // if empty value, remove from environment |
| 107 | if (*pValue == 0) |
| 108 | unsetenv( pKey); |
| 109 | else |
| 110 | // add/overwrite to current environment |
| 111 | setenv( pKey, pValue, 1); |
| 112 | free( pValue); |
| 113 | } |
| 114 | |
| 115 | // get next variable |
| 116 | while(*pKey) |
| 117 | pKey++; |
| 118 | pKey++; |
| 119 | } |
| 120 | |
| 121 | //done |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | int _sys_init_environ_ini(void) { |
| 126 | HAB hab; |
| 127 | ULONG ulSize = 0L; |
| 128 | APIRET rc; |
| 129 | PPIB pib; |
| 130 | CHAR Buff[_MAX_PATH]; |
| 131 | CHAR AppKey[_MAX_PATH+10]; |
| 132 | char fname[_MAX_FNAME], ext[_MAX_EXT]; |
| 133 | |
| 134 | // enumerate LIBC global key |
| 135 | if (PrfQueryProfileSize( HINI_USERPROFILE, "KLIBC", NULL, &ulSize) && ulSize) { |
| 136 | rc = __sys_init_environ_ini( "KLIBC", ulSize); |
| 137 | } |
| 138 | |
| 139 | // get executable fullpath |
| 140 | rc = DosGetInfoBlocks( NULL, &pib); |
| 141 | rc = DosQueryModuleName( pib->pib_hmte, sizeof(Buff), Buff); |
| 142 | // extract path info |
| 143 | _splitpath( Buff, NULL, NULL, fname, ext); |
| 144 | |
| 145 | // enumerate LIBC process key |
| 146 | strcpy( AppKey, "KLIBC_"); |
| 147 | strcat( AppKey, fname); |
| 148 | strcat( AppKey, ext); |
| 149 | if (PrfQueryProfileSize( HINI_USERPROFILE, AppKey, NULL, &ulSize) && ulSize) { |
| 150 | rc = __sys_init_environ_ini( AppKey, ulSize); |
| 151 | } |
| 152 | |
| 153 | // enumerate LIBC process full path key |
| 154 | strcpy( AppKey, "KLIBC_"); |
| 155 | strcat( AppKey, Buff); |
| 156 | if (PrfQueryProfileSize( HINI_USERPROFILE, AppKey, NULL, &ulSize) && ulSize) { |
| 157 | rc = __sys_init_environ_ini( AppKey, ulSize); |
| 158 | } |
| 159 | |
| 160 | // done |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | |