Changeset 50642 in vbox
- Timestamp:
- Feb 27, 2014 8:22:26 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92536
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/env.h
r50408 r50642 257 257 RTDECL(char *) RTEnvDupEx(RTENV Env, const char *pszVar); 258 258 259 /** 260 * Counts the variables in the environment. 261 * 262 * @returns Number of variables in the environment. UINT32_MAX on error. 263 * @param hEnv The environment handle. 264 * RTENV_DEFAULT is currently not accepted. 265 */ 266 RTDECL(uint32_t) RTEnvCountEx(RTENV hEnv); 267 268 /** 269 * Queries an environment variable by it's index. 270 * 271 * This can be used together with RTEnvCount to enumerate the environment block. 272 * 273 * @returns IPRT status code. 274 * @retval VERR_ENV_VAR_NOT_FOUND if the index is out of bounds, output buffers 275 * untouched. 276 * @retval VERR_BUFFER_OVERFLOW if one of the buffers are too small. We'll 277 * fill it with as much we can in RTStrCopy fashion. 278 * 279 * @param hEnv The environment handle. 280 * RTENV_DEFAULT is currently not accepted. 281 * @param iVar The variable index. 282 * @param pszVar Variable name buffer. 283 * @param cbVar The size of the variable name buffer. 284 * @param pszValue Value buffer. 285 * @param cbValue The size of the value buffer. 286 */ 287 RTDECL(uint32_t) RTEnvGetByIndexEx(RTENV hEnv, uint32_t iVar, char *pszVar, size_t cbVar, char *pszValue, size_t cbValue); 288 259 289 #endif /* IN_RING3 */ 260 290 -
trunk/include/iprt/mangling.h
r50526 r50642 495 495 # define RTDvmVolumeCreateVfsFile RT_MANGLER(RTDvmVolumeCreateVfsFile) 496 496 # define RTEnvClone RT_MANGLER(RTEnvClone) 497 # define RTEnvCountEx RT_MANGLER(RTEnvCountEx) 497 498 # define RTEnvCreate RT_MANGLER(RTEnvCreate) 498 499 # define RTEnvDestroy RT_MANGLER(RTEnvDestroy) … … 505 506 # define RTEnvGet RT_MANGLER(RTEnvGet) 506 507 # define RTEnvGetBad RT_MANGLER(RTEnvGetBad) 508 # define RTEnvGetByIndexEx RT_MANGLER(RTEnvGetByIndexEx) 507 509 # define RTEnvGetUtf8 RT_MANGLER(RTEnvGetUtf8) 508 510 # define RTEnvGetEx RT_MANGLER(RTEnvGetEx) -
trunk/src/VBox/Runtime/generic/env-generic.cpp
r50408 r50642 234 234 #ifdef RTENV_HAVE_WENVIRON 235 235 papszEnv = NULL; 236 papwszEnv = (PCRTUTF16 * const 236 papwszEnv = (PCRTUTF16 * const)_wenviron; 237 237 if (papwszEnv) 238 238 while (papwszEnv[cVars]) … … 842 842 RT_EXPORT_SYMBOL(RTEnvFreeUtf16Block); 843 843 844 845 RTDECL(uint32_t) RTEnvCountEx(RTENV hEnv) 846 { 847 PRTENVINTERNAL pIntEnv = hEnv; 848 AssertPtrReturn(pIntEnv, UINT32_MAX); 849 AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, UINT32_MAX); 850 851 RTENV_LOCK(pIntEnv); 852 uint32_t cVars = (uint32_t)pIntEnv->cVars; 853 RTENV_UNLOCK(pIntEnv); 854 855 return cVars; 856 } 857 RT_EXPORT_SYMBOL(RTEnvCountEx); 858 859 860 RTDECL(uint32_t) RTEnvGetByIndexEx(RTENV hEnv, uint32_t iVar, char *pszVar, size_t cbVar, char *pszValue, size_t cbValue) 861 { 862 PRTENVINTERNAL pIntEnv = hEnv; 863 AssertPtrReturn(pIntEnv, UINT32_MAX); 864 AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, UINT32_MAX); 865 if (cbVar) 866 AssertPtrReturn(pszVar, VERR_INVALID_POINTER); 867 if (cbValue) 868 AssertPtrReturn(pszValue, VERR_INVALID_POINTER); 869 870 RTENV_LOCK(pIntEnv); 871 872 int rc; 873 if (iVar < pIntEnv->cVars) 874 { 875 const char *pszSrcVar = pIntEnv->papszEnv[iVar]; 876 const char *pszSrcValue = strchr(pszSrcVar, '='); 877 bool fHasEqual = pszSrcValue != NULL; 878 if (pszSrcValue) 879 pszSrcValue++; 880 else 881 pszSrcValue = strchr(pszSrcVar, '\0'); 882 rc = VINF_SUCCESS; 883 if (cbVar) 884 rc = RTStrCopyEx(pszVar, cbVar, pszSrcVar, pszSrcValue - pszSrcVar - fHasEqual); 885 if (cbValue) 886 { 887 int rc2 = RTStrCopy(pszValue, cbValue, pszSrcValue); 888 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 889 rc = rc2; 890 } 891 } 892 else 893 rc = VERR_ENV_VAR_NOT_FOUND; 894 895 RTENV_UNLOCK(pIntEnv); 896 897 return rc; 898 } 899 RT_EXPORT_SYMBOL(RTEnvGetByIndexEx); 900
Note:
See TracChangeset
for help on using the changeset viewer.