source: trunk/third/gnome-vfs/test/test-info.c @ 15858

Revision 15858, 4.8 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15857, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* test-info.c - Test program for the `get_file_info()' functionality of the
3   GNOME Virtual File System.
4
5   Copyright (C) 1999 Free Software Foundation
6
7   The Gnome Library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Library General Public License as
9   published by the Free Software Foundation; either version 2 of the
10   License, or (at your option) any later version.
11
12   The Gnome Library is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   Library General Public License for more details.
16
17   You should have received a copy of the GNU Library General Public
18   License along with the Gnome Library; see the file COPYING.LIB.  If not,
19   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20   Boston, MA 02111-1307, USA.
21
22   Author: Ettore Perazzoli <ettore@comm2000.it> */
23
24
25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
29#include <gnome.h>
30
31#include "gnome-vfs.h"
32
33static const gchar *
34type_to_string (GnomeVFSFileType type)
35{
36        switch (type) {
37        case GNOME_VFS_FILE_TYPE_UNKNOWN:
38                return "Unknown";
39        case GNOME_VFS_FILE_TYPE_REGULAR:
40                return "Regular";
41        case GNOME_VFS_FILE_TYPE_DIRECTORY:
42                return "Directory";
43        case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
44                return "Symbolic Link";
45        case GNOME_VFS_FILE_TYPE_FIFO:
46                return "FIFO";
47        case GNOME_VFS_FILE_TYPE_SOCKET:
48                return "Socket";
49        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
50                return "Character device";
51        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
52                return "Block device";
53        default:
54                return "???";
55        }
56}
57
58
59static void
60print_file_info (const GnomeVFSFileInfo *info)
61{
62#define FLAG_STRING(info, which)                                \
63        (GNOME_VFS_FILE_INFO_##which (info) ? "YES" : "NO")
64
65        printf ("Name              : %s\n", info->name);
66
67        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)
68                printf ("Type              : %s\n", type_to_string (info->type));
69
70        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME && info->symlink_name != NULL)
71                printf ("Symlink to        : %s\n", info->symlink_name);
72
73        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)
74                printf ("MIME type         : %s\n", info->mime_type);
75
76        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)
77                printf ("Size              : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
78                        info->size);
79
80        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)
81                printf ("Blocks            : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
82                        info->block_count);
83
84        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE)
85                printf ("I/O block size    : %d\n", info->io_block_size);
86
87        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_FLAGS) {
88                printf ("Local             : %s\n", FLAG_STRING (info, LOCAL));
89                printf ("SUID              : %s\n", FLAG_STRING (info, SUID));
90                printf ("SGID              : %s\n", FLAG_STRING (info, SGID));
91                printf ("Sticky            : %s\n", FLAG_STRING (info, STICKY));
92        }
93
94        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)
95                printf ("Permissions       : %04o\n", info->permissions);
96
97       
98        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)
99                printf ("Link count        : %d\n", info->link_count);
100       
101        printf ("UID               : %d\n", info->uid);
102        printf ("GID               : %d\n", info->gid);
103
104        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME)
105                printf ("Access time       : %s", ctime (&info->atime));
106
107        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME)
108                printf ("Modification time : %s", ctime (&info->mtime));
109
110        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME)
111                printf ("Change time       : %s", ctime (&info->ctime));
112
113        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_DEVICE)
114                printf ("Device #          : %ld\n", (gulong) info->device);
115
116        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE)
117                printf ("Inode #           : %ld\n", (gulong) info->inode);
118
119
120#undef FLAG_STRING
121}
122
123int
124main (int argc,
125      char **argv)
126{
127        GnomeVFSFileInfo *info;
128        GnomeVFSResult result;
129        gchar *uri;
130        int i=1;
131
132        if (argc < 2) {
133                fprintf (stderr, "Usage: %s <uri> [<uri>...]\n", argv[0]);
134                return 1;
135        }
136
137        if (!gnome_vfs_init ()) {
138                fprintf (stderr, "%s: Cannot initialize the GNOME Virtual File System.\n",
139                         argv[0]);
140                return 1;
141        }
142
143        while (i < argc) {
144
145                uri = argv[i];
146
147                g_print("Getting info for \"%s\".\n", uri);
148
149                info = gnome_vfs_file_info_new ();
150                result = gnome_vfs_get_file_info (uri,
151                                                  info,
152                                                  (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
153                                                   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
154                if (result != GNOME_VFS_OK) {
155                        fprintf (stderr, "%s: %s: %s\n",
156                                 argv[0], uri, gnome_vfs_result_to_string (result));
157                        i++;
158                        return result;
159                }
160
161                print_file_info (info);
162
163                gnome_vfs_file_info_unref (info);
164
165                i++;
166        }
167
168        return 0;
169}
Note: See TracBrowser for help on using the repository browser.