summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2005-08-12 14:41:55 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2005-08-12 14:41:55 +0000
commit67f5d1861c0f35e63b722710ed392df56f58e57e (patch)
treee5c731c8190e1ac0380031974fa054d058767284 /usr.bin
parent184f0197af89b634e2f395b0e91cd22ea44d1582 (diff)
add cvs_rename() function; ok jfb
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/cvs.h3
-rw-r--r--usr.bin/cvs/util.c24
2 files changed, 25 insertions, 2 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 6417d02d4f2..5507c93f181 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.78 2005/08/09 10:33:46 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.79 2005/08/12 14:41:54 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -403,6 +403,7 @@ int cvs_cksum(const char *, char *, size_t);
int cvs_exec(int, char **, int []);
int cvs_getargv(const char *, char **, int);
int cvs_chdir(const char *);
+int cvs_rename(const char *, const char *);
int cvs_unlink(const char *);
int cvs_rmdir(const char *);
int cvs_create_dir(const char *, int, char *, char *);
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index e48eb859f55..9969a1a22d7 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.48 2005/07/30 21:16:17 moritz Exp $ */
+/* $OpenBSD: util.c,v 1.49 2005/08/12 14:41:54 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -519,6 +519,28 @@ cvs_chdir(const char *path)
}
/*
+ * cvs_rename()
+ * Change the name of a file.
+ * rename() wrapper with an error message.
+ * Returns 0 on success, or -1 on failure.
+ */
+int
+cvs_rename(const char *from, const char *to)
+{
+ cvs_log(LP_TRACE, "cvs_rename(%s,%s)", from, to);
+
+ if (cvs_noexec == 1)
+ return (0);
+
+ if (rename(from, to) == -1) {
+ cvs_log(LP_ERRNO, "cannot rename file `%s' to `%s'", from, to);
+ return (-1);
+ }
+
+ return (0);
+}
+
+/*
* cvs_unlink()
*
* Removes the link named by <path>.