aboutsummaryrefslogtreecommitdiffstats
path: root/chdir.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-11-01 22:06:40 +0100
committerMattias Andrée <maandree@kth.se>2019-11-01 22:06:40 +0100
commitc57844b08bced71778f38f2346464c3e0836287c (patch)
treee3733b4c99818ee6c77ed3d4d37becf30f92268f /chdir.c
parentUse installed liberror (diff)
downloadliberror-libc-c57844b08bced71778f38f2346464c3e0836287c.tar.gz
liberror-libc-c57844b08bced71778f38f2346464c3e0836287c.tar.bz2
liberror-libc-c57844b08bced71778f38f2346464c3e0836287c.tar.xz
Add some functions and add functions with _failed suffix
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'chdir.c')
-rw-r--r--chdir.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/chdir.c b/chdir.c
new file mode 100644
index 0000000..9ed27a4
--- /dev/null
+++ b/chdir.c
@@ -0,0 +1,54 @@
+/* See LICENSE file for copyright and license details. */
+#include "internal.h"
+
+
+void
+liberror_chdir_failed(const char *path)
+{
+ const char *desc;
+ switch (errno) {
+ case EFAULT:
+ if (!path)
+ desc = "Path parameter is NULL";
+ else
+ desc = "Path parameter is an invalid pointer";
+ break;
+ case EACCES:
+ desc = "Search permission is denied for any component of the path";
+ break;
+ case ELOOP:
+ desc = "A symbolic link chain in the path too long or circular";
+ break;
+ case ENAMETOOLONG:
+ desc = "The canonical path or intermediate result in pathname resolution is too long";
+ break;
+ case ENOENT:
+ if (!*path)
+ desc = "Path parameter is the empty string";
+ else
+ desc = "A component of path does not name an existing directory";
+ break;
+ case ENOTDIR:
+ desc = "A component of path is not a directory";
+ break;
+ case ENOMEM:
+ desc = "Insufficient kernel memory was available";
+ break;
+ case EIO:
+ default:
+ desc = "";
+ break;
+ }
+ liberror_libc_set_error_one_file(desc, "chdir", "Directory file", -1, path);
+}
+
+
+int
+liberror_chdir(const char *path)
+{
+ if (!chdir(path))
+ return 0;
+ liberror_save_backtrace(NULL);
+ liberror_chdir_failed(path);
+ return -1;
+}