Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

user/3351: patch: use basename(3) in rm(1), reducing redundant code

From: Daniel J. Matic <danmatic(at)iprimus.com.au>
Date: Sat Jul 12 2003 - 12:51:26 EDT


>Number: 3351
>Category: user
>Synopsis: patch: use basename(3) in rm(1), reducing redundant code
>Confidential: yes
>Severity: non-critical
>Priority: low
>Responsible: bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sat Jul 12 07:00:01 GMT 2003
>Closed-Date:
>Last-Modified:
>Originator: Daniel J. Matic
>Release: 3.3-current
>Organization:
>Environment:

	System      : OpenBSD 3.3
	Architecture: OpenBSD.i386
	Machine     : i386

>Description:
Here is a patch that cleans up checkdot() in rm(1), so that it uses basename(3) instead of it's own version.
>How-To-Repeat:
n/a

>Fix:

Index: bin/rm/rm.c



RCS file: /cvs/src/bin/rm/rm.c,v
retrieving revision 1.15
diff -U3 -r1.15 rm.c
--- bin/rm/rm.c	2 Jun 2003 23:32:09 -0000	1.15
+++ bin/rm/rm.c	12 Jul 2003 05:52:25 -0000
@@ -49,17 +49,18 @@
 #include <sys/param.h>
 #include <sys/mount.h>  
-#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
 

 extern char *__progname;  

@@ -396,35 +397,29 @@

  • Since POSIX.2 defines basename as the final portion of a path after
  • trailing slashes have been removed, we'll remove them here. */ -#define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2]))) +#define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2]))) void checkdot(char **argv) { - char *p, **save, **t; - int complained; - - complained = 0; - for (t = argv; *t;) { - /* strip trailing slashes */ - p = strrchr (*t, '\0'); - while (--p > *t && *p == '/') - *p = '\0'; - - /* extract basename */ - if ((p = strrchr(*t, '/')) != NULL) - ++p; - else - p = *t; + char *bname, **temp; + int complained = 0;
    • if (ISDOT(p)) {
    • if (!complained++) + while (*argv != NULL) { + bname = basename(*argv); + if (bname != NULL && ISDOT(bname)) { + if (complained++ == 0) { warnx("\".\" and \"..\" may not be removed");
    • eval = 1;
    • for (save = t; (t[0] = t[1]) != NULL; ++t)
    • continue;
    • t = save; + eval = 1; + } + /* + * Remove the offending file by re-stacking the + * argument list, thus preserving order (and making + * argv point to the next argument). + */ + for (temp = argv; (temp[0] = temp[1]) != NULL; temp++) + ; } else
    • ++t; + argv++; } }

>Release-Note:
Received on Sat Jul 12 03:22:47 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:59 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library