Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Nov 1999 14:15:09 +0200 (EET)
From:      serg@bcs.zp.ua
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/14824: ports/sysutils/stat error
Message-ID:  <199911111215.OAA65054@bcs3.bcs.zp.ua>

next in thread | raw e-mail | index | archive | help

>Number:         14824
>Category:       ports
>Synopsis:       no '\0' at the end of buffer
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 11 04:20:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Sergey Shkonda
>Release:        FreeBSD 3.3-STABLE i386
>Organization:
Business Computer Service
>Environment:

	

>Description:

Sometimes stat(1) outputs bad character at the end of file
descrption

>How-To-Repeat:

cd /tmp
touch ab abc
stat abc ab

>Fix:
	
Here is the patches


*** stat.1.orig	Sun Feb 16 15:16:52 1997
--- stat.1	Sun Aug 29 18:11:32 1999
***************
*** 44,49 ****
--- 44,51 ----
  	%m		Modified time.
  	%c		Status change time.
  	%b		# of blocks allocated.
+ 	%n		File name
+ 	%N		File name in form "name" or "name" -> "name"
  .fi
  .SH "SEE ALSO"
  stat(2), ls(1)



--- stat.fmt.c.orig	Sun Feb 16 15:12:33 1997
+++ stat.fmt.c	Sat Nov  6 22:04:08 1999
@@ -25,6 +25,8 @@
 		%m		Modified time.
 		%c		Status change time.
 		%b		# of blocks allocated.
+		%n		File name
+		%N		File name in form "name" or "name" -> "name"
 * libraries used:
 	standard + getopt
 * compile time parameters:
@@ -62,7 +64,7 @@
 char	*progname;		/* Name we're called as */
 
 char *fmt_app __P((char *, char *));
-void FmtInode __P((char *, char*, struct stat *));
+void FmtInode __P((char *, char*, struct stat *, char*, char*));
 void Usage __P((void));
 
 
@@ -92,6 +94,7 @@
 #define	LBUFSIZ		256	/* Length of symbolic link translation buffer */
 	char		Lbuf [LBUFSIZ];	/* Symbolic link translation buffer */
 
+	Lbuf[0] = 0;
 	if( lstat(filename,&Sbuf) == FAIL) {
 		fprintf(stderr,"Can't lstat %s\n",filename); 
 		return(FAIL);
@@ -104,12 +107,9 @@
 		}
 		if( count < LBUFSIZ)
 			Lbuf[count] = '\0';
-		printf("  File: \"%s\" -> \"%s\"\n", filename, Lbuf);
-	} else
-		printf("  File: \"%s\"\n", filename);
-
+	}
 
-	FmtInode(buf, fmt_str, &Sbuf);
+	FmtInode(buf, fmt_str, &Sbuf, filename, Lbuf);
 
 	printf("%s\n", buf);
 
@@ -402,6 +402,8 @@
 **	%m		Modified time.
 **	%c		Status change time.
 **	%b		# of blocks allocated.
+**	%n		File name
+**	%N		File name in form "name" or "name" -> "name"
 **
 **	Use a backslash to 'hide' any special character, e.g. '%'
 **
@@ -411,9 +413,11 @@
 */
 
 void
-FmtInode(buf, fmt, ip)
+FmtInode(buf, fmt, ip, name, lbuf)
 char		*buf,
-		*fmt;
+		*fmt,
+		*name,
+		*lbuf;
 struct stat	*ip;
 {
 	char		auxbuf [64];
@@ -429,6 +433,18 @@
 			*bufp++ = c;
 		} else {
 			switch (c = *fmt++) {
+				case 'n':	/* File name */
+					sprintf(auxbuf, "%s", name);
+					bufp = fmt_app(auxbuf, bufp);
+					break;
+				case 'N':
+					if (lbuf[0])
+					    sprintf(auxbuf, "\"%s\" -> \"%s\"",
+							name, lbuf);
+					else
+					    sprintf(auxbuf, "\"%s\"", name);
+					bufp = fmt_app(auxbuf, bufp);
+					break;
 				case 'f':	/* Filetype */
 					TypeToS(auxbuf, ip);
 					bufp = fmt_app(auxbuf, bufp);
@@ -500,6 +516,7 @@
 			}
 		}
 	}
+	*bufp=0;
 }
 /*
 **  USAGE -- Display a reminder
@@ -549,7 +566,7 @@
 	 *	Set some defaults ...
 	 */
 
-	fmt_str = "  Size: %s\tAllocated Blocks: %b\tFiletype: %f\n  Mode: (%p)\tUid: (%u) Gid: (%g)\nDevice: %d\tInode: %i\tLinks: %l\t%t\nAccess: %a\nModify: %m\nChange: %c\n";
+	fmt_str = "  File: %N\n  Size: %s\tAllocated Blocks: %b\tFiletype: %f\n  Mode: (%p)\tUid: (%u) Gid: (%g)\nDevice: %d\tInode: %i\tLinks: %l\t%t\nAccess: %a\nModify: %m\nChange: %c\n";
 
 	/*
 	 *	Check for flag arguments ...

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911111215.OAA65054>