From: Jim Meyering Date: Tue, 25 Jul 2000 22:23:05 +0000 (+0000) Subject: (change_file_owner): Save errno from a possibly failed chown, X-Git-Tag: TEXTUTILS-2_0g~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d86f9d40a52e37e060427dfbcf35b85185ecc066;p=platform%2Fupstream%2Fcoreutils.git (change_file_owner): Save errno from a possibly failed chown, and use that later. Otherwise, errno itself could be clobbered before used. --- diff --git a/src/chown.c b/src/chown.c index 5998fdf4c..0b07bc47f 100644 --- a/src/chown.c +++ b/src/chown.c @@ -199,6 +199,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group, { int fail; int symlink_changed = 1; + int saved_errno; if (S_ISLNK (file_stats.st_mode) && change_symlinks) { @@ -216,6 +217,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group, { fail = chown (file, newuser, newgroup); } + saved_errno = errno; if (verbosity == V_high || (verbosity == V_changes_only && !fail)) { @@ -229,7 +231,7 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group, if (fail) { if (force_silent == 0) - error (0, errno, "%s", file); + error (0, saved_errno, "%s", file); errors = 1; } }