diff options
Diffstat (limited to 'ports/unix/guts/mkstemp.c')
-rw-r--r-- | ports/unix/guts/mkstemp.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/ports/unix/guts/mkstemp.c b/ports/unix/guts/mkstemp.c new file mode 100644 index 0000000..46c0be1 --- /dev/null +++ b/ports/unix/guts/mkstemp.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_mkstemp(char *template) { + * int rc = -1; + */ + struct stat buf; + int save_errno; + size_t len; + char *tmp_template; + + if (!template) { + errno = EFAULT; + return 0; + } + + len = strlen(template); + tmp_template = PSEUDO_ROOT_PATH(AT_FDCWD, template, AT_SYMLINK_NOFOLLOW); + + if (!tmp_template) { + errno = ENOENT; + return -1; + } + + rc = real_mkstemp(tmp_template); + + if (rc != -1) { + save_errno = errno; + + if (real_fstat(rc, &buf) != -1) { + pseudo_client_op_plain(OP_CREAT, 0, -1, -1, tmp_template, &buf); + pseudo_client_op_plain(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf); + } else { + pseudo_debug(1, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n", + rc, strerror(errno)); + pseudo_client_op_plain(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0); + } + errno = save_errno; + } + /* mkstemp only changes the XXXXXX at the end. */ + memcpy(template + len - 6, tmp_template + strlen(tmp_template) - 6, 6); + free(tmp_template); +/* return rc; + * } + */ |