PERFORCE change 143816 for review

Gabor Kovesdan gabor at FreeBSD.org
Fri Jun 20 11:49:38 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143816

Change 143816 by gabor at gabor_server on 2008/06/20 11:48:57

	- Don't grep directories as standard files when -R is given
	
	Reported by:	Michael Plass <mfp49_freebsd at plass-family.net>

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/util.c#29 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/util.c#29 (text+ko) ====

@@ -66,7 +66,6 @@
 	FTS		*fts;
 	FTSENT		*p;
 	int		 c, fts_flags;
-	struct stat	*finfo = 0;
 
 	c = fts_flags = 0;
 
@@ -91,19 +90,26 @@
 		case FTS_DP:
 			break;
 		default:
-			if (Dflag) {
+			if (Dflag || Rflag) {
+				struct stat	*finfo;
+
 				if (!(finfo = malloc(sizeof(struct stat))))
 					err(2, NULL);
 				if (stat(p->fts_path, finfo) == -1)
 					err(2, NULL);
-				if (S_ISBLK(finfo->st_mode) ||
+
+				if (Dflag && (S_ISBLK(finfo->st_mode) ||
 				    S_ISCHR(finfo->st_mode) ||
 				    S_ISFIFO(finfo->st_mode) ||
-				    S_ISSOCK(finfo->st_mode)) {
+				    S_ISSOCK(finfo->st_mode))) {
 					free(finfo);
 					break;
-				} else
+				}
+				if (Rflag && S_ISDIR(finfo->st_mode)) {
 					free(finfo);
+					break;
+				}
+				free(finfo);
 			}
 			c += procfile(p->fts_path);
 			break;


More information about the p4-projects mailing list