xiaoxiang781216 commented on code in PR #21046:
URL: https://github.com/apache/nuttx/pull/21046#discussion_r4389033721
##########
libs/libc/stdlib/lib_mkstemp.c:
##########
@@ -27,14 +27,123 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
-#include <unistd.h>
-#include <stdlib.h>
+#include <errno.h>
#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* mktemp() replaces at most six X's */
+
+#define MKSTEMP_MAXXS 6
+
+/* The number of names that are tried when the file exists */
+
+#define MKSTEMP_RETRIES 238328 /* 62**3 */
/****************************************************************************
* Public Functions
****************************************************************************/
+/****************************************************************************
+ * Name: mkostemps
+ *
+ * Description:
+ * Replace the X's (up to six) before the last suffixlen characters of
+ * path_template with characters that make the name unique, then create
+ * and open the file for reading and writing. If another process created
+ * a file of that name in the meantime, try a new name.
+ *
+ * Input Parameters:
+ * path_template - The name of the file to create, with the X's.
+ * suffixlen - The number of characters after the X's.
+ * flags - More flags for open(), such as O_CLOEXEC or O_APPEND.
+ *
+ * Returned Value:
+ * An open file descriptor on success. Otherwise -1 is returned and
+ * errno is set.
+ *
+ ****************************************************************************/
+
+int mkostemps(FAR char *path_template, int suffixlen, int flags)
+{
+ char suffix0;
+ size_t len = strlen(path_template);
+ size_t end;
+ int retries;
+ int xlen;
+ int fd;
+
+ if (suffixlen < 0 || (size_t)suffixlen > len)
+ {
+ set_errno(EINVAL);
+ return -1;
+ }
+
+ /* Count the X's before the suffix */
+
+ end = len - suffixlen;
+ for (xlen = 0; xlen < MKSTEMP_MAXXS && (size_t)xlen < end &&
Review Comment:
xlen->size_t and remove the cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]