File: XS_statfs

package info (click to toggle)
libfilesys-df-perl 0.92-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 96 kB
  • sloc: perl: 178; makefile: 3
file content (100 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef DF_STATFS_USE_MOUNT
#include <sys/param.h>
#include <sys/mount.h>
#endif
#ifdef DF_STATFS
#include <sys/statfs.h>
#endif
#ifdef __cplusplus
}
#endif


typedef struct statfs Statfs;


MODULE = Filesys::Df	PACKAGE = Filesys::Df

void
_df(dir)
	char *dir
	PREINIT:
	Statfs st;
	PPCODE:
	EXTEND(sp, 7);
#ifdef DF_SOLARIS
	if(statfs(dir, &st, 0, 0) == 0) {
#else
	if(statfs(dir, &st) == 0) {
#endif
		PUSHs(sv_2mortal(newSVnv((double)st.f_bsize)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_blocks)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_bfree)));
#ifdef DF_SOLARIS
		PUSHs(sv_2mortal(newSVnv((double)st.f_bfree)));
#else
		PUSHs(sv_2mortal(newSVnv((double)st.f_bavail)));
#endif
		PUSHs(sv_2mortal(newSVnv((double)st.f_files)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
		/* No favail */
		PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
	}

	else {
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));

		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
	}

void
_df_fh(fd)
	int fd
	PREINIT:
	Statfs st;
	PPCODE:
	EXTEND(sp, 7);
#ifdef DF_SOLARIS
	if(fstatfs(fd, &st, 0, 0) == 0) {
#else
	if(fstatfs(fd, &st) == 0) {
#endif
		PUSHs(sv_2mortal(newSVnv((double)st.f_bsize)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_blocks)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_bfree)));
#ifdef DF_SOLARIS
		PUSHs(sv_2mortal(newSVnv((double)st.f_bfree)));
#else
		PUSHs(sv_2mortal(newSVnv((double)st.f_bavail)));
#endif
		PUSHs(sv_2mortal(newSVnv((double)st.f_files)));
		PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
		/* No favail */
		PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
	}

	else {
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));

		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
		PUSHs(sv_2mortal(newSVuv(0)));
	}