]> git.saurik.com Git - apple/shell_cmds.git/blobdiff - find/misc.c
shell_cmds-118.tar.gz
[apple/shell_cmds.git] / find / misc.c
index cf6a85bbd3869289617fa6a01bee7b313d7ba53f..ced8cfbf569b821d5dff02d1b5aa455bda86bd29 100644 (file)
@@ -1,5 +1,3 @@
-/*     $NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $     */
-
 /*-
  * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #ifndef lint
 #if 0
-static char sccsid[] = "from: @(#)misc.c       8.2 (Berkeley) 4/1/94";
+static char sccsid[] = "@(#)misc.c     8.2 (Berkeley) 4/1/94";
 #else
-__RCSID("$NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $");
 #endif
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/find/misc.c,v 1.8 2005/04/02 07:44:12 tjr Exp $");
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -56,16 +55,13 @@ __RCSID("$NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $");
 #include <string.h>
 
 #include "find.h"
+
 /*
  * brace_subst --
- *     Replace occurrences of {} in orig with path, and place it in a malloced
- *      area of memory set in store.
+ *     Replace occurrences of {} in s1 with s2 and return the result string.
  */
 void
-brace_subst(orig, store, path, len)
-       char *orig, **store, *path;
-       int len;
+brace_subst(char *orig, char **store, char *path, int len)
 {
        int plen;
        char ch, *p;
@@ -75,7 +71,7 @@ brace_subst(orig, store, path, len)
                if (ch == '{' && orig[1] == '}') {
                        while ((p - *store) + plen > len)
                                if (!(*store = realloc(*store, len *= 2)))
-                                       err(1, "realloc");
+                                       err(1, NULL);
                        memmove(p, path, plen);
                        p += plen;
                        ++orig;
@@ -87,13 +83,13 @@ brace_subst(orig, store, path, len)
 /*
  * queryuser --
  *     print a message to standard error and then read input from standard
- *     input. If the input is 'y' then 1 is returned.
+ *     input. If the input is an affirmative response (according to the
+ *     current locale) then 1 is returned.
  */
 int
-queryuser(argv)
-       char **argv;
+queryuser(char *argv[])
 {
-       int ch, first, nl;
+       char *p, resp[256];
 
        (void)fprintf(stderr, "\"%s", *argv);
        while (*++argv)
@@ -101,35 +97,17 @@ queryuser(argv)
        (void)fprintf(stderr, "\"? ");
        (void)fflush(stderr);
 
-       first = ch = getchar();
-       for (nl = 0;;) {
-               if (ch == '\n') {
-                       nl = 1;
-                       break;
-               }
-               if (ch == EOF)
-                       break;
-               ch = getchar();
-       }
-
-       if (!nl) {
+       if (fgets(resp, sizeof(resp), stdin) == NULL)
+               *resp = '\0';
+       if ((p = strchr(resp, '\n')) != NULL)
+               *p = '\0';
+       else {
                (void)fprintf(stderr, "\n");
                (void)fflush(stderr);
        }
-        return (first == 'y');
-}
-/*
- * emalloc --
- *     malloc with error checking.
- */
-void *
-emalloc(len)
-       u_int len;
-{
-       void *p;
-
-       if ((p = malloc(len)) == NULL)
-               err(1, "malloc");
-       return (p);
+#ifdef __APPLE__
+        return (resp[0] == 'y');
+#else
+        return (rpmatch(resp) == 1);
+#endif
 }