Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/locate/code Adjust the previous change to not genera...



details:   https://anonhg.NetBSD.org/src/rev/46dcc746226a
branches:  trunk
changeset: 485812:46dcc746226a
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Sat May 06 10:02:06 2000 +0000

description:
Adjust the previous change to not generate garbage databases.

diffstat:

 usr.bin/locate/code/locate.code.c |  20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diffs (58 lines):

diff -r 6d4bd749a173 -r 46dcc746226a usr.bin/locate/code/locate.code.c
--- a/usr.bin/locate/code/locate.code.c Sat May 06 07:53:53 2000 +0000
+++ b/usr.bin/locate/code/locate.code.c Sat May 06 10:02:06 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locate.code.c,v 1.7 2000/03/20 19:18:34 jdolecek Exp $ */
+/*     $NetBSD: locate.code.c,v 1.8 2000/05/06 10:02:06 mycroft Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)locate.code.c      8.4 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: locate.code.c,v 1.7 2000/03/20 19:18:34 jdolecek Exp $");
+__RCSID("$NetBSD: locate.code.c,v 1.8 2000/05/06 10:02:06 mycroft Exp $");
 #endif /* not lint */
 
 /*
@@ -99,7 +99,7 @@
 
 char buf1[MAXPATHLEN] = " ";   
 char buf2[MAXPATHLEN];
-char *bigrams;
+char bigrams[BGBUFSIZE + 1] = { 0 };
 
 int    bgindex __P((char *));
 int    main __P((int, char **));
@@ -125,14 +125,10 @@
        if (argc != 1)
                usage();
 
-       bigrams = argv[0];
-
        /* First copy bigram array to stdout. */
-       count = strlen(bigrams);
-       if (fwrite(bigrams, 1, count, stdout) != count)
+       strncpy(bigrams, argv[0], BGBUFSIZE + 1);
+       if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE)
                err(1, "stdout");
-       for(count = BGBUFSIZE - count; count > 0; count--)
-               fputc('\0', stdout);
 
        oldpath = buf1;
        path = buf2;
@@ -204,10 +200,10 @@
 
        bg0 = bg[0];
        bg1 = bg[1];
-       for (p = bigrams; *p != '\0'; p++)
-               if (*p++ == bg0 && *p == bg1)
+       for (p = bigrams; *p != '\0'; p += 2)
+               if (p[0] == bg0 && p[1] == bg1)
                        break;
-       return (*p == '\0' ? -1 : --p - bigrams);
+       return (*p == '\0' ? -1 : p - bigrams);
 }
 
 void



Home | Main Index | Thread Index | Old Index