Bugzilla bug #25982: renamed the new PR_PutEnv() function to PR_SetEnv()

and resurrected the original Mac-specific PR_PutEnv().
Modified files: prenv.h, prenv.c, pr/tests/env.c
This commit is contained in:
wtc%netscape.com 2000-08-30 17:06:04 +00:00
Родитель 48b22f761d
Коммит 435e14fa0c
3 изменённых файлов: 42 добавлений и 25 удалений

Просмотреть файл

@ -72,7 +72,7 @@ PR_BEGIN_EXTERN_C
** other platforms, a subsequent call to getenv() returns a
** pointer to a null-string (a byte of zero).
**
** PR_GetEnv(), PR_PutEnv() provide a consistent behavior
** PR_GetEnv(), PR_SetEnv() provide a consistent behavior
** across all supported platforms. There are, however, some
** restrictions and some practices you must use to achieve
** consistent results everywhere.
@ -82,9 +82,9 @@ PR_BEGIN_EXTERN_C
** you interpret the return of a pointer to null-string to
** mean the same as a return of NULL from PR_GetEnv().
**
** A call to PR_PutEnv() where the parameter is of the form
** A call to PR_SetEnv() where the parameter is of the form
** "name" will return PR_FAILURE; the environment remains
** unchanged. A call to PR_PutEnv() where the parameter is
** unchanged. A call to PR_SetEnv() where the parameter is
** of the form "name=" may un-set the envrionment variable on
** some platforms; on others it may set the value of the
** environment variable to the null-string.
@ -99,10 +99,10 @@ PR_BEGIN_EXTERN_C
** }
**
** The caller must ensure that the string passed
** to PR_PutEnv() is persistent. That is: The string should
** to PR_SetEnv() is persistent. That is: The string should
** not be on the stack, where it can be overwritten
** on return from the function calling PR_PutEnv().
** Similarly, the string passed to PR_PutEnv() must not be
** on return from the function calling PR_SetEnv().
** Similarly, the string passed to PR_SetEnv() must not be
** overwritten by other actions of the process. ... Some
** platforms use the string by reference rather than copying
** it into the environment space. ... You have been warned!
@ -120,10 +120,10 @@ PR_BEGIN_EXTERN_C
NSPR_API(char*) PR_GetEnv(const char *var);
/*
** PR_PutEnv() -- set, unset or change an environment variable
** PR_SetEnv() -- set, unset or change an environment variable
**
** Description:
** PR_PutEnv() is modeled on the Unix putenv() function.
** PR_SetEnv() is modeled on the Unix putenv() function.
**
** Inputs:
** string -- pointer to a caller supplied
@ -140,7 +140,14 @@ NSPR_API(char*) PR_GetEnv(const char *var);
**
**
*/
NSPR_API(PRStatus) PR_PutEnv(const char *string);
NSPR_API(PRStatus) PR_SetEnv(const char *string);
/*
** DEPRECATED. Use PR_SetEnv() instead.
*/
#ifdef XP_MAC
NSPR_API(PRIntn) PR_PutEnv(const char *string);
#endif
PR_END_EXTERN_C

Просмотреть файл

@ -72,7 +72,7 @@ PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
return ev;
}
PR_IMPLEMENT(PRStatus) PR_PutEnv(const char *string)
PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string)
{
PRIntn result;
@ -85,3 +85,13 @@ PR_IMPLEMENT(PRStatus) PR_PutEnv(const char *string)
_PR_UNLOCK_ENV();
return (result)? PR_FAILURE : PR_SUCCESS;
}
/*
** DEPRECATED. Use PR_SetEnv() instead.
*/
#ifdef XP_MAC
PR_IMPLEMENT(PRIntn) PR_PutEnv(const char *string)
{
return (PR_SetEnv(string) == PR_SUCCESS) ? PR_TRUE : PR_FALSE;
}
#endif

Просмотреть файл

@ -124,12 +124,12 @@ PRIntn main(PRIntn argc, char *argv[])
/* set an environment variable, read it back */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "=" ENVVALUE );
rc = PR_PutEnv( envBuf );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
if (debug) printf( "env: PR_PutEnv() failed setting\n");
if (debug) printf( "env: PR_SetEnv() failed setting\n");
failedAlready = PR_TRUE;
} else {
if (verbose) printf("env: PR_PutEnv() worked.\n");
if (verbose) printf("env: PR_SetEnv() worked.\n");
}
value = PR_GetEnv( ENVNAME );
@ -144,11 +144,11 @@ PRIntn main(PRIntn argc, char *argv[])
/* un-set the variable, using RAW name... should not work */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME );
rc = PR_PutEnv( envBuf );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
if (verbose) printf( "env: PR_PutEnv() not un-set using RAW name. Good!\n");
if (verbose) printf( "env: PR_SetEnv() not un-set using RAW name. Good!\n");
} else {
if (debug) printf("env: PR_PutEnv() un-set using RAW name. Bad!\n" );
if (debug) printf("env: PR_SetEnv() un-set using RAW name. Bad!\n" );
failedAlready = PR_TRUE;
}
@ -164,23 +164,23 @@ PRIntn main(PRIntn argc, char *argv[])
/* set it again ... */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "=" ENVVALUE );
rc = PR_PutEnv( envBuf );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
if (debug) printf( "env: PR_PutEnv() failed setting the second time.\n");
if (debug) printf( "env: PR_SetEnv() failed setting the second time.\n");
failedAlready = PR_TRUE;
} else {
if (verbose) printf("env: PR_PutEnv() worked.\n");
if (verbose) printf("env: PR_SetEnv() worked.\n");
}
/* un-set the variable using the form name= */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "=" );
rc = PR_PutEnv( envBuf );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
if (debug) printf( "env: PR_PutEnv() failed un-setting using name=\n");
if (debug) printf( "env: PR_SetEnv() failed un-setting using name=\n");
failedAlready = PR_TRUE;
} else {
if (verbose) printf("env: PR_PutEnv() un-set using name= worked\n" );
if (verbose) printf("env: PR_SetEnv() un-set using name= worked\n" );
}
value = PR_GetEnv( ENVNAME );
@ -194,12 +194,12 @@ PRIntn main(PRIntn argc, char *argv[])
/* un-set the variable using the form name= */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "999=" );
rc = PR_PutEnv( envBuf );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
if (debug) printf( "env: PR_PutEnv() failed un-setting using name=\n");
if (debug) printf( "env: PR_SetEnv() failed un-setting using name=\n");
failedAlready = PR_TRUE;
} else {
if (verbose) printf("env: PR_PutEnv() un-set using name= worked\n" );
if (verbose) printf("env: PR_SetEnv() un-set using name= worked\n" );
}
value = PR_GetEnv( ENVNAME "999" );