Subject: misc/18255: stat(2) manual page inaccurate
To: None <gnats-bugs@gnats.netbsd.org>
From: Edward V. Hynan Jr. <ehynan@rose.ehynan.com>
List: netbsd-bugs
Date: 09/10/2002 10:05:31
>Number:         18255
>Category:       misc
>Synopsis:       stat(2) manual page inaccurate
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 10 07:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Edward V. Hynan Jr.
>Release:        NetBSD 1.5.3
>Organization:
	
>Environment:
	
	
System: NetBSD rose 1.5.3 NetBSD 1.5.3 (ROSE) #0: Tue Sep 3 04:03:13 EDT 2002 toor@rose:/stella/NetBSD-1.5.3/rose/usr/src/sys/arch/i386/compile/ROSE i386
Architecture: i386
Machine: i386
>Description:
	
The stat(2) manual page, /usr/share/man/man2/stat.2, includes a definition
of struct stat that is not accurate.  The typedef'd types for the
st_{blocks,blksize} fields do not agree with sys/stat.h, nor does the
description of the time related fields.  The latter does not describe
the preprocessor macros conditional on !_POSIX_SOURCE && !_XOPEN_SOURCE.
Also, macros for st_{a,m,c}time{,nsec}, conditional on the above, are not shown.

>How-To-Repeat:
Invoke man 2 stat, and compare to /usr/include/sys/stat.h.
>Fix:
A patch is included below.  The form of the changes follow the FreeBSD stat(2),
but of course the content is from the NetBSD sys/stat.h.

BEGIN_PATCH
*** stat.2.orig	Mon Sep  9 22:38:56 2002
--- stat.2	Mon Sep  9 23:34:51 2002
***************
*** 96,107 ****
      uid_t     st_uid;     /* user-id of owner */
      gid_t     st_gid;     /* group-id of owner */
      dev_t     st_rdev;    /* device type, for special file inode */
      struct timespec st_atimespec;  /* time of last access */
      struct timespec st_mtimespec;  /* time of last data modification */
      struct timespec st_ctimespec;  /* time of last file status change */
      off_t     st_size;    /* file size, in bytes */
!     int64_t   st_blocks;  /* blocks allocated for file */
!     u_int32_t st_blksize; /* optimal file sys I/O ops blocksize */
      u_int32_t st_flags;   /* user defined flags for file */
      u_int32_t st_gen;     /* file generation number */
  };
--- 96,116 ----
      uid_t     st_uid;     /* user-id of owner */
      gid_t     st_gid;     /* group-id of owner */
      dev_t     st_rdev;    /* device type, for special file inode */
+ #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
      struct timespec st_atimespec;  /* time of last access */
      struct timespec st_mtimespec;  /* time of last data modification */
      struct timespec st_ctimespec;  /* time of last file status change */
+ #else
+     time_t    st_atime;            /* time of last access */
+     long      st_atimensec;        /* nsec of last access */
+     time_t    st_mtime;            /* time of last data modification */
+     long      st_mtimensec;        /* nsec of last data modification */
+     time_t    st_ctime;            /* time of last file status change */
+     long      st_ctimensec;        /* nsec of last file status change */
+ #endif
      off_t     st_size;    /* file size, in bytes */
!     blkcnt_t  st_blocks;  /* blocks allocated for file */
!     blksize_t st_blksize; /* optimal file sys I/O ops blocksize */
      u_int32_t st_flags;   /* user defined flags for file */
      u_int32_t st_gen;     /* file generation number */
  };
***************
*** 142,147 ****
--- 151,172 ----
  .Xr write 2
  system calls.
  .El
+ .Pp
+ If
+ .Dv _POSIX_SOURCE
+ and
+ .Dv _XOPEN_SOURCE
+ are not defined, the time-related fields are defined as:
+ .Bd -literal
+ #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
+ #define st_atime        st_atimespec.tv_sec
+ #define st_atimensec    st_atimespec.tv_nsec
+ #define st_mtime        st_mtimespec.tv_sec
+ #define st_mtimensec    st_mtimespec.tv_nsec
+ #define st_ctime        st_ctimespec.tv_sec
+ #define st_ctimensec    st_ctimespec.tv_nsec
+ #endif
+ .Ed
  .Pp
  The size-related fields of the
  .Fa struct stat
END_PATCH


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