# Compiling GNU stat



## bsd4eva (Aug 12, 2010)

I would like to used options available in the GNU version of the 'stat' command.  I couldn't find it in the Ports.  I have little C programming ability.  I'm not requesting a lot of time, so if this issue doesn't have an easy answer please pass.

I get better results (fewer errors) using g++ rather than gcc.  The sys/sysmacros.h and sys/vfs.h were found by including /usr/src/sys/cddl/compat/opensolaris which also has include/stdlib.h  [I still the the malloc.h error when /usr/src/sys/cddl/compat/opensolaris/include/stdlib.h is removed.]

The errors to me originate from this statement at line 54.

void print_human_fstype(struct statfs *statfsbuf)


```
[root@ /usr/home/scc/Desktop/Downloads/stat-3.3]# make stat
g++ -O2 -g -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/src/sys/cddl/compat/opensolaris -o stat stat.c 
In file included from stat.c:10:
/usr/include/malloc.h:3:2: error: #error "<malloc.h> has been replaced by <stdlib.h>"
stat.c: In function 'void print_human_fstype(statfs*)':
stat.c:58: error: invalid use of incomplete type 'struct statfs'
stat.c:54: error: forward declaration of 'struct statfs'
stat.c:231: error: 'malloc' was not declared in this scope
stat.c:238: error: invalid use of incomplete type 'struct statfs'
stat.c:54: error: forward declaration of 'struct statfs'
stat.c: At global scope:
stat.c:242: error: expected constructor, destructor, or type conversion before '(' token
stat.c:243: error: expected constructor, destructor, or type conversion before '(' token
stat.c:244: error: expected declaration before '}' token
*** Error code 1
```


----------



## SirDice (Aug 12, 2010)

It's not going to work. As far as I can tell GNU stat uses statfs and procfs. Procfs is available on FreeBSD but it's different from the one on Linux. Statfs doesn't exist at all on FreeBSD.


----------



## camelia (Aug 12, 2010)

Why not to use the GNU stat in sysutils/coreutils?
	
	



```
$ gstat mmap.c
  File: `mmap.c'
  Size: 298             Blocks: 2          IO Block: 4096   regular file
Device: ae295c36h/2921946166d   Inode: 32015       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/    holo)   Gid: ( 1001/    holo)
Access: 2010-07-17 23:24:27.275635242 +0400
Modify: 2010-07-17 23:24:27.275635242 +0400
Change: 2010-07-18 05:02:59.337835052 +0400

$ stat -x mmap.c
  File: "mmap.c"
  Size: 298          FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: ( 1001/    holo)  Gid: ( 1001/    holo)
Device: 92,2921922614   Inode: 32015    Links: 1
Access: Sat Jul 17 23:24:27 2010
Modify: Sat Jul 17 23:24:27 2010
Change: Sun Jul 18 05:02:59 2010
```


----------



## fronclynne (Aug 12, 2010)

We do have linprocfs(5) & linsysfs(5), though I have no idea how you would fiddle them in.  Perhaps see also /usr/src/sys/compat/linprocfs/linprocfs.c et /usr/src/sys/compat/linsysfs/linsysfs.c.

But, as *camelia* suggests, it may be redundant.


----------



## bsd4eva (Aug 13, 2010)

*[Solved (for me)] Compiling GNU stat*

Thanks to all that replied.

Thanks to camelia for steering me in a useful direction.    GNU [CMD="gstat"][/CMD] from sysutils/coreutils does what I need.  

Thanks to DutchDaemon for cleaning up a newbie's 1st post.


----------

