sparc: reuse struct stat parser code for struct solstat decoding

* printstat.h: Parametrize major() and minor().
* file.c [SPARC || SPARC64]: Define do_printstat_sol by instantiating
printstat.h template.
[SPARC || SPARC64] (printstatsol): Use do_printstat_sol.
diff --git a/file.c b/file.c
index 20a481d..7b5b310 100644
--- a/file.c
+++ b/file.c
@@ -131,77 +131,7 @@
 
 #include "printstat.h"
 
-#if defined(SPARC) || defined(SPARC64)
-typedef struct {
-	int     tv_sec;
-	int     tv_nsec;
-} timestruct_t;
-
-struct solstat {
-	unsigned        st_dev;
-	int             st_pad1[3];     /* network id */
-	unsigned        st_ino;
-	unsigned        st_mode;
-	unsigned        st_nlink;
-	unsigned        st_uid;
-	unsigned        st_gid;
-	unsigned        st_rdev;
-	int             st_pad2[2];
-	int             st_size;
-	int             st_pad3;        /* st_size, off_t expansion */
-	timestruct_t    st_atime;
-	timestruct_t    st_mtime;
-	timestruct_t    st_ctime;
-	int             st_blksize;
-	int             st_blocks;
-	char            st_fstype[16];
-	int             st_pad4[8];     /* expansion area */
-};
-
-static void
-printstatsol(struct tcb *tcp, long addr)
-{
-	struct solstat statbuf;
-
-	if (umove(tcp, addr, &statbuf) < 0) {
-		tprints("{...}");
-		return;
-	}
-	if (!abbrev(tcp)) {
-		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
-			(unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
-			(unsigned long) (statbuf.st_dev & 0x3ffff),
-			(unsigned long) statbuf.st_ino,
-			sprintmode(statbuf.st_mode));
-		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-			(unsigned long) statbuf.st_nlink,
-			(unsigned long) statbuf.st_uid,
-			(unsigned long) statbuf.st_gid);
-		tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
-		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
-	}
-	else
-		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-	switch (statbuf.st_mode & S_IFMT) {
-	case S_IFCHR: case S_IFBLK:
-		tprintf("st_rdev=makedev(%lu, %lu), ",
-			(unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
-			(unsigned long) (statbuf.st_rdev & 0x3ffff));
-		break;
-	default:
-		tprintf("st_size=%u, ", statbuf.st_size);
-		break;
-	}
-	if (!abbrev(tcp)) {
-		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
-		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
-		tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
-	}
-	else
-		tprints("...}");
-}
-
-# if defined(SPARC64)
+#ifdef SPARC64
 static void
 printstat_sparc64(struct tcb *tcp, long addr)
 {
@@ -247,8 +177,7 @@
 	else
 		tprints("...}");
 }
-# endif /* SPARC64 */
-#endif /* SPARC[64] */
+#endif /* SPARC64 */
 
 #if defined POWERPC64
 struct stat_powerpc32 {
@@ -293,6 +222,56 @@
 }
 #endif /* POWERPC64 */
 
+#if defined(SPARC) || defined(SPARC64)
+
+struct solstat {
+	unsigned	st_dev;
+	unsigned int	st_pad1[3];     /* network id */
+	unsigned	st_ino;
+	unsigned	st_mode;
+	unsigned	st_nlink;
+	unsigned	st_uid;
+	unsigned	st_gid;
+	unsigned	st_rdev;
+	unsigned int	st_pad2[2];
+	unsigned int	st_size;
+	unsigned int	st_pad3;        /* st_size, off_t expansion */
+	unsigned int	st_atime;
+	unsigned int	st_atime_nsec;
+	unsigned int	st_mtime;
+	unsigned int	st_mtime_nsec;
+	unsigned int	st_ctime;
+	unsigned int	st_ctime_nsec;
+	unsigned int	st_blksize;
+	unsigned int	st_blocks;
+	char		st_fstype[16];
+	unsigned int	st_pad4[8];     /* expansion area */
+};
+
+# define DO_PRINTSTAT	do_printstat_sol
+# define STRUCT_STAT	struct solstat
+# define STAT_MAJOR(x)	(((x) >> 18) & 0x3fff)
+# define STAT_MINOR(x)	((x) & 0x3ffff)
+# undef HAVE_STRUCT_STAT_ST_FLAGS
+# undef HAVE_STRUCT_STAT_ST_FSTYPE
+# undef HAVE_STRUCT_STAT_ST_GEN
+# include "printstat.h"
+
+static void
+printstatsol(struct tcb *tcp, long addr)
+{
+	struct solstat statbuf;
+
+	if (umove(tcp, addr, &statbuf) < 0) {
+		tprints("{...}");
+		return;
+	}
+
+	do_printstat_sol(tcp, &statbuf);
+}
+
+#endif /* SPARC || SPARC64 */
+
 static void
 printstat(struct tcb *tcp, long addr)
 {
diff --git a/printstat.h b/printstat.h
index b6e18d3..dd0b02e 100644
--- a/printstat.h
+++ b/printstat.h
@@ -6,13 +6,21 @@
 # define STRUCT_STAT struct stat
 #endif
 
+#ifndef STAT_MAJOR
+# define STAT_MAJOR(x) major(x)
+#endif
+
+#ifndef STAT_MINOR
+# define STAT_MINOR(x) minor(x)
+#endif
+
 static void
 DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
 {
 	if (!abbrev(tcp)) {
 		tprintf("{st_dev=makedev(%u, %u), st_ino=%llu, st_mode=%s, ",
-			(unsigned int) major(statbuf->st_dev),
-			(unsigned int) minor(statbuf->st_dev),
+			(unsigned int) STAT_MAJOR(statbuf->st_dev),
+			(unsigned int) STAT_MINOR(statbuf->st_dev),
 			(unsigned long long) statbuf->st_ino,
 			sprintmode(statbuf->st_mode));
 		tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
@@ -34,12 +42,12 @@
 	case S_IFCHR: case S_IFBLK:
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
 		tprintf("st_rdev=makedev(%u, %u), ",
-			(unsigned int) major(statbuf->st_rdev),
-			(unsigned int) minor(statbuf->st_rdev));
+			(unsigned int) STAT_MAJOR(statbuf->st_rdev),
+			(unsigned int) STAT_MINOR(statbuf->st_rdev));
 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
 		tprintf("st_size=makedev(%u, %u), ",
-			(unsigned int) major(statbuf->st_size),
-			(unsigned int) minor(statbuf->st_size));
+			(unsigned int) STAT_MAJOR(statbuf->st_size),
+			(unsigned int) STAT_MINOR(statbuf->st_size));
 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
 		break;
 	default:
@@ -68,5 +76,7 @@
 	}
 }
 
+#undef STAT_MINOR
+#undef STAT_MAJOR
 #undef STRUCT_STAT
 #undef DO_PRINTSTAT