From ee2210476229e156c02f4f886e92b3985b9f7cbe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 6 Nov 2014 07:00:23 -0600 Subject: [PATCH] Can't use formal parameter name 'template' in stdlib.h. Causes C++ compilation errors. Noted by Lorenz Meier --- include/cxx/cstdlib | 30 ++++++++++++++++++++++++++++++ include/stdlib.h | 4 ++-- libc/stdlib/lib_mkstemp.c | 28 ++++++++++++++-------------- libc/stdlib/lib_mktemp.c | 4 ++-- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/include/cxx/cstdlib b/include/cxx/cstdlib index 1bf8ed9da5..d7167d2e4c 100644 --- a/include/cxx/cstdlib +++ b/include/cxx/cstdlib @@ -49,10 +49,15 @@ namespace std { + // Random number generation + using ::srand; using ::rand; + // Environment variable support + #ifndef CONFIG_DISABLE_ENIVRON + using ::get_environ_ptr; using ::getenv; using ::putenv; using ::clearenv; @@ -60,6 +65,8 @@ namespace std using ::unsetenv; #endif + // Process exit functions + using ::exit; using ::abort; #ifdef CONFIG_SCHED_ATEXIT @@ -69,10 +76,22 @@ namespace std using ::on_exit; #endif + // String to binary conversions + using ::strtol; using ::strtoul; +#ifdef CONFIG_HAVE_LONG_LONG + using ::strtoll; + using ::strtoull; +#endif using ::strtod; + // Binary to string conversions + + using ::itoa; + + // Memory Management + using ::malloc; using ::free; using ::realloc; @@ -80,6 +99,17 @@ namespace std using ::zalloc; using ::calloc; using ::mallinfo; + + // Misc. + + using ::abs; + using ::labs; +#ifdef CONFIG_HAVE_LONG_LONG + using ::llabs; +#endif + using ::mktemp; + using ::mkstemp; + using ::qsort; } #endif // __INCLUDE_CXX_CSTDLIB diff --git a/include/stdlib.h b/include/stdlib.h index c149e0ac11..16a3f935b3 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -182,8 +182,8 @@ long int labs(long int j); #ifdef CONFIG_HAVE_LONG_LONG long long int llabs(long long int j); #endif -int mktemp(FAR char *template); -int mkstemp(FAR char *template); +int mktemp(FAR char *path_template); +int mkstemp(FAR char *path_template); /* Sorting */ diff --git a/libc/stdlib/lib_mkstemp.c b/libc/stdlib/lib_mkstemp.c index 3269463f5f..729dfa5354 100644 --- a/libc/stdlib/lib_mkstemp.c +++ b/libc/stdlib/lib_mkstemp.c @@ -195,18 +195,18 @@ static void copy_base62(FAR char *dest, int len) * * Description: * The mkstemp() function replaces the contents of the string pointed to - * by template by a unique filename, and returns a file descriptor for the - * file open for reading and writing. The function thus prevents any - * possible race condition between testing whether the file exists and - * opening it for use. The string in template should look like a filename - * with six trailing 'X' s; mkstemp() replaces each 'X' with a character - * from the portable filename character set. The characters are chosen - * such that the resulting name does not duplicate the name of an existing - * file at the time of a call to mkstemp(). + * by path_template by a unique filename, and returns a file descriptor + * for the file open for reading and writing. The function thus prevents + * any possible race condition between testing whether the file exists and + * opening it for use. The string in path_template should look like a + * filename with six trailing 'X' s; mkstemp() replaces each 'X' with a + * character from the portable filename character set. The characters are + * chosen such that the resulting name does not duplicate the name of an + * existing file at the time of a call to mkstemp(). * * Input Parameters: - * template - The base file name that will be modified to produce the - * unique file name. This must be a full path beginning with /tmp. + * path_template - The base file name that will be modified to produce + * the unique file name. This must be a full path beginning with /tmp. * This function will modify only the first XXXXXX characters within * that full path. * @@ -217,7 +217,7 @@ static void copy_base62(FAR char *dest, int len) * ****************************************************************************/ -int mkstemp(FAR char *template) +int mkstemp(FAR char *path_template) { uint8_t base62[MAX_XS]; uint32_t retries; @@ -229,12 +229,12 @@ int mkstemp(FAR char *template) /* Count the number of X's at the end of the template */ - xptr = strchr(template, 'X'); + xptr = strchr(path_template, 'X'); if (!xptr) { /* No Xs? There should always really be 6 */ - return open(template, O_RDWR | O_CREAT | O_EXCL, 0666); + return open(path_template, O_RDWR | O_CREAT | O_EXCL, 0666); } /* There is at least one.. count all of them */ @@ -279,7 +279,7 @@ int mkstemp(FAR char *template) * directories */ - fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0666); + fd = open(path_template, O_RDWR | O_CREAT | O_EXCL, 0666); if (fd >= 0) { /* We have it... return the file descriptor */ diff --git a/libc/stdlib/lib_mktemp.c b/libc/stdlib/lib_mktemp.c index 705c5cb9e3..2559f99cbf 100644 --- a/libc/stdlib/lib_mktemp.c +++ b/libc/stdlib/lib_mktemp.c @@ -65,9 +65,9 @@ * ****************************************************************************/ -int mktemp(FAR char *template) +int mktemp(FAR char *path_template) { - int fd = mkstemp(template); + int fd = mkstemp(path_template); if (fd < 0) { return ERROR;