aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-14 21:22:10 -0600
committerRob Landley <rob@landley.net>2018-12-14 21:22:10 -0600
commitc2a44fbe073fb13ab9407ac3a072c7b847383b62 (patch)
treeb819f38f764fad30ee6ae1182d8bc054471f9f08 /lib
parentd4017dbd0a422953bc439db467db9c36d5dd4e33 (diff)
downloadtoybox-c2a44fbe073fb13ab9407ac3a072c7b847383b62.tar.gz
Add xrename()
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c2
-rw-r--r--lib/lib.h1
-rw-r--r--lib/xwrap.c5
3 files changed, 7 insertions, 1 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 11acba0d..ad85dc63 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -747,7 +747,7 @@ void replace_tempfile(int fdin, int fdout, char **tempname)
xclose(fdin);
}
xclose(fdout);
- rename(*tempname, temp);
+ xrename(*tempname, temp);
tempfile2zap = (char *)1;
free(*tempname);
free(temp);
diff --git a/lib/lib.h b/lib/lib.h
index 6dc2ca2b..5d806508 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -138,6 +138,7 @@ int xrun(char **argv);
int xpspawn(char **argv, int*pipes);
void xaccess(char *path, int flags);
void xunlink(char *path);
+void xrename(char *from, char *to);
int xtempfile(char *name, char **tempname);
int xcreate(char *path, int flags, int mode);
int xopen(char *path, int flags);
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 2027069d..b2416a4e 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -378,6 +378,11 @@ int notstdio(int fd)
return fd;
}
+void xrename(char *from, char *to)
+{
+ if (rename(from, to)) perror_exit("rename %s -> %s", from, to);
+}
+
int xtempfile(char *name, char **tempname)
{
int fd;