Home | History | Annotate | Line # | Download | only in mtree
compare.c revision 1.24
      1  1.24    simonb /*	$NetBSD: compare.c,v 1.24 2001/03/09 03:09:45 simonb Exp $	*/
      2   1.8       cgd 
      3   1.1       cgd /*-
      4   1.7       cgd  * Copyright (c) 1989, 1993
      5   1.7       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.13     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38   1.8       cgd #if 0
     39   1.7       cgd static char sccsid[] = "@(#)compare.c	8.1 (Berkeley) 6/6/93";
     40   1.8       cgd #else
     41  1.24    simonb __RCSID("$NetBSD: compare.c,v 1.24 2001/03/09 03:09:45 simonb Exp $");
     42   1.8       cgd #endif
     43   1.1       cgd #endif /* not lint */
     44   1.1       cgd 
     45   1.1       cgd #include <sys/param.h>
     46   1.1       cgd #include <sys/stat.h>
     47  1.18     jwise #include <sys/types.h>
     48  1.24    simonb 
     49  1.24    simonb #include <errno.h>
     50   1.4       cgd #include <fcntl.h>
     51   1.1       cgd #include <fts.h>
     52  1.18     jwise #include <md5.h>
     53   1.1       cgd #include <stdio.h>
     54   1.1       cgd #include <time.h>
     55   1.4       cgd #include <unistd.h>
     56  1.24    simonb 
     57   1.1       cgd #include "mtree.h"
     58   1.4       cgd #include "extern.h"
     59   1.1       cgd 
     60  1.20       mrg extern int iflag, mflag, tflag, uflag;
     61   1.4       cgd 
     62  1.24    simonb static char *ftype(u_int);
     63   1.4       cgd 
     64   1.4       cgd #define	INDENTNAMELEN	8
     65  1.20       mrg #define MARK                                                                  \
     66  1.20       mrg do {                                                                          \
     67  1.20       mrg 	len = printf("%s: ", RP(p));                                          \
     68  1.20       mrg 	if (len > INDENTNAMELEN) {                                            \
     69  1.20       mrg 		tab = "\t";                                                   \
     70  1.20       mrg 		(void)printf("\n");                                           \
     71  1.20       mrg 	} else {                                                              \
     72  1.20       mrg 		tab = "";                                                     \
     73  1.20       mrg 		(void)printf("%*s", INDENTNAMELEN - (int)len, "");            \
     74  1.20       mrg 	}                                                                     \
     75  1.20       mrg } while (0)
     76  1.20       mrg #define	LABEL if (!label++) MARK
     77  1.20       mrg 
     78  1.20       mrg #define CHANGEFLAGS(path, oflags) \
     79  1.20       mrg 	if (flags != (oflags)) {                                              \
     80  1.20       mrg 		if (!label) {                                                 \
     81  1.20       mrg 			MARK;                                                 \
     82  1.20       mrg 			(void)printf("%sflags (\"%s\"", tab,                  \
     83  1.20       mrg 			    flags_to_string(p->fts_statp->st_flags, "none")); \
     84  1.20       mrg 		}                                                             \
     85  1.20       mrg 		if (chflags(path, flags)) {                                   \
     86  1.20       mrg 			label++;                                              \
     87  1.20       mrg 			(void)printf(", not modified: %s)\n",                 \
     88  1.20       mrg 			    strerror(errno));                                 \
     89  1.20       mrg 		} else                                                        \
     90  1.20       mrg 			(void)printf(", modified to \"%s\")\n",               \
     91  1.20       mrg 			     flags_to_string(flags, "none"));                 \
     92   1.4       cgd 	}
     93   1.1       cgd 
     94  1.20       mrg /* SETFLAGS:
     95  1.20       mrg  * given pflags, additionally set those flags specified in sflags and
     96  1.20       mrg  * selected by mask (the other flags are left unchanged). oflags is
     97  1.20       mrg  * passed as reference to check if chflags is necessary.
     98  1.20       mrg  */
     99  1.20       mrg #define SETFLAGS(path, sflags, pflags, oflags, mask)                          \
    100  1.20       mrg do {                                                                          \
    101  1.20       mrg 	flags = ((sflags) & (mask)) | (pflags);                               \
    102  1.20       mrg         CHANGEFLAGS(path, oflags);                                            \
    103  1.20       mrg } while (0)
    104  1.20       mrg 
    105  1.20       mrg /* CLEARFLAGS:
    106  1.20       mrg  * given pflags, reset the flags specified in sflags and selected by mask
    107  1.20       mrg  * (the other flags are left unchanged). oflags is
    108  1.20       mrg  * passed as reference to check if chflags is necessary.
    109  1.20       mrg  */
    110  1.20       mrg #define CLEARFLAGS(path, sflags, pflags, oflags, mask)                        \
    111  1.20       mrg do {                                                                          \
    112  1.20       mrg 	flags = (~((sflags) & (mask)) & CH_MASK) & (pflags);                  \
    113  1.20       mrg         CHANGEFLAGS(path, oflags);                                            \
    114  1.20       mrg } while (0)
    115  1.20       mrg 
    116   1.4       cgd int
    117  1.24    simonb compare(char *name, NODE *s, FTSENT *p)
    118   1.1       cgd {
    119  1.20       mrg 	u_int32_t len, val, flags;
    120   1.4       cgd 	int fd, label;
    121   1.4       cgd 	char *cp, *tab;
    122  1.18     jwise 	char md5buf[35];
    123   1.1       cgd 
    124  1.13     lukem 	tab = NULL;
    125   1.1       cgd 	label = 0;
    126   1.1       cgd 	switch(s->type) {
    127   1.1       cgd 	case F_BLOCK:
    128   1.3   deraadt 		if (!S_ISBLK(p->fts_statp->st_mode))
    129   1.1       cgd 			goto typeerr;
    130   1.1       cgd 		break;
    131   1.1       cgd 	case F_CHAR:
    132   1.3   deraadt 		if (!S_ISCHR(p->fts_statp->st_mode))
    133   1.1       cgd 			goto typeerr;
    134   1.1       cgd 		break;
    135   1.1       cgd 	case F_DIR:
    136   1.3   deraadt 		if (!S_ISDIR(p->fts_statp->st_mode))
    137   1.1       cgd 			goto typeerr;
    138   1.1       cgd 		break;
    139   1.1       cgd 	case F_FIFO:
    140   1.3   deraadt 		if (!S_ISFIFO(p->fts_statp->st_mode))
    141   1.1       cgd 			goto typeerr;
    142   1.1       cgd 		break;
    143   1.1       cgd 	case F_FILE:
    144   1.3   deraadt 		if (!S_ISREG(p->fts_statp->st_mode))
    145   1.1       cgd 			goto typeerr;
    146   1.1       cgd 		break;
    147   1.1       cgd 	case F_LINK:
    148   1.3   deraadt 		if (!S_ISLNK(p->fts_statp->st_mode))
    149   1.1       cgd 			goto typeerr;
    150   1.1       cgd 		break;
    151   1.1       cgd 	case F_SOCK:
    152   1.4       cgd 		if (!S_ISSOCK(p->fts_statp->st_mode)) {
    153   1.1       cgd typeerr:		LABEL;
    154   1.4       cgd 			(void)printf("\ttype (%s, %s)\n",
    155   1.3   deraadt 			    ftype(s->type), inotype(p->fts_statp->st_mode));
    156   1.1       cgd 		}
    157   1.1       cgd 		break;
    158   1.1       cgd 	}
    159  1.20       mrg 	if (iflag && !uflag) {
    160  1.20       mrg 		if (s->flags & F_FLAGS)
    161  1.20       mrg 		    SETFLAGS(p->fts_accpath, s->st_flags,
    162  1.20       mrg 			p->fts_statp->st_flags, p->fts_statp->st_flags,
    163  1.20       mrg 			SP_FLGS);
    164  1.20       mrg 		return (label);
    165  1.20       mrg         }
    166  1.20       mrg 	if (mflag && !uflag) {
    167  1.20       mrg 		if (s->flags & F_FLAGS)
    168  1.20       mrg 		    CLEARFLAGS(p->fts_accpath, s->st_flags,
    169  1.20       mrg 			p->fts_statp->st_flags, p->fts_statp->st_flags,
    170  1.20       mrg 			SP_FLGS);
    171  1.20       mrg 		return (label);
    172  1.20       mrg         }
    173   1.4       cgd 	/* Set the uid/gid first, then set the mode. */
    174   1.4       cgd 	if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
    175   1.1       cgd 		LABEL;
    176  1.19  christos 		(void)printf("%suser (%lu, %lu",
    177  1.19  christos 		    tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
    178  1.19  christos 		if (uflag) {
    179   1.4       cgd 			if (chown(p->fts_accpath, s->st_uid, -1))
    180   1.4       cgd 				(void)printf(", not modified: %s)\n",
    181   1.1       cgd 				    strerror(errno));
    182   1.1       cgd 			else
    183   1.4       cgd 				(void)printf(", modified)\n");
    184  1.19  christos 		} else
    185   1.4       cgd 			(void)printf(")\n");
    186   1.4       cgd 		tab = "\t";
    187   1.1       cgd 	}
    188   1.4       cgd 	if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
    189   1.1       cgd 		LABEL;
    190  1.19  christos 		(void)printf("%sgid (%lu, %lu",
    191  1.19  christos 		    tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
    192  1.19  christos 		if (uflag) {
    193   1.4       cgd 			if (chown(p->fts_accpath, -1, s->st_gid))
    194   1.5       cgd 				(void)printf(", not modified: %s)\n",
    195   1.1       cgd 				    strerror(errno));
    196   1.1       cgd 			else
    197   1.5       cgd 				(void)printf(", modified)\n");
    198  1.19  christos 		}
    199   1.4       cgd 		else
    200   1.4       cgd 			(void)printf(")\n");
    201   1.4       cgd 		tab = "\t";
    202   1.1       cgd 	}
    203   1.4       cgd 	if (s->flags & F_MODE &&
    204   1.4       cgd 	    s->st_mode != (p->fts_statp->st_mode & MBITS)) {
    205   1.1       cgd 		LABEL;
    206  1.19  christos 		(void)printf("%spermissions (%#lo, %#lo",
    207  1.19  christos 		    tab, (u_long)s->st_mode,
    208  1.19  christos 		    (u_long)p->fts_statp->st_mode & MBITS);
    209  1.19  christos 		if (uflag) {
    210   1.4       cgd 			if (chmod(p->fts_accpath, s->st_mode))
    211   1.5       cgd 				(void)printf(", not modified: %s)\n",
    212   1.1       cgd 				    strerror(errno));
    213   1.1       cgd 			else
    214   1.5       cgd 				(void)printf(", modified)\n");
    215  1.19  christos 		}
    216   1.4       cgd 		else
    217   1.4       cgd 			(void)printf(")\n");
    218   1.4       cgd 		tab = "\t";
    219   1.1       cgd 	}
    220   1.1       cgd 	if (s->flags & F_NLINK && s->type != F_DIR &&
    221   1.3   deraadt 	    s->st_nlink != p->fts_statp->st_nlink) {
    222   1.1       cgd 		LABEL;
    223  1.19  christos 		(void)printf("%slink count (%lu, %lu)\n",
    224  1.19  christos 		    tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
    225   1.4       cgd 		tab = "\t";
    226   1.1       cgd 	}
    227   1.3   deraadt 	if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
    228   1.1       cgd 		LABEL;
    229  1.23     lukem 		(void)printf("%ssize (%lld, %lld)\n",
    230  1.14     enami 		    tab, (long long)s->st_size,
    231  1.14     enami 		    (long long)p->fts_statp->st_size);
    232   1.4       cgd 		tab = "\t";
    233   1.4       cgd 	}
    234   1.7       cgd 	/*
    235   1.7       cgd 	 * XXX
    236  1.11   mycroft 	 * Since utimes(2) only takes a timeval, there's no point in
    237  1.11   mycroft 	 * comparing the low bits of the timespec nanosecond field.  This
    238  1.11   mycroft 	 * will only result in mismatches that we can never fix.
    239  1.11   mycroft 	 *
    240  1.11   mycroft 	 * Doesn't display microsecond differences.
    241   1.7       cgd 	 */
    242  1.11   mycroft 	if (s->flags & F_TIME) {
    243  1.11   mycroft 		struct timeval tv[2];
    244  1.21  christos 		struct stat *ps = p->fts_statp;
    245  1.22  christos 		time_t smtime = s->st_mtimespec.tv_sec;
    246  1.22  christos 
    247  1.21  christos #ifdef BSD4_4
    248  1.21  christos 		time_t pmtime = ps->st_mtimespec.tv_sec;
    249  1.11   mycroft 
    250  1.21  christos 		TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec);
    251  1.21  christos #else
    252  1.22  christos 		time_t pmtime = (time_t)ps->st_mtime;
    253  1.21  christos 
    254  1.21  christos 		tv[1].tv_sec = ps->st_mtime;
    255  1.21  christos 		tv[1].tv_usec = 0;
    256  1.21  christos #endif
    257  1.22  christos 		TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec);
    258  1.21  christos 
    259  1.11   mycroft 		if (tv[0].tv_sec != tv[1].tv_sec ||
    260  1.11   mycroft 		    tv[0].tv_usec != tv[1].tv_usec) {
    261  1.11   mycroft 			LABEL;
    262  1.11   mycroft 			(void)printf("%smodification time (%.24s, ",
    263  1.21  christos 			    tab, ctime(&smtime));
    264  1.21  christos 			(void)printf("%.24s", ctime(&pmtime));
    265  1.11   mycroft 			if (tflag) {
    266  1.11   mycroft 				tv[1] = tv[0];
    267  1.11   mycroft 				if (utimes(p->fts_accpath, tv))
    268  1.11   mycroft 					(void)printf(", not modified: %s)\n",
    269  1.11   mycroft 					    strerror(errno));
    270  1.11   mycroft 				else
    271  1.11   mycroft 					(void)printf(", modified)\n");
    272  1.11   mycroft 			} else
    273  1.11   mycroft 				(void)printf(")\n");
    274  1.11   mycroft 			tab = "\t";
    275  1.11   mycroft 		}
    276  1.17       mrg 	}
    277  1.17       mrg 	/*
    278  1.17       mrg 	 * XXX
    279  1.17       mrg 	 * since chflags(2) will reset file times, the utimes() above
    280  1.17       mrg 	 * may have been useless!  oh well, we'd rather have correct
    281  1.17       mrg 	 * flags, rather than times?
    282  1.17       mrg 	 */
    283  1.20       mrg         if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags)
    284  1.20       mrg 	    || mflag || iflag)) {
    285  1.20       mrg 		if (s->st_flags != p->fts_statp->st_flags) {
    286  1.20       mrg 			LABEL;
    287  1.20       mrg 			(void)printf("%sflags (\"%s\" is not ", tab,
    288  1.20       mrg 			    flags_to_string(s->st_flags, "none"));
    289  1.20       mrg 			(void)printf("\"%s\"",
    290  1.20       mrg 			    flags_to_string(p->fts_statp->st_flags, "none"));
    291  1.20       mrg 		}
    292  1.19  christos 		if (uflag) {
    293  1.20       mrg 			if (iflag)
    294  1.20       mrg 				SETFLAGS(p->fts_accpath, s->st_flags,
    295  1.20       mrg 				    0, p->fts_statp->st_flags, CH_MASK);
    296  1.20       mrg 			else if (mflag)
    297  1.20       mrg 				CLEARFLAGS(p->fts_accpath, s->st_flags,
    298  1.20       mrg 				    0, p->fts_statp->st_flags, SP_FLGS);
    299  1.17       mrg 			else
    300  1.20       mrg 				SETFLAGS(p->fts_accpath, s->st_flags,
    301  1.20       mrg 			     	    0, p->fts_statp->st_flags,
    302  1.20       mrg 				    (~SP_FLGS & CH_MASK));
    303  1.19  christos 		} else
    304  1.17       mrg 			(void)printf(")\n");
    305  1.17       mrg 		tab = "\t";
    306   1.1       cgd 	}
    307  1.15      ross 	if (s->flags & F_CKSUM) {
    308   1.4       cgd 		if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
    309   1.4       cgd 			LABEL;
    310   1.4       cgd 			(void)printf("%scksum: %s: %s\n",
    311   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    312   1.4       cgd 			tab = "\t";
    313   1.4       cgd 		} else if (crc(fd, &val, &len)) {
    314   1.4       cgd 			(void)close(fd);
    315   1.1       cgd 			LABEL;
    316   1.4       cgd 			(void)printf("%scksum: %s: %s\n",
    317   1.4       cgd 			    tab, p->fts_accpath, strerror(errno));
    318   1.4       cgd 			tab = "\t";
    319   1.4       cgd 		} else {
    320   1.4       cgd 			(void)close(fd);
    321   1.4       cgd 			if (s->cksum != val) {
    322   1.4       cgd 				LABEL;
    323   1.4       cgd 				(void)printf("%scksum (%lu, %lu)\n",
    324  1.16  wsanchez 				    tab, s->cksum, (unsigned long)val);
    325   1.4       cgd 			}
    326   1.4       cgd 			tab = "\t";
    327   1.1       cgd 		}
    328  1.15      ross 	}
    329  1.18     jwise 	if (s->flags & F_MD5) {
    330  1.18     jwise 		if (MD5File(p->fts_accpath, md5buf) == NULL) {
    331  1.18     jwise 			LABEL;
    332  1.18     jwise 			(void)printf("%smd5: %s: %s\n",
    333  1.18     jwise 			    tab, p->fts_accpath, strerror(errno));
    334  1.18     jwise 			tab = "\t";
    335  1.18     jwise 		} else {
    336  1.18     jwise 			if (strcmp(s->md5sum, md5buf)) {
    337  1.18     jwise 				LABEL;
    338  1.18     jwise 				(void)printf("%smd5 (0x%s, 0x%s)\n",
    339  1.18     jwise 				    tab, s->md5sum, md5buf);
    340  1.18     jwise 			}
    341  1.18     jwise 			tab = "\t";
    342  1.18     jwise 		}
    343  1.18     jwise 	}
    344  1.18     jwise 
    345   1.4       cgd 	if (s->flags & F_SLINK && strcmp(cp = rlink(name), s->slink)) {
    346   1.1       cgd 		LABEL;
    347   1.4       cgd 		(void)printf("%slink ref (%s, %s)\n", tab, cp, s->slink);
    348   1.1       cgd 	}
    349   1.4       cgd 	return (label);
    350   1.1       cgd }
    351   1.1       cgd 
    352   1.1       cgd char *
    353  1.24    simonb inotype(u_int type)
    354   1.1       cgd {
    355  1.24    simonb 
    356   1.1       cgd 	switch(type & S_IFMT) {
    357   1.1       cgd 	case S_IFBLK:
    358   1.4       cgd 		return ("block");
    359   1.1       cgd 	case S_IFCHR:
    360   1.4       cgd 		return ("char");
    361   1.1       cgd 	case S_IFDIR:
    362   1.4       cgd 		return ("dir");
    363   1.4       cgd 	case S_IFIFO:
    364   1.4       cgd 		return ("fifo");
    365   1.1       cgd 	case S_IFREG:
    366   1.4       cgd 		return ("file");
    367   1.1       cgd 	case S_IFLNK:
    368   1.4       cgd 		return ("link");
    369   1.1       cgd 	case S_IFSOCK:
    370   1.4       cgd 		return ("socket");
    371   1.1       cgd 	default:
    372   1.4       cgd 		return ("unknown");
    373   1.1       cgd 	}
    374   1.1       cgd 	/* NOTREACHED */
    375   1.1       cgd }
    376   1.1       cgd 
    377   1.4       cgd static char *
    378  1.24    simonb ftype(u_int type)
    379   1.1       cgd {
    380  1.24    simonb 
    381   1.1       cgd 	switch(type) {
    382   1.1       cgd 	case F_BLOCK:
    383   1.4       cgd 		return ("block");
    384   1.1       cgd 	case F_CHAR:
    385   1.4       cgd 		return ("char");
    386   1.1       cgd 	case F_DIR:
    387   1.4       cgd 		return ("dir");
    388   1.1       cgd 	case F_FIFO:
    389   1.4       cgd 		return ("fifo");
    390   1.1       cgd 	case F_FILE:
    391   1.4       cgd 		return ("file");
    392   1.1       cgd 	case F_LINK:
    393   1.4       cgd 		return ("link");
    394   1.1       cgd 	case F_SOCK:
    395   1.4       cgd 		return ("socket");
    396   1.1       cgd 	default:
    397   1.4       cgd 		return ("unknown");
    398   1.1       cgd 	}
    399   1.1       cgd 	/* NOTREACHED */
    400   1.1       cgd }
    401   1.1       cgd 
    402   1.1       cgd char *
    403  1.24    simonb rlink(char *name)
    404   1.1       cgd {
    405   1.4       cgd 	static char lbuf[MAXPATHLEN];
    406  1.13     lukem 	int len;
    407   1.1       cgd 
    408   1.4       cgd 	if ((len = readlink(name, lbuf, sizeof(lbuf))) == -1)
    409  1.16  wsanchez 		mtree_err("%s: %s", name, strerror(errno));
    410   1.1       cgd 	lbuf[len] = '\0';
    411   1.4       cgd 	return (lbuf);
    412   1.1       cgd }
    413