2005-05-03  Dmitry V. Levin <ldv@altlinux.org>

	Include additional information about failed operation to error
	messages.
	
	* src/copyin.c (create_final_defers, copyin_regular_file,
	copyin_directory, copyin_device, copyin_link): Include names of
	failed calls to error messages.
	* src/copyout.c (writeout_defered_file, process_copy_out):
	Likewise.
	* src/copypass.c (process_copy_pass): Likewise.
	* src/makepath.c (make_path): Likewise.
	* src/util.c (warn_if_file_changed, get_next_reel,
	add_cdf_double_slashes): Likewise.

diff -uprk.orig cpio-2.6.orig/src/copyin.c cpio-2.6/src/copyin.c
--- cpio-2.6.orig/src/copyin.c	2004-09-08 11:10:02 +0000
+++ cpio-2.6/src/copyin.c	2005-05-03 17:13:56 +0000
@@ -385,12 +385,12 @@ create_final_defers ()
 	}
       if (out_file_des < 0)
 	{
-	  error (0, errno, "%s", d->header.c_name);
+	  error (0, errno, "%s: open", d->header.c_name);
 	  continue;
 	}
 
       if (close (out_file_des) < 0)
-	error (0, errno, "%s", d->header.c_name);
+	error (0, errno, "%s: close", d->header.c_name);
 
       /* File is now copied; set attributes.  */
       if (!no_chown_flag)
@@ -398,15 +398,15 @@ create_final_defers ()
 		    set_owner_flag ? set_owner : d->header.c_uid,
 	       set_group_flag ? set_group : d->header.c_gid) < 0)
 	    && errno != EPERM)
-	  error (0, errno, "%s", d->header.c_name);
+	  error (0, errno, "%s: chown", d->header.c_name);
       /* chown may have turned off some permissions we wanted. */
       if (chmod (d->header.c_name, (int) d->header.c_mode) < 0)
-	error (0, errno, "%s", d->header.c_name);
+	error (0, errno, "%s: chmod", d->header.c_name);
       if (retain_time_flag)
 	{
 	  times.actime = times.modtime = d->header.c_mtime;
 	  if (utime (d->header.c_name, &times) < 0)
-	    error (0, errno, "%s", d->header.c_name);
+	    error (0, errno, "%s: utime", d->header.c_name);
 	}
     }
 }
@@ -509,7 +509,7 @@ copyin_regular_file (struct new_cpio_hea
       
       if (out_file_des < 0)
 	{
-	  error (0, errno, "%s", file_hdr->c_name);
+	  error (0, errno, "%s: open", file_hdr->c_name);
 	  tape_toss_input (in_file_des, file_hdr->c_filesize);
 	  tape_skip_padding (in_file_des, file_hdr->c_filesize);
 	  return;
@@ -558,7 +558,7 @@ copyin_regular_file (struct new_cpio_hea
       delayed_seek_count = 0;
     }
   if (close (out_file_des) < 0)
-    error (0, errno, "%s", file_hdr->c_name);
+    error (0, errno, "%s: close", file_hdr->c_name);
 
   if (archive_format == arf_crcascii)
     {
@@ -573,11 +573,11 @@ copyin_regular_file (struct new_cpio_hea
 		set_owner_flag ? set_owner : file_hdr->c_uid,
 	   set_group_flag ? set_group : file_hdr->c_gid) < 0)
 	&& errno != EPERM)
-      error (0, errno, "%s", file_hdr->c_name);
+      error (0, errno, "%s: chown", file_hdr->c_name);
   
   /* chown may have turned off some permissions we wanted. */
   if (chmod (file_hdr->c_name, (int) file_hdr->c_mode) < 0)
-    error (0, errno, "%s", file_hdr->c_name);
+    error (0, errno, "%s: chmod", file_hdr->c_name);
   
   if (retain_time_flag)
     {
@@ -587,7 +587,7 @@ copyin_regular_file (struct new_cpio_hea
 
       times.actime = times.modtime = file_hdr->c_mtime;
       if (utime (file_hdr->c_name, &times) < 0)
-	error (0, errno, "%s", file_hdr->c_name);
+	error (0, errno, "%s: utime", file_hdr->c_name);
     }
   
   tape_skip_padding (in_file_des, file_hdr->c_filesize);
@@ -667,7 +667,7 @@ copyin_directory(struct new_cpio_header*
 	   (lstat (file_hdr->c_name, &file_stat) != 0) ||
 	   !(S_ISDIR (file_stat.st_mode) ) )
 	{
-	  error (0, errno, "%s", file_hdr->c_name);
+	  error (0, errno, "%s: mkdir/stat", file_hdr->c_name);
 	  return;
 	}
     }
@@ -676,10 +676,10 @@ copyin_directory(struct new_cpio_header*
 		set_owner_flag ? set_owner : file_hdr->c_uid,
 		set_group_flag ? set_group : file_hdr->c_gid) < 0)
 	&& errno != EPERM)
-      error (0, errno, "%s", file_hdr->c_name);
+      error (0, errno, "%s: chown", file_hdr->c_name);
   /* chown may have turned off some permissions we wanted. */
   if (chmod (file_hdr->c_name, (int) file_hdr->c_mode) < 0)
-    error (0, errno, "%s", file_hdr->c_name);
+    error (0, errno, "%s: chmod", file_hdr->c_name);
 #ifdef HPUX_CDF
   if (cdf_flag)
     /* Once we "hide" the directory with the chmod(),
@@ -694,7 +694,7 @@ copyin_directory(struct new_cpio_header*
 
       times.actime = times.modtime = file_hdr->c_mtime;
       if (utime (file_hdr->c_name, &times) < 0)
-	error (0, errno, "%s", file_hdr->c_name);
+	error (0, errno, "%s: utime", file_hdr->c_name);
     }
 }
 
@@ -752,7 +752,7 @@ copyin_device(struct new_cpio_header* fi
     }
   if (res < 0)
     {
-      error (0, errno, "%s", file_hdr->c_name);
+      error (0, errno, "%s: mknod", file_hdr->c_name);
       return;
     }
   if (!no_chown_flag)
@@ -760,10 +760,10 @@ copyin_device(struct new_cpio_header* fi
 		set_owner_flag ? set_owner : file_hdr->c_uid,
 		set_group_flag ? set_group : file_hdr->c_gid) < 0)
 	&& errno != EPERM)
-      error (0, errno, "%s", file_hdr->c_name);
+      error (0, errno, "%s: chown", file_hdr->c_name);
   /* chown may have turned off some permissions we wanted. */
   if (chmod (file_hdr->c_name, file_hdr->c_mode) < 0)
-    error (0, errno, "%s", file_hdr->c_name);
+    error (0, errno, "%s: chmod", file_hdr->c_name);
   if (retain_time_flag)
     {
       struct utimbuf times;		/* For setting file times.  */
@@ -772,7 +772,7 @@ copyin_device(struct new_cpio_header* fi
 
       times.actime = times.modtime = file_hdr->c_mtime;
       if (utime (file_hdr->c_name, &times) < 0)
-	error (0, errno, "%s", file_hdr->c_name);
+	error (0, errno, "%s: utime", file_hdr->c_name);
     }
 }
 
@@ -807,7 +807,7 @@ copyin_link(struct new_cpio_header *file
     }
   if (res < 0)
     {
-      error (0, errno, "%s", file_hdr->c_name);
+      error (0, errno, "%s: symlink", file_hdr->c_name);
       free (link_name);
       return;
     }
@@ -817,7 +817,7 @@ copyin_link(struct new_cpio_header *file
 	     set_group_flag ? set_group : file_hdr->c_gid) < 0)
 	&& errno != EPERM)
       {
-	error (0, errno, "%s", file_hdr->c_name);
+	error (0, errno, "%s: lchown", file_hdr->c_name);
       }
   free (link_name);
 }
diff -uprk.orig cpio-2.6.orig/src/copyout.c cpio-2.6/src/copyout.c
--- cpio-2.6.orig/src/copyout.c	2004-10-14 09:14:03 +0000
+++ cpio-2.6/src/copyout.c	2005-05-03 17:13:56 +0000
@@ -222,7 +222,7 @@ writeout_defered_file (struct new_cpio_h
 		      O_RDONLY | O_BINARY, 0);
   if (in_file_des < 0)
     {
-      error (0, errno, "%s", header->c_name);
+      error (0, errno, "%s: open", header->c_name);
       return;
     }
 
@@ -242,7 +242,7 @@ writeout_defered_file (struct new_cpio_h
   tape_pad_output (out_file_des, file_hdr.c_filesize);
 
   if (close (in_file_des) < 0)
-    error (0, errno, "%s", header->c_name);
+    error (0, errno, "%s: close", header->c_name);
   if (reset_time_flag)
     {
       times.actime = file_hdr.c_mtime;
@@ -253,7 +253,7 @@ writeout_defered_file (struct new_cpio_h
          "bug-gnu-utils@prep.ai.mit.edu".  -BEM */
       if (utime (file_hdr.c_name, &times) < 0
 	  && errno != EROFS)
-	error (0, errno, "%s", file_hdr.c_name);
+	error (0, errno, "%s: utime", file_hdr.c_name);
     }
   return;
 }
@@ -497,7 +497,7 @@ process_copy_out ()
 
       /* Process next file.  */
       if ((*xstat) (input_name.ds_string, &file_stat) < 0)
-	error (0, errno, "%s", input_name.ds_string);
+	error (0, errno, "%s: stat", input_name.ds_string);
       else
 	{
 	  /* Set values in output header.  */
@@ -634,7 +634,7 @@ process_copy_out ()
 				  O_RDONLY | O_BINARY, 0);
 	      if (in_file_des < 0)
 		{
-		  error (0, errno, "%s", input_name.ds_string);
+		  error (0, errno, "%s: open", input_name.ds_string);
 		  continue;
 		}
 
@@ -655,7 +655,7 @@ process_copy_out ()
 	      tape_pad_output (out_file_des, file_hdr.c_filesize);
 
 	      if (close (in_file_des) < 0)
-		error (0, errno, "%s", input_name.ds_string);
+		error (0, errno, "%s: close", input_name.ds_string);
 	      if (reset_time_flag)
 		{
 		  times.actime = file_stat.st_atime;
@@ -667,7 +667,7 @@ process_copy_out ()
                      "bug-gnu-utils@prep.ai.mit.edu".  -BEM */
 		  if (utime (file_hdr.c_name, &times) < 0
 		      && errno != EROFS)
-		    error (0, errno, "%s", file_hdr.c_name);
+		    error (0, errno, "%s: utime", file_hdr.c_name);
 		}
 	      break;
 
@@ -722,7 +722,7 @@ process_copy_out ()
 			              file_stat.st_size);
 		if (link_size < 0)
 		  {
-		    error (0, errno, "%s", input_name.ds_string);
+		    error (0, errno, "%s: readlink", input_name.ds_string);
 		    free (link_name);
 		    continue;
 		  }
diff -uprk.orig cpio-2.6.orig/src/copypass.c cpio-2.6/src/copypass.c
--- cpio-2.6.orig/src/copypass.c	2004-09-06 12:09:04 +0000
+++ cpio-2.6/src/copypass.c	2005-01-05 09:27:53 +0000
@@ -82,7 +82,7 @@ process_copy_pass ()
 
       if ((*xstat) (input_name.ds_string, &in_file_stat) < 0)
 	{
-	  error (0, errno, "%s", input_name.ds_string);
+	  error (0, errno, "%s: stat", input_name.ds_string);
 	  continue;
 	}
 
@@ -150,7 +150,7 @@ process_copy_pass ()
 				  O_RDONLY | O_BINARY, 0);
 	      if (in_file_des < 0)
 		{
-		  error (0, errno, "%s", input_name.ds_string);
+		  error (0, errno, "%s: open", input_name.ds_string);
 		  continue;
 		}
 	      out_file_des = open (output_name.ds_string,
@@ -163,7 +163,7 @@ process_copy_pass ()
 		}
 	      if (out_file_des < 0)
 		{
-		  error (0, errno, "%s", output_name.ds_string);
+		  error (0, errno, "%s: open", output_name.ds_string);
 		  close (in_file_des);
 		  continue;
 		}
@@ -180,9 +180,9 @@ process_copy_pass ()
 		  delayed_seek_count = 0;
 		}
 	      if (close (in_file_des) < 0)
-		error (0, errno, "%s", input_name.ds_string);
+		error (0, errno, "%s: close", input_name.ds_string);
 	      if (close (out_file_des) < 0)
-		error (0, errno, "%s", output_name.ds_string);
+		error (0, errno, "%s: close", output_name.ds_string);
 
 	      /* Set the attributes of the new file.  */
 	      if (!no_chown_flag)
@@ -190,10 +190,10 @@ process_copy_pass ()
 			    set_owner_flag ? set_owner : in_file_stat.st_uid,
 		      set_group_flag ? set_group : in_file_stat.st_gid) < 0)
 		    && errno != EPERM)
-		  error (0, errno, "%s", output_name.ds_string);
+		  error (0, errno, "%s: chown", output_name.ds_string);
 	      /* chown may have turned off some permissions we wanted. */
 	      if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
-		error (0, errno, "%s", output_name.ds_string);
+		error (0, errno, "%s: chmod", output_name.ds_string);
 	      if (reset_time_flag)
 		{
 		  times.actime = in_file_stat.st_atime;
@@ -205,16 +205,16 @@ process_copy_pass ()
                      "bug-gnu-utils@prep.ai.mit.edu".  -BEM */
 		  if (utime (input_name.ds_string, &times) < 0
 		      && errno != EROFS)
-		    error (0, errno, "%s", input_name.ds_string);
+		    error (0, errno, "%s: utime", input_name.ds_string);
 		  if (utime (output_name.ds_string, &times) < 0
 		      && errno != EROFS)
-		    error (0, errno, "%s", output_name.ds_string);
+		    error (0, errno, "%s: utime", output_name.ds_string);
 		}
 	      if (retain_time_flag)
 		{
 		  times.actime = times.modtime = in_file_stat.st_mtime;
 		  if (utime (output_name.ds_string, &times) < 0)
-		    error (0, errno, "%s", output_name.ds_string);
+		    error (0, errno, "%s: utime", output_name.ds_string);
 		}
 	      warn_if_file_changed(input_name.ds_string, in_file_stat.st_size,
                                    in_file_stat.st_mtime);
@@ -261,7 +261,7 @@ process_copy_pass ()
       		   (lstat (output_name.ds_string, &out_file_stat) != 0) ||
 	           !(S_ISDIR (out_file_stat.st_mode) ) )
 		{
-		  error (0, errno, "%s", output_name.ds_string);
+		  error (0, errno, "%s: mkdir/lstat", output_name.ds_string);
 		  continue;
 		}
 	    }
@@ -270,10 +270,10 @@ process_copy_pass ()
 			set_owner_flag ? set_owner : in_file_stat.st_uid,
 		      set_group_flag ? set_group : in_file_stat.st_gid) < 0)
 		&& errno != EPERM)
-	      error (0, errno, "%s", output_name.ds_string);
+	      error (0, errno, "%s: chown", output_name.ds_string);
 	  /* chown may have turned off some permissions we wanted. */
 	  if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
-	    error (0, errno, "%s", output_name.ds_string);
+	    error (0, errno, "%s: chmod", output_name.ds_string);
 #ifdef HPUX_CDF
 	  if (cdf_flag)
 	    /* Once we "hide" the directory with the chmod(),
@@ -284,7 +284,7 @@ process_copy_pass ()
 	    {
 	      times.actime = times.modtime = in_file_stat.st_mtime;
 	      if (utime (output_name.ds_string, &times) < 0)
-		error (0, errno, "%s", output_name.ds_string);
+		error (0, errno, "%s: utime", output_name.ds_string);
 	    }
 	}
       else if (S_ISCHR (in_file_stat.st_mode) ||
@@ -321,7 +321,7 @@ process_copy_pass ()
 		}
 	      if (res < 0)
 		{
-		  error (0, errno, "%s", output_name.ds_string);
+		  error (0, errno, "%s: mknod", output_name.ds_string);
 		  continue;
 		}
 	      if (!no_chown_flag)
@@ -329,15 +329,15 @@ process_copy_pass ()
 			    set_owner_flag ? set_owner : in_file_stat.st_uid,
 			  set_group_flag ? set_group : in_file_stat.st_gid) < 0)
 		    && errno != EPERM)
-		  error (0, errno, "%s", output_name.ds_string);
+		  error (0, errno, "%s: chown", output_name.ds_string);
 	      /* chown may have turned off some permissions we wanted. */
 	      if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
-		error (0, errno, "%s", output_name.ds_string);
+		error (0, errno, "%s: chmod", output_name.ds_string);
 	      if (retain_time_flag)
 		{
 		  times.actime = times.modtime = in_file_stat.st_mtime;
 		  if (utime (output_name.ds_string, &times) < 0)
-		    error (0, errno, "%s", output_name.ds_string);
+		    error (0, errno, "%s: utime", output_name.ds_string);
 		}
 	    }
 	}
@@ -353,7 +353,7 @@ process_copy_pass ()
 			        in_file_stat.st_size);
 	  if (link_size < 0)
 	    {
-	      error (0, errno, "%s", input_name.ds_string);
+	      error (0, errno, "%s: readlink", input_name.ds_string);
 	      free (link_name);
 	      continue;
 	    }
@@ -369,7 +369,7 @@ process_copy_pass ()
 	    }
 	  if (res < 0)
 	    {
-	      error (0, errno, "%s", output_name.ds_string);
+	      error (0, errno, "%s: symlink", output_name.ds_string);
 	      free (link_name);
 	      continue;
 	    }
@@ -380,7 +380,7 @@ process_copy_pass ()
 			 set_owner_flag ? set_owner : in_file_stat.st_uid,
 		      set_group_flag ? set_group : in_file_stat.st_gid) < 0)
 		&& errno != EPERM)
-	      error (0, errno, "%s", output_name.ds_string);
+	      error (0, errno, "%s: lchown", output_name.ds_string);
 	  free (link_name);
 	}
 #endif
diff -uprk.orig cpio-2.6.orig/src/makepath.c cpio-2.6/src/makepath.c
--- cpio-2.6.orig/src/makepath.c	2004-09-17 10:44:13 +0000
+++ cpio-2.6/src/makepath.c	2005-01-05 09:29:08 +0000
@@ -164,7 +164,7 @@ make_path (char *argpath,
 #endif
 		      )
 		    {
-		      error (0, errno, "%s", dirpath);
+		      error (0, errno, "%s: chown", dirpath);
 		      retval = 1;
 		    }
 		  if (re_protect)
@@ -231,14 +231,14 @@ make_path (char *argpath,
 #endif
 	      )
 	    {
-	      error (0, errno, "%s", dirpath);
+	      error (0, errno, "%s: chown", dirpath);
 	      retval = 1;
 	    }
 	}
 	  /* chown may have turned off some permission bits we wanted.  */
 	  if ((mode & 07000) != 0 && chmod (dirpath, mode))
 	    {
-	      error (0, errno, "%s", dirpath);
+	      error (0, errno, "%s: chmod", dirpath);
 	      retval = 1;
 	    }
 
@@ -255,7 +255,7 @@ make_path (char *argpath,
 	     bit so we don't break HP CDF's.  */
 	  if (chmod (dirpath, parent_mode))
 	    {
-	      error (0, errno, "%s", dirpath);
+	      error (0, errno, "%s: chmod", dirpath);
 	      retval = 1;
 	    }
 #endif
@@ -286,12 +286,12 @@ make_path (char *argpath,
 #endif
 	  )
 	{
-	  error (0, errno, "%s", dirpath);
+	  error (0, errno, "%s: chown", dirpath);
 	  retval = 1;
 	}
       if (chmod (dirpath, mode))
 	{
-	  error (0, errno, "%s", dirpath);
+	  error (0, errno, "%s: chmod", dirpath);
 	  retval = 1;
 	}
     }
diff -uprk.orig cpio-2.6.orig/src/util.c cpio-2.6/src/util.c
--- cpio-2.6.orig/src/util.c	2004-09-08 10:44:49 +0000
+++ cpio-2.6/src/util.c	2005-01-05 09:28:19 +0000
@@ -550,7 +550,7 @@ warn_if_file_changed (char *file_name, u
   struct stat new_file_stat;
   if ((*xstat) (file_name, &new_file_stat) < 0)
     {
-      error (0, errno, "%s", file_name);
+      error (0, errno, "%s: stat", file_name);
       return;
     }
 
@@ -907,7 +907,7 @@ get_next_reel (int tape_des)
 
 	  tape_des = open_archive (next_archive_name);
 	  if (tape_des == -1)
-	    error (0, errno, "%s", next_archive_name);
+	    error (0, errno, "%s: open_archive", next_archive_name);
 	}
       while (tape_des < 0);
     }
@@ -1055,7 +1055,7 @@ add_cdf_double_slashes (char *input_name
   *p = '\0';
   if ((*xstat) (input_name, &dir_stat) < 0)
     {
-      error (0, errno, "%s", input_name);
+      error (0, errno, "%s: stat", input_name);
       return input_name;
     }
 
@@ -1081,7 +1081,7 @@ add_cdf_double_slashes (char *input_name
 	  *p = '\0';
 	  if ((*xstat) (input_name, &dir_stat) < 0)
 	    {
-	      error (0, errno, "%s", input_name);
+	      error (0, errno, "%s: stat", input_name);
 	      return input_name;
 	    }
 	  *p = '/';
