diff options
-rw-r--r-- | ChangeLog.txt | 5 | ||||
-rw-r--r-- | ports/unix/guts/mkostemp.c | 14 | ||||
-rw-r--r-- | ports/unix/guts/mkostemps.c | 55 | ||||
-rw-r--r-- | ports/unix/guts/mkstemp.c | 37 | ||||
-rw-r--r-- | ports/unix/guts/mkstemps.c | 14 | ||||
-rw-r--r-- | ports/unix/wrapfuncs.in | 3 |
6 files changed, 93 insertions, 35 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index 8c886c6..169e707 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,8 @@ +2018-02-26: + * (seebs) implement mkstemps, mkostemp, and mkostemps. Actually, + move implementation all to mkostemps, then implement the others + in terms of it. + 2018-02-19: * (seebs) fix using index of request rather than request's value diff --git a/ports/unix/guts/mkostemp.c b/ports/unix/guts/mkostemp.c new file mode 100644 index 0000000..bce0939 --- /dev/null +++ b/ports/unix/guts/mkostemp.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int mkostemp(char *template, int oflags) + * int rc = -1; + */ + + /* mkostemp = mkostemps() with suffixlen of 0 */ + rc = wrap_mkostemps(template, 0, oflags); + +/* return rc; + * } + */ diff --git a/ports/unix/guts/mkostemps.c b/ports/unix/guts/mkostemps.c new file mode 100644 index 0000000..27ada46 --- /dev/null +++ b/ports/unix/guts/mkostemps.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008-2010, 2012 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * Copyright (c) 2018 Peter Seebach; see + * guts/COPYRIGHT for information. + * + * int mkostemps(char *template, int suffixlen, int oflags) + * int rc = -1; + */ + + PSEUDO_STATBUF 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_mkostemps(tmp_template, suffixlen, oflags); + + if (rc != -1) { + save_errno = errno; + + if (base_fstat(rc, &buf) != -1) { + real_fchmod(rc, PSEUDO_FS_MODE(0600, 0)); + pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf); + pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf); + } else { + pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n", + rc, strerror(errno)); + pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0); + } + errno = save_errno; + } + /* WARNING: At least one system allows the number of Xs to be something + * other than 6. I do not attempt to handle this. + */ + /* mkstemp only changes the XXXXXX at the end, or suffixlen characters before + * the end if mkostemp/mkostemps. + */ + memcpy(template + len - 6 - suffixlen, tmp_template + strlen(tmp_template) - 6 - suffixlen, 6); +/* return rc; + * } + */ diff --git a/ports/unix/guts/mkstemp.c b/ports/unix/guts/mkstemp.c index 1e2b026..8fab58b 100644 --- a/ports/unix/guts/mkstemp.c +++ b/ports/unix/guts/mkstemp.c @@ -6,42 +6,9 @@ * wrap_mkstemp(char *template) { * int rc = -1; */ - PSEUDO_STATBUF buf; - int save_errno; - size_t len; - char *tmp_template; + /* mkstemp() is just like mkostemps() with no flags and no suffix */ + rc = wrap_mkostemps(template, 0, 0); - 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 (base_fstat(rc, &buf) != -1) { - real_fchmod(rc, PSEUDO_FS_MODE(0600, 0)); - pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf); - pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf); - } else { - pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n", - rc, strerror(errno)); - pseudo_client_op(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); /* return rc; * } */ diff --git a/ports/unix/guts/mkstemps.c b/ports/unix/guts/mkstemps.c new file mode 100644 index 0000000..95b3b83 --- /dev/null +++ b/ports/unix/guts/mkstemps.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int mkstemps(char *template, int suffixlen) + * int rc = -1; + */ + + /* mkstemps() is mkostemps() with no flags */ + rc = wrap_mkostemps(template, suffixlen, 0); + +/* return rc; + * } + */ diff --git a/ports/unix/wrapfuncs.in b/ports/unix/wrapfuncs.in index 2addb27..3910fae 100644 --- a/ports/unix/wrapfuncs.in +++ b/ports/unix/wrapfuncs.in @@ -46,6 +46,9 @@ int mkfifoat(int dirfd, const char *path, mode_t mode); /* flags=AT_SYMLINK_NOFO int mknod(const char *path, mode_t mode, dev_t dev); /* flags=AT_SYMLINK_NOFOLLOW */ int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev); /* flags=AT_SYMLINK_NOFOLLOW */ int mkstemp(char *template); /* flags=AT_SYMLINK_NOFOLLOW */ +int mkostemp(char *template, int oflags); /* flags=AT_SYMLINK_NOFOLLOW */ +int mkstemps(char *template, int suffixlen); /* flags=AT_SYMLINK_NOFOLLOW */ +int mkostemps(char *template, int suffixlen, int oflags); /* flags=AT_SYMLINK_NOFOLLOW */ int rename(const char *oldpath, const char *newpath); /* flags=AT_SYMLINK_NOFOLLOW */ int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); /* flags=AT_SYMLINK_NOFOLLOW */ int rmdir(const char *path); /* flags=AT_SYMLINK_NOFOLLOW */ |