X-Git-Url: https://git.saurik.com/apple/shell_cmds.git/blobdiff_plain/44bd5ea795281151bc7b81a65d2dd42c6b8914d8..41a2c555d8993b200d28bf1fa33eebd8388950f7:/find/misc.c diff --git a/find/misc.c b/find/misc.c index cf6a85b..ced8cfb 100644 --- a/find/misc.c +++ b/find/misc.c @@ -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. @@ -36,15 +34,16 @@ * SUCH DAMAGE. */ -#include #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 +__FBSDID("$FreeBSD: src/usr.bin/find/misc.c,v 1.8 2005/04/02 07:44:12 tjr Exp $"); + #include #include @@ -56,16 +55,13 @@ __RCSID("$NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $"); #include #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 }