summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-07-17 13:31:05 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-17 13:46:48 +0100
commitac0373bdecfabe6acf99d3662e5117de73fa2aef (patch)
treec8afd634216061973440aef4a8880545eebb565e
parent4bc110e2bc738bde9b9c09bc602ef13c06b60e90 (diff)
downloadlibguestfs-ac0373bdecfabe6acf99d3662e5117de73fa2aef.tar.gz
libguestfs-ac0373bdecfabe6acf99d3662e5117de73fa2aef.tar.xz
libguestfs-ac0373bdecfabe6acf99d3662e5117de73fa2aef.zip
case_sensitive_path: Move variables to top of function.
This is just code motion.
-rw-r--r--daemon/realpath.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 2d657a4c..edf6da0a 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -84,8 +84,11 @@ char *
do_case_sensitive_path (const char *path)
{
char ret[PATH_MAX+1] = "/";
+ char name[NAME_MAX+1];
size_t next = 1;
- int fd_cwd;
+ int fd_cwd, fd2, err;
+ size_t i;
+ char *retp;
/* 'fd_cwd' here is a surrogate for the current working directory, so
* that we don't have to actually call chdir(2).
@@ -100,7 +103,7 @@ do_case_sensitive_path (const char *path)
* and follow it.
*/
while (*path) {
- size_t i = strcspn (path, "/");
+ i = strcspn (path, "/");
if (i == 0) {
path++;
continue;
@@ -116,7 +119,6 @@ do_case_sensitive_path (const char *path)
goto error;
}
- char name[NAME_MAX+1];
memcpy (name, path, i);
name[i] = '\0';
@@ -143,8 +145,8 @@ do_case_sensitive_path (const char *path)
next += i;
/* Is it a directory? Try going into it. */
- int fd2 = openat (fd_cwd, name, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
- int err = errno;
+ fd2 = openat (fd_cwd, name, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ err = errno;
close (fd_cwd);
fd_cwd = fd2;
errno = err;
@@ -166,7 +168,7 @@ do_case_sensitive_path (const char *path)
close (fd_cwd);
ret[next] = '\0';
- char *retp = strdup (ret);
+ retp = strdup (ret);
if (retp == NULL) {
reply_with_perror ("strdup");
return NULL;