public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Re: deletion of output files
@ 2004-12-15 12:37 Jan Beulich
  2004-12-15 13:41 ` DJ Delorie
  2004-12-16 12:04 ` Nick Clifton
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Beulich @ 2004-12-15 12:37 UTC (permalink / raw)
  To: ian; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 9251 bytes --]

>I suppose we could make that deletion happen only if the file were a
>regular file.  It seems like a strange exception, and it seems like
it
>would be easy for your script to use a temporary file, but I guess I
>don't really know for sure how it should work.  I see that gcc does
>check whether temporary files are regular files before deleting them
>(DELETE_IF_ORDINARY in gcc.c), which argues that the binutils should
>do the same.
>
>I think that libiberty is the right place for such a function.

Built and tested on i686-pc-linux-gnu.

Jan

bfd/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* Makefile.am: Add dependency of cache.o on libiberty.h.
	* cache.c: Include libiberty.h.
	(bfd_open_file): Use unlink_if_ordinary instead of unlink.

binutils/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* ar.c (remove_output): Use unlink_if_ordinary instead of
unlink.
	* objcopy.c (copy_file): Likewise.
	(strip_main): Likewise.

gas/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* as.c (main): Use unlink_if_ordinary instead of unlink.
	* messages.c (as_fatal): Likewise.

include/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* libiberty.h: Declare unlink_if_ordinary.

ld/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* ldmain.c (remove_output): Use unlink_if_ordinary instead of
unlink.
	* pe-dll.c (pe_dll_generate_implib): Likewise.

libiberty/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* Makefile.in (CFILES): Add unlink-if-ordinary.c
	(REQUIRED_OFILES): Add unlink-if-ordinary.o.
	Add dependencies and rule for unlink-if-ordinary.o.
	* unlink-if-ordinary.c: New.

---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/Makefile.am	2004-11-18
15:05:03.000000000 +0100
+++ 2004-12-03.13.35/bfd/Makefile.am	2004-12-15 12:24:30.392060672
+0100
@@ -903,7 +903,7 @@ bfd.lo: bfd.c bfdver.h $(INCDIR)/filenam
   $(INCDIR)/elf/external.h
 bfdio.lo: bfdio.c $(INCDIR)/filenames.h
 bfdwin.lo: bfdwin.c $(INCDIR)/filenames.h
-cache.lo: cache.c $(INCDIR)/filenames.h
+cache.lo: cache.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h
 coffgen.lo: coffgen.c $(INCDIR)/filenames.h $(INCDIR)/coff/internal.h
\
   libcoff.h $(INCDIR)/bfdlink.h
 corefile.lo: corefile.c $(INCDIR)/filenames.h
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/Makefile.in	2004-11-18
15:05:03.000000000 +0100
+++ 2004-12-03.13.35/bfd/Makefile.in	2004-12-15 12:24:40.276558000
+0100
@@ -1458,7 +1458,7 @@ bfd.lo: bfd.c bfdver.h $(INCDIR)/filenam
   $(INCDIR)/elf/external.h
 bfdio.lo: bfdio.c $(INCDIR)/filenames.h
 bfdwin.lo: bfdwin.c $(INCDIR)/filenames.h
-cache.lo: cache.c $(INCDIR)/filenames.h
+cache.lo: cache.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h
 coffgen.lo: coffgen.c $(INCDIR)/filenames.h $(INCDIR)/coff/internal.h
\
   libcoff.h $(INCDIR)/bfdlink.h
 corefile.lo: corefile.c $(INCDIR)/filenames.h
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/cache.c	2004-06-28
16:51:45.000000000 +0200
+++ 2004-12-03.13.35/bfd/cache.c	2004-12-15 12:24:50.550996048
+0100
@@ -41,6 +41,7 @@ SECTION
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
+#include "libiberty.h"
 
 static bfd_boolean bfd_cache_delete (bfd *);
 
@@ -436,7 +437,7 @@ bfd_open_file (bfd *abfd)
 	  struct stat s;
 
 	  if (stat (abfd->filename, &s) == 0 && s.st_size != 0)
-	    unlink (abfd->filename);
+	    unlink_if_ordinary (abfd->filename);
 #endif
 	  abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WUB);
 	  abfd->opened_once = TRUE;
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/binutils/ar.c	2004-11-02
17:16:01.000000000 +0100
+++ 2004-12-03.13.35/binutils/ar.c	2004-12-15 12:10:35.610966688
+0100
@@ -328,7 +328,7 @@ remove_output (void)
 	bfd_cache_close (output_bfd);
       if (output_file != NULL)
 	fclose (output_file);
-      unlink (output_filename);
+      unlink_if_ordinary (output_filename);
     }
 }
 
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/binutils/objcopy.c	2004-11-02
17:16:02.000000000 +0100
+++ 2004-12-03.13.35/binutils/objcopy.c	2004-12-15
12:22:41.303644632 +0100
@@ -1716,7 +1716,7 @@ copy_file (const char *input_filename, c
 
       if (delete)
 	{
-	  unlink (output_filename);
+	  unlink_if_ordinary (output_filename);
 	  status = 1;
 	}
     }
@@ -2423,7 +2423,7 @@ strip_main (int argc, char *argv[])
 	  status = hold_status;
 	}
       else
-	unlink (tmpname);
+	unlink_if_ordinary (tmpname);
       if (output_file == NULL)
 	free (tmpname);
     }
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/gas/as.c	2004-08-27
13:44:16.000000000 +0200
+++ 2004-12-03.13.35/gas/as.c	2004-12-15 12:00:28.777219440 +0100
@@ -1197,7 +1197,7 @@ main (int argc, char ** argv)
     keep_it = 0;
 
   if (!keep_it)
-    unlink (out_file_name);
+    unlink_if_ordinary (out_file_name);
 
   input_scrub_end ();
 
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/gas/messages.c	2004-10-06
09:35:49.000000000 +0200
+++ 2004-12-03.13.35/gas/messages.c	2004-12-15 12:00:49.554060880
+0100
@@ -412,7 +412,7 @@ as_fatal (const char *format, ...)
   /* Delete the output file, if it exists.  This will prevent make
from
      thinking that a file was created and hence does not need
rebuilding.  */
   if (out_file_name != NULL)
-    unlink (out_file_name);
+    unlink_if_ordinary (out_file_name);
   xexit (EXIT_FAILURE);
 }
 #else
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/include/libiberty.h	2004-10-06
09:35:58.000000000 +0200
+++ 2004-12-03.13.35/include/libiberty.h	2004-12-15
11:43:21.581376944 +0100
@@ -163,6 +163,10 @@ extern char *choose_temp_base PARAMS ((v
 
 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
 
+/* Remove a link to a file unless it is special. */
+
+extern int unlink_if_ordinary PARAMS((const char *));
+
 /* Allocate memory filled with spaces.  Allocates using malloc.  */
 
 extern const char *spaces PARAMS ((int count));
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/ld/ldmain.c	2004-11-18
15:07:17.000000000 +0100
+++ 2004-12-03.13.35/ld/ldmain.c	2004-12-15 12:08:20.423518304
+0100
@@ -171,7 +171,7 @@ remove_output (void)
       if (output_bfd)
 	bfd_cache_close (output_bfd);
       if (delete_output_file_on_failure)
-	unlink (output_filename);
+	unlink_if_ordinary (output_filename);
     }
 }
 
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/ld/pe-dll.c	2004-11-02
17:16:17.000000000 +0100
+++ 2004-12-03.13.35/ld/pe-dll.c	2004-12-15 12:09:00.280459128
+0100
@@ -2231,7 +2231,7 @@ pe_dll_generate_implib (def_file *def, c
     if (!ISALNUM (dll_symname[i]))
       dll_symname[i] = '_';
 
-  unlink (impfilename);
+  unlink_if_ordinary (impfilename);
 
   outarch = bfd_openw (impfilename, 0);
 
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/libiberty/Makefile.in	2004-11-18
15:07:33.000000000 +0100
+++ 2004-12-03.13.35/libiberty/Makefile.in	2004-12-15
11:50:38.597940328 +0100
@@ -152,6 +152,7 @@ CFILES = alloca.c argv.c asprintf.c atex
 	 strstr.c strtod.c strtol.c
strtoul.c				\
 	ternary.c
tmpnam.c						\
 	vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c
vsprintf.c	\
+	unlink-if-ordinary.c						\

	waitpid.c							\
 	xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
 
@@ -171,6 +172,7 @@ REQUIRED_OFILES = ./regex.o ./cplus-dem.
 	./safe-ctype.o ./sort.o ./spaces.o ./splay-tree.o
./strerror.o	\
 	
./strsignal.o							\

	./ternary.o							\
+	./unlink-if-ordinary.o						\
 	./xatexit.o ./xexit.o ./xmalloc.o ./xmemdup.o
./xstrdup.o	\
 	 ./xstrerror.o
 
@@ -973,6 +975,13 @@ $(CONFIGURED_OFILES): stamp-picdir
 	else true; fi
 	$(COMPILE.c) $(srcdir)/tmpnam.c $(OUTPUT_OPTION)
 
+./unlink-if-ordinary.o: $(srcdir)/unlink-if-ordinary.c config.h
$(INCDIR)/ansidecl.h \
+	$(INCDIR)/libiberty.h
+	if [ x"$(PICFLAG)" != x ]; then \
+	  $(COMPILE.c) $(PICFLAG) $(srcdir)/unlink-if-ordinary.c -o
pic/$@; \
+	else true; fi
+	$(COMPILE.c) $(srcdir)/unlink-if-ordinary.c $(OUTPUT_OPTION)
+
 ./vasprintf.o: $(srcdir)/vasprintf.c config.h $(INCDIR)/ansidecl.h \
 	$(INCDIR)/libiberty.h
 	if [ x"$(PICFLAG)" != x ]; then \
---
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/libiberty/unlink-if-ordinary.c	1970-01-01
01:00:00.000000000 +0100
+++ 2004-12-03.13.35/libiberty/unlink-if-ordinary.c	2004-12-15
12:14:37.960124016 +0100
@@ -0,0 +1,49 @@
+/* unlink-if-ordinary.c - remove link to a file unless it is special
*/
+
+/*
+
+@deftypefn Supplemental int unlink_if_ordinary (const char*)
+
+Unlink the named file, unless it is special (e.g. a device file).
+Returns 0 when the file was unlinked, a negative value (and errno set)
when
+there was an error deleting the file, and a positive value if no
attempt
+was made to unlink the file because it is special.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include "libiberty.h"
+
+#ifndef S_ISLNK
+#ifdef S_IFLNK
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#else
+#define S_ISLNK(m) 0
+#define lstat stat
+#endif
+#endif
+
+int
+unlink_if_ordinary (name)
+  const char *name;
+{
+  struct stat st;
+
+  if (lstat (name, &st) == 0
+      && (S_ISREG (st.st_mode) || S_ISLNK (st.st_mode)))
+    return unlink (name);
+
+  return 1;
+}


[-- Attachment #2: binutils-mainline-unlink-ordinary.patch --]
[-- Type: application/octet-stream, Size: 8750 bytes --]



Built and tested on i686-pc-linux-gnu.

Jan

bfd/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* Makefile.am: Add dependency of cache.o on libiberty.h.
	* cache.c: Include libiberty.h.
	(bfd_open_file): Use unlink_if_ordinary instead of unlink.

binutils/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* ar.c (remove_output): Use unlink_if_ordinary instead of unlink.
	* objcopy.c (copy_file): Likewise.
	(strip_main): Likewise.

gas/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* as.c (main): Use unlink_if_ordinary instead of unlink.
	* messages.c (as_fatal): Likewise.

include/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* libiberty.h: Declare unlink_if_ordinary.

ld/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* ldmain.c (remove_output): Use unlink_if_ordinary instead of unlink.
	* pe-dll.c (pe_dll_generate_implib): Likewise.

libiberty/
2004-12-15 Jan Beulich  <jbeulich@novell.com>

	* Makefile.in (CFILES): Add unlink-if-ordinary.c
	(REQUIRED_OFILES): Add unlink-if-ordinary.o.
	Add dependencies and rule for unlink-if-ordinary.o.
	* unlink-if-ordinary.c: New.

--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/Makefile.am	2004-11-18 15:05:03.000000000 +0100
+++ 2004-12-03.13.35/bfd/Makefile.am	2004-12-15 12:24:30.392060672 +0100
@@ -903,7 +903,7 @@ bfd.lo: bfd.c bfdver.h $(INCDIR)/filenam
   $(INCDIR)/elf/external.h
 bfdio.lo: bfdio.c $(INCDIR)/filenames.h
 bfdwin.lo: bfdwin.c $(INCDIR)/filenames.h
-cache.lo: cache.c $(INCDIR)/filenames.h
+cache.lo: cache.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h
 coffgen.lo: coffgen.c $(INCDIR)/filenames.h $(INCDIR)/coff/internal.h \
   libcoff.h $(INCDIR)/bfdlink.h
 corefile.lo: corefile.c $(INCDIR)/filenames.h
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/Makefile.in	2004-11-18 15:05:03.000000000 +0100
+++ 2004-12-03.13.35/bfd/Makefile.in	2004-12-15 12:24:40.276558000 +0100
@@ -1458,7 +1458,7 @@ bfd.lo: bfd.c bfdver.h $(INCDIR)/filenam
   $(INCDIR)/elf/external.h
 bfdio.lo: bfdio.c $(INCDIR)/filenames.h
 bfdwin.lo: bfdwin.c $(INCDIR)/filenames.h
-cache.lo: cache.c $(INCDIR)/filenames.h
+cache.lo: cache.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h
 coffgen.lo: coffgen.c $(INCDIR)/filenames.h $(INCDIR)/coff/internal.h \
   libcoff.h $(INCDIR)/bfdlink.h
 corefile.lo: corefile.c $(INCDIR)/filenames.h
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/bfd/cache.c	2004-06-28 16:51:45.000000000 +0200
+++ 2004-12-03.13.35/bfd/cache.c	2004-12-15 12:24:50.550996048 +0100
@@ -41,6 +41,7 @@ SECTION
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
+#include "libiberty.h"
 
 static bfd_boolean bfd_cache_delete (bfd *);
 
@@ -436,7 +437,7 @@ bfd_open_file (bfd *abfd)
 	  struct stat s;
 
 	  if (stat (abfd->filename, &s) == 0 && s.st_size != 0)
-	    unlink (abfd->filename);
+	    unlink_if_ordinary (abfd->filename);
 #endif
 	  abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WUB);
 	  abfd->opened_once = TRUE;
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/binutils/ar.c	2004-11-02 17:16:01.000000000 +0100
+++ 2004-12-03.13.35/binutils/ar.c	2004-12-15 12:10:35.610966688 +0100
@@ -328,7 +328,7 @@ remove_output (void)
 	bfd_cache_close (output_bfd);
       if (output_file != NULL)
 	fclose (output_file);
-      unlink (output_filename);
+      unlink_if_ordinary (output_filename);
     }
 }
 
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/binutils/objcopy.c	2004-11-02 17:16:02.000000000 +0100
+++ 2004-12-03.13.35/binutils/objcopy.c	2004-12-15 12:22:41.303644632 +0100
@@ -1716,7 +1716,7 @@ copy_file (const char *input_filename, c
 
       if (delete)
 	{
-	  unlink (output_filename);
+	  unlink_if_ordinary (output_filename);
 	  status = 1;
 	}
     }
@@ -2423,7 +2423,7 @@ strip_main (int argc, char *argv[])
 	  status = hold_status;
 	}
       else
-	unlink (tmpname);
+	unlink_if_ordinary (tmpname);
       if (output_file == NULL)
 	free (tmpname);
     }
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/gas/as.c	2004-08-27 13:44:16.000000000 +0200
+++ 2004-12-03.13.35/gas/as.c	2004-12-15 12:00:28.777219440 +0100
@@ -1197,7 +1197,7 @@ main (int argc, char ** argv)
     keep_it = 0;
 
   if (!keep_it)
-    unlink (out_file_name);
+    unlink_if_ordinary (out_file_name);
 
   input_scrub_end ();
 
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/gas/messages.c	2004-10-06 09:35:49.000000000 +0200
+++ 2004-12-03.13.35/gas/messages.c	2004-12-15 12:00:49.554060880 +0100
@@ -412,7 +412,7 @@ as_fatal (const char *format, ...)
   /* Delete the output file, if it exists.  This will prevent make from
      thinking that a file was created and hence does not need rebuilding.  */
   if (out_file_name != NULL)
-    unlink (out_file_name);
+    unlink_if_ordinary (out_file_name);
   xexit (EXIT_FAILURE);
 }
 #else
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/include/libiberty.h	2004-10-06 09:35:58.000000000 +0200
+++ 2004-12-03.13.35/include/libiberty.h	2004-12-15 11:43:21.581376944 +0100
@@ -163,6 +163,10 @@ extern char *choose_temp_base PARAMS ((v
 
 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
 
+/* Remove a link to a file unless it is special. */
+
+extern int unlink_if_ordinary PARAMS((const char *));
+
 /* Allocate memory filled with spaces.  Allocates using malloc.  */
 
 extern const char *spaces PARAMS ((int count));
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/ld/ldmain.c	2004-11-18 15:07:17.000000000 +0100
+++ 2004-12-03.13.35/ld/ldmain.c	2004-12-15 12:08:20.423518304 +0100
@@ -171,7 +171,7 @@ remove_output (void)
       if (output_bfd)
 	bfd_cache_close (output_bfd);
       if (delete_output_file_on_failure)
-	unlink (output_filename);
+	unlink_if_ordinary (output_filename);
     }
 }
 
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/ld/pe-dll.c	2004-11-02 17:16:17.000000000 +0100
+++ 2004-12-03.13.35/ld/pe-dll.c	2004-12-15 12:09:00.280459128 +0100
@@ -2231,7 +2231,7 @@ pe_dll_generate_implib (def_file *def, c
     if (!ISALNUM (dll_symname[i]))
       dll_symname[i] = '_';
 
-  unlink (impfilename);
+  unlink_if_ordinary (impfilename);
 
   outarch = bfd_openw (impfilename, 0);
 
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/libiberty/Makefile.in	2004-11-18 15:07:33.000000000 +0100
+++ 2004-12-03.13.35/libiberty/Makefile.in	2004-12-15 11:50:38.597940328 +0100
@@ -152,6 +152,7 @@ CFILES = alloca.c argv.c asprintf.c atex
 	 strstr.c strtod.c strtol.c strtoul.c				\
 	ternary.c tmpnam.c						\
 	vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c	\
+	unlink-if-ordinary.c						\
 	waitpid.c							\
 	xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
 
@@ -171,6 +172,7 @@ REQUIRED_OFILES = ./regex.o ./cplus-dem.
 	./safe-ctype.o ./sort.o ./spaces.o ./splay-tree.o ./strerror.o	\
 	 ./strsignal.o							\
 	./ternary.o							\
+	./unlink-if-ordinary.o						\
 	./xatexit.o ./xexit.o ./xmalloc.o ./xmemdup.o ./xstrdup.o	\
 	 ./xstrerror.o
 
@@ -973,6 +975,13 @@ $(CONFIGURED_OFILES): stamp-picdir
 	else true; fi
 	$(COMPILE.c) $(srcdir)/tmpnam.c $(OUTPUT_OPTION)
 
+./unlink-if-ordinary.o: $(srcdir)/unlink-if-ordinary.c config.h $(INCDIR)/ansidecl.h \
+	$(INCDIR)/libiberty.h
+	if [ x"$(PICFLAG)" != x ]; then \
+	  $(COMPILE.c) $(PICFLAG) $(srcdir)/unlink-if-ordinary.c -o pic/$@; \
+	else true; fi
+	$(COMPILE.c) $(srcdir)/unlink-if-ordinary.c $(OUTPUT_OPTION)
+
 ./vasprintf.o: $(srcdir)/vasprintf.c config.h $(INCDIR)/ansidecl.h \
 	$(INCDIR)/libiberty.h
 	if [ x"$(PICFLAG)" != x ]; then \
--- /home/jbeulich/src/binutils/mainline/2004-12-03.13.35/libiberty/unlink-if-ordinary.c	1970-01-01 01:00:00.000000000 +0100
+++ 2004-12-03.13.35/libiberty/unlink-if-ordinary.c	2004-12-15 12:14:37.960124016 +0100
@@ -0,0 +1,49 @@
+/* unlink-if-ordinary.c - remove link to a file unless it is special */
+
+/*
+
+@deftypefn Supplemental int unlink_if_ordinary (const char*)
+
+Unlink the named file, unless it is special (e.g. a device file).
+Returns 0 when the file was unlinked, a negative value (and errno set) when
+there was an error deleting the file, and a positive value if no attempt
+was made to unlink the file because it is special.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include "libiberty.h"
+
+#ifndef S_ISLNK
+#ifdef S_IFLNK
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#else
+#define S_ISLNK(m) 0
+#define lstat stat
+#endif
+#endif
+
+int
+unlink_if_ordinary (name)
+  const char *name;
+{
+  struct stat st;
+
+  if (lstat (name, &st) == 0
+      && (S_ISREG (st.st_mode) || S_ISLNK (st.st_mode)))
+    return unlink (name);
+
+  return 1;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] Re: deletion of output files
@ 2004-12-15 14:33 Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2004-12-15 14:33 UTC (permalink / raw)
  To: dj; +Cc: binutils

>> tmpnam.c						\
>>  	vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c
>> vsprintf.c	\
>>
+	unlink-if-ordinary.c						\
>
>This list is supposed to be in alphabetical order.

I saw that, I just misplaced it by a line.

>Also, your mailer is corrupting your patch by line wrapping.  (yes, I
>saw the attached binary, just FYI).

I know, but can't (at present) do anything about it.

>> @@ -973,6 +975,13 @@ $(CONFIGURED_OFILES): stamp-picdir
>>  	else true; fi
>>  	$(COMPILE.c) $(srcdir)/tmpnam.c $(OUTPUT_OPTION)
>>  
>> +./unlink-if-ordinary.o: $(srcdir)/unlink-if-ordinary.c config.h
>> $(INCDIR)/ansidecl.h \
>> +	$(INCDIR)/libiberty.h
>> +	if [ x"$(PICFLAG)" != x ]; then \
>> +	  $(COMPILE.c) $(PICFLAG) $(srcdir)/unlink-if-ordinary.c -o
>> pic/$@; \
>> +	else true; fi
>> +	$(COMPILE.c) $(srcdir)/unlink-if-ordinary.c $(OUTPUT_OPTION)
>> +
>
>Did you use "make maint-deps" to produce this part, or cut and paste?

Just cut-and-paste. I wasn't sure how Makefile.in would get generated
(namely the one in cvs), and for this simple case it seemed appropriate
to do this by hand. Just for my understanding of the processes here: if
I regenerated it, would I still list this in the patch (and apply the
delta once approved)?

>>
/home/jbeulich/src/binutils/mainline/2004-12-03.13.35/libiberty/unlink-if-ordinary.c	1970-01-01
>> 01:00:00.000000000 +0100
>> +++ 2004-12-03.13.35/libiberty/unlink-if-ordinary.c	2004-12-15
>> 12:14:37.960124016 +0100
>> @@ -0,0 +1,49 @@
>> +/* unlink-if-ordinary.c - remove link to a file unless it is
special
>> */
>
>Copyright block required.

Odd (as so many things). I used another of the source files as
template, and that one (getpwd.c) didn't have one either. But of course
it's no big deal to copy one from one of those files that have it.

>> +/*
>> +
>> +@deftypefn Supplemental int unlink_if_ordinary (const char*)
>> +
>> +Unlink the named file, unless it is special (e.g. a device file).
>> +Returns 0 when the file was unlinked, a negative value (and errno
set)
>> when
>> +there was an error deleting the file, and a positive value if no
>> attempt
>> +was made to unlink the file because it is special.
>
>Hmmm... I wonder if returning an error condition when it doesn't
>attempt an unlink is accurate.  After all, it correctly did what it
>was supposed to do.  Any bets on how often programmers forget to
check
>for this?  ;-)

Depends on whether you see this as an error condition. Many functions
return negative values (and not just non-zero) as error condition, which
is why I selected this method.
Btw., none of the call sites in binutils actually check the return
value.

>> +    return unlink (name);
>> +
>> +  return 1;
>> +}
>
>I wonder if we should set errno to something useful if we return 1.
>Else, we should document that errno is unspecified in that case.

Since I don't view this as an error condition, I intentionally didn't
set errno.

Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <s1c04b13.092@emea1-mh.id2.novell.com>]
* Re: [PATCH] Re: deletion of output files
@ 2004-12-16  9:11 Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2004-12-16  9:11 UTC (permalink / raw)
  To: dj; +Cc: binutils

>> >Copyright block required.
>> 
>> Odd (as so many things). I used another of the source files as
>> template, and that one (getpwd.c) didn't have one either. But of course
>> it's no big deal to copy one from one of those files that have it.
>
>Please choose one that's lenient, LGPL plus the extra built-with-gcc
>exception.  That will cause the least headaches later.  Unless, of
>course, you as the author want it otherwise.

Hmm, there are too many different headers. I simply have no clue which one to chose (I first wanted to use the one from regex.c, but that * as I read it * doesn't have the exztra partt you refer to, then thought of using gcc/libgcc2.c's one, but that is GPL). Do you perhaps have a hint at what file is already using a header as you suggest I should use?

Thanks again, Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <s1c15147.035@emea1-mh.id2.novell.com>]

end of thread, other threads:[~2004-12-16 20:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-15 12:37 [PATCH] Re: deletion of output files Jan Beulich
2004-12-15 13:41 ` DJ Delorie
2004-12-16 12:04 ` Nick Clifton
2004-12-15 14:33 Jan Beulich
     [not found] <s1c04b13.092@emea1-mh.id2.novell.com>
2004-12-15 19:34 ` DJ Delorie
2004-12-16  9:11 Jan Beulich
     [not found] <s1c15147.035@emea1-mh.id2.novell.com>
2004-12-16 20:15 ` DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).