ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / programs / gnomevfs-info.c
1 /* gnomevfs-info.c - Test for get_file_info() for gnome-vfs
2
3    Copyright (C) 2003, Red Hat
4
5    The Gnome Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    The Gnome Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the Gnome Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.
19
20    Author: Bastien Nocera <hadess@hadess.net>
21 */
22
23 #include <libgnomevfs/gnome-vfs.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <time.h>
29
30 static const gchar *
31 type_to_string (GnomeVFSFileType type)
32 {
33         switch (type) {
34         case GNOME_VFS_FILE_TYPE_UNKNOWN:
35                 return "Unknown";
36         case GNOME_VFS_FILE_TYPE_REGULAR:
37                 return "Regular";
38         case GNOME_VFS_FILE_TYPE_DIRECTORY:
39                 return "Directory";
40         case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
41                 return "Symbolic Link";
42         case GNOME_VFS_FILE_TYPE_FIFO:
43                 return "FIFO";
44         case GNOME_VFS_FILE_TYPE_SOCKET:
45                 return "Socket";
46         case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
47                 return "Character device";
48         case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
49                 return "Block device";
50         default:
51                 return "???";
52         }
53 }
54
55 static void
56 show_file_info (GnomeVFSFileInfo *info)
57 {
58 #define FLAG_STRING(info, which)                                \
59         (GNOME_VFS_FILE_INFO_##which (info) ? "YES" : "NO")
60
61         printf ("Name              : %s\n", info->name);
62
63         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)
64                 printf ("Type              : %s\n", type_to_string (info->type));
65
66         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME && info->symlink_name != NULL)
67                 printf ("Symlink to        : %s\n", info->symlink_name);
68
69         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)
70                 printf ("MIME type         : %s\n", info->mime_type);
71
72         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)
73                 printf ("Size              : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
74                                 info->size);
75
76         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)
77                 printf ("Blocks            : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
78                                 info->block_count);
79
80         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE)
81                 printf ("I/O block size    : %d\n", info->io_block_size);
82
83         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_FLAGS) {
84                 printf ("Local             : %s\n", FLAG_STRING (info, LOCAL));
85                 printf ("SUID              : %s\n", FLAG_STRING (info, SUID));
86                 printf ("SGID              : %s\n", FLAG_STRING (info, SGID));
87                 printf ("Sticky            : %s\n", FLAG_STRING (info, STICKY));        }
88
89         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)
90                 printf ("Permissions       : %04o\n", info->permissions);
91
92
93         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)
94                 printf ("Link count        : %d\n", info->link_count);
95
96         printf ("UID               : %d\n", info->uid);
97         printf ("GID               : %d\n", info->gid);
98
99         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME)
100                 printf ("Access time       : %s", ctime (&info->atime));
101
102         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME)
103                 printf ("Modification time : %s", ctime (&info->mtime));
104
105         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME)
106                 printf ("Change time       : %s", ctime (&info->ctime));
107
108         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_DEVICE)
109                 printf ("Device #          : %ld\n", (gulong) info->device);
110
111         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE)
112                 printf ("Inode #           : %ld\n", (gulong) info->inode);
113
114         if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
115                 printf ("Readable          : %s\n",
116                                 (info->permissions&GNOME_VFS_PERM_ACCESS_READABLE?"YES":"NO"));
117                 printf ("Writable          : %s\n",
118                                 (info->permissions&GNOME_VFS_PERM_ACCESS_WRITABLE?"YES":"NO"));
119                 printf ("Executable        : %s\n",
120                                 (info->permissions&GNOME_VFS_PERM_ACCESS_EXECUTABLE?"YES":"NO"));
121         }
122
123 #undef FLAG_STRING
124 }
125
126 int
127 main (int argc, char **argv)
128 {
129         GnomeVFSFileInfo *info;
130
131         if (argc != 2) {
132                 fprintf (stderr, "Usage: %s <uri>\n", argv[0]);
133                 return 1;
134         }
135
136         if (! gnome_vfs_init ()) {
137                 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
138                 return 1;
139         }
140
141         info = gnome_vfs_file_info_new ();
142         gnome_vfs_get_file_info (argv[1], info,
143                         (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
144                          | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS
145                          | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
146         show_file_info (info);
147
148         return 0;
149 }