pyldb: avoid segfault when adding an element with no name
[kai/samba-autobuild/.git] / examples / libsmbclient / testfstatvfs.c
1 #include <sys/types.h>
2 #include <sys/statvfs.h>
3 #include <stdio.h> 
4 #include <unistd.h>
5 #include <string.h> 
6 #include <time.h> 
7 #include <errno.h>
8 #include <libsmbclient.h> 
9 #include "get_auth_data_fn.h"
10
11
12 int main(int argc, char * argv[]) 
13
14     int             fd;
15     int             ret;
16     int             debug = 0;
17     char *          p;
18     char            path[2048];
19     struct stat     statbuf;
20     struct statvfs  statvfsbuf;
21     
22     smbc_init(get_auth_data_fn, debug); 
23     
24     for (;;)
25     {
26         fprintf(stdout, "Path: ");
27         *path = '\0';
28         p = fgets(path, sizeof(path) - 1, stdin);
29         if (p == NULL) {
30                 fprintf(stderr, "failed to read from stdin\n");
31                 return 1;
32         }
33         if (strlen(path) == 0)
34         {
35             return 0;
36         }
37
38         p = path + strlen(path) - 1;
39         if (*p == '\n')
40         {
41             *p = '\0';
42         }
43     
44         /* Determine if it's a file or a folder */
45         if (smbc_stat(path, &statbuf) < 0)
46         {
47             perror("smbc_stat");
48             continue;
49         }
50
51         if (S_ISREG(statbuf.st_mode))
52         {
53             if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
54             {
55                 perror("smbc_open");
56                 continue;
57             }
58         }
59         else
60         {
61             if ((fd = smbc_opendir(path)) < 0)
62             {
63                 perror("smbc_opendir");
64                 continue;
65             }
66         }
67
68         ret = smbc_fstatvfs(fd, &statvfsbuf);
69
70         smbc_close(fd);
71
72         if (ret < 0)
73         {
74             perror("fstatvfs");
75         }
76         else
77         {
78             printf("\n");
79             printf("Block Size: %lu\n", statvfsbuf.f_bsize);
80             printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
81             printf("Blocks: %llu\n",
82                    (unsigned long long) statvfsbuf.f_blocks);
83             printf("Free Blocks: %llu\n",
84                    (unsigned long long) statvfsbuf.f_bfree);
85             printf("Available Blocks: %llu\n",
86                    (unsigned long long) statvfsbuf.f_bavail);
87             printf("Files : %llu\n",
88                    (unsigned long long) statvfsbuf.f_files);
89             printf("Free Files: %llu\n",
90                    (unsigned long long) statvfsbuf.f_ffree);
91             printf("Available Files: %llu\n",
92                    (unsigned long long) statvfsbuf.f_favail);
93 #ifdef HAVE_FSID_INT
94             printf("File System ID: %lu\n",
95                    (unsigned long) statvfsbuf.f_fsid);
96 #endif
97             printf("\n");
98
99             printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
100             printf("Extended Features: ");
101
102             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
103             {
104                 printf("NO_UNIXCIFS ");
105             }
106             else
107             {
108                 printf("unixcifs ");
109             }
110
111             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
112             {
113                 printf("CASE_INSENSITIVE ");
114             }
115             else
116             {
117                 printf("case_sensitive ");
118             }
119
120             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
121             {
122                 printf("DFS ");
123             }
124             else
125             {
126                 printf("no_dfs ");
127             }
128
129             printf("\n");
130         }
131     }
132
133     return 0; 
134 }