Print this page
12328 FNMPERIOD makes little sense for find -path


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  24  * Copyright (c) 2013 Andrew Stormont.  All rights reserved.

  25  */
  26 
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 
  32 /*      Parts of this product may be derived from               */
  33 /*      Mortice Kern Systems Inc. and Berkeley 4.3 BSD systems. */
  34 /*      licensed from  Mortice Kern Systems Inc. and            */
  35 /*      the University of California.                           */
  36 
  37 /*
  38  * Copyright 1985, 1990 by Mortice Kern Systems Inc.  All rights reserved.
  39  */
  40 
  41 #include <stdio.h>
  42 #include <errno.h>
  43 #include <pwd.h>
  44 #include <grp.h>


1010 
1011                         if (np->action == INAME || np->action == IPATH)
1012                                 fnmflags = FNM_IGNORECASE;
1013 
1014                         /*
1015                          * basename(3c) may modify name, so
1016                          * we need to pass another string
1017                          */
1018                         if ((path = strdup(name)) == NULL) {
1019                                 (void) fprintf(stderr,
1020                                     gettext("%s: cannot strdup() %s: %s\n"),
1021                                     cmdname, name, strerror(errno));
1022                                 exit(2);
1023                         }
1024                         /*
1025                          * XPG4 find should not treat a leading '.' in a
1026                          * filename specially for pattern matching.
1027                          * /usr/bin/find  will not pattern match a leading
1028                          * '.' in a filename, unless '.' is explicitly
1029                          * specified.


1030                          */
1031 #ifndef XPG4

1032                         fnmflags |= FNM_PERIOD;
1033 #endif
1034 
1035                         val = !fnmatch(np->first.cp,
1036                             (np->action == NAME || np->action == INAME) ?
1037                             basename(path) : path, fnmflags);
1038                         free(path);
1039                         break;
1040                 }
1041 
1042                 case PRUNE:
1043                         if (type == FTW_D)
1044                                 state->quit = FTW_PRUNE;
1045                         val = 1;
1046                         break;
1047                 case NOUSER:
1048                         val = ((getpwuid(statb->st_uid)) == 0);
1049                         break;
1050                 case NOGRP:
1051                         val = ((getgrgid(statb->st_gid)) == 0);




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  24  * Copyright (c) 2013 Andrew Stormont.  All rights reserved.
  25  * Copyright 2020 Joyent, Inc.
  26  */
  27 
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  30 /*        All Rights Reserved   */
  31 
  32 
  33 /*      Parts of this product may be derived from               */
  34 /*      Mortice Kern Systems Inc. and Berkeley 4.3 BSD systems. */
  35 /*      licensed from  Mortice Kern Systems Inc. and            */
  36 /*      the University of California.                           */
  37 
  38 /*
  39  * Copyright 1985, 1990 by Mortice Kern Systems Inc.  All rights reserved.
  40  */
  41 
  42 #include <stdio.h>
  43 #include <errno.h>
  44 #include <pwd.h>
  45 #include <grp.h>


1011 
1012                         if (np->action == INAME || np->action == IPATH)
1013                                 fnmflags = FNM_IGNORECASE;
1014 
1015                         /*
1016                          * basename(3c) may modify name, so
1017                          * we need to pass another string
1018                          */
1019                         if ((path = strdup(name)) == NULL) {
1020                                 (void) fprintf(stderr,
1021                                     gettext("%s: cannot strdup() %s: %s\n"),
1022                                     cmdname, name, strerror(errno));
1023                                 exit(2);
1024                         }
1025                         /*
1026                          * XPG4 find should not treat a leading '.' in a
1027                          * filename specially for pattern matching.
1028                          * /usr/bin/find  will not pattern match a leading
1029                          * '.' in a filename, unless '.' is explicitly
1030                          * specified.
1031                          *
1032                          * The legacy behavior makes no sense for PATH.
1033                          */
1034 #ifndef XPG4
1035                         if (np->action == NAME || np->action == INAME)
1036                                 fnmflags |= FNM_PERIOD;
1037 #endif
1038 
1039                         val = !fnmatch(np->first.cp,
1040                             (np->action == NAME || np->action == INAME) ?
1041                             basename(path) : path, fnmflags);
1042                         free(path);
1043                         break;
1044                 }
1045 
1046                 case PRUNE:
1047                         if (type == FTW_D)
1048                                 state->quit = FTW_PRUNE;
1049                         val = 1;
1050                         break;
1051                 case NOUSER:
1052                         val = ((getpwuid(statb->st_uid)) == 0);
1053                         break;
1054                 case NOGRP:
1055                         val = ((getgrgid(statb->st_gid)) == 0);