--- posix.c.~1.124.~ 2004-02-21 09:19:52.000000000 +1000 +++ posix.c 2004-02-21 10:30:54.000000000 +1000 @@ -1420,7 +1420,11 @@ #undef FUNC_NAME #endif /* HAVE_SYNC */ +/* crypt() returns a pointer to a static buffer, so we use a mutex to avoid + another thread overwriting that buffer by another call. + OPTIMIZE-ME: Use glibc crypt_r() when available. */ #if HAVE_CRYPT +static scm_t_mutex crypt_mutex; SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0, (SCM key, SCM salt), "Encrypt @var{key} using @var{salt} as the salt value to the\n" @@ -1428,12 +1432,16 @@ #define FUNC_NAME s_scm_crypt { char * p; + SCM ret; SCM_VALIDATE_STRING (1, key); SCM_VALIDATE_STRING (2, salt); + scm_mutex_lock (&crypt_mutex); p = crypt (SCM_STRING_CHARS (key), SCM_STRING_CHARS (salt)); - return scm_makfrom0str (p); + ret = scm_makfrom0str (p); + scm_mutex_unlock (&crypt_mutex); + return ret; } #undef FUNC_NAME #endif /* HAVE_CRYPT */ @@ -1826,6 +1834,10 @@ scm_c_define ("LOCK_NB", SCM_MAKINUM (LOCK_NB)); #endif +#if HAVE_CRYPT + scm_mutex_init (&crypt_mutex, &scm_i_plugin_mutex); +#endif + #include "libguile/cpp_sig_symbols.c" #include "libguile/posix.x" }