From 597b2a381bef7f9d434f16c6b283bfddafa8401f Mon Sep 17 00:00:00 2001 From: Ken Coar Date: Wed, 3 May 2000 17:55:38 +0000 Subject: [PATCH] Use our own buffer for tmpnam() if the platform seems to know about it. Avoids threading and reentrancy problems. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85132 13f79535-47bb-0310-9956-ffa450edef68 --- support/htpasswd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/support/htpasswd.c b/support/htpasswd.c index 65eb53042d..8175ce7c78 100644 --- a/support/htpasswd.c +++ b/support/htpasswd.c @@ -117,6 +117,14 @@ * access it. */ static char *tempfilename; +/* + * If our platform knows about the tmpnam() external buffer size, create + * a buffer to pass in. This is needed in a threaded environment, or + * one that thinks it is (like HP-UX). + */ +#ifdef L_tmpnam +static char tname_buf[L_tmpnam]; +#endif /* * Get a line of input from the user, not including any terminating @@ -517,11 +525,18 @@ int main(int argc, char *argv[]) * We can access the files the right way, and we have a record * to add or update. Let's do it.. */ + errno = 0; +#ifdef L_tmpnam + tempfilename = tmpnam(tname_buf); +#else /* def L_tmpnam */ tempfilename = tmpnam(NULL); +#endif /* def L_tmpnam */ if ((tempfilename == NULL) || (strlen(tempfilename) == 0)) { fprintf(stderr, "%s: unable to generate temporary filename\n", argv[0]); - errno = ENOENT; + if (errno == 0) { + errno = ENOENT; + } perror("tmpnam"); exit(ERR_FILEPERM); } -- 2.50.1