diff options
Diffstat (limited to 'gtk/xdgmime')
-rw-r--r-- | gtk/xdgmime/ChangeLog | 8 | ||||
-rw-r--r-- | gtk/xdgmime/test-mime.c | 2 | ||||
-rw-r--r-- | gtk/xdgmime/xdgmime.c | 18 | ||||
-rw-r--r-- | gtk/xdgmime/xdgmime.h | 4 |
4 files changed, 25 insertions, 7 deletions
diff --git a/gtk/xdgmime/ChangeLog b/gtk/xdgmime/ChangeLog index efaa26cc3f..0c8a7a79cf 100644 --- a/gtk/xdgmime/ChangeLog +++ b/gtk/xdgmime/ChangeLog @@ -1,3 +1,11 @@ +2005-09-01 Matthias Clasen <mclasen@redhat.com> + + * xdgmime.h: + * xdgmime.c (xdg_mime_get_mime_type_for_file): Take + a struct statbuf * as argument. + + * test-mime.c (main): Adjust. + 2005-08-24 Matthias Clasen <mclasen@redhat.com> * === Released 2.8.2 === diff --git a/gtk/xdgmime/test-mime.c b/gtk/xdgmime/test-mime.c index b0bcc875fe..9364cf8238 100644 --- a/gtk/xdgmime/test-mime.c +++ b/gtk/xdgmime/test-mime.c @@ -108,7 +108,7 @@ main (int argc, char *argv[]) for (i = 1; i < argc; i++) { file_name = argv[i]; - result = xdg_mime_get_mime_type_for_file (file_name); + result = xdg_mime_get_mime_type_for_file (file_name, NULL); printf ("File \"%s\" has a mime-type of %s\n", file_name, result); } diff --git a/gtk/xdgmime/xdgmime.c b/gtk/xdgmime/xdgmime.c index c7ac59290a..bc8eeaf01a 100644 --- a/gtk/xdgmime/xdgmime.c +++ b/gtk/xdgmime/xdgmime.c @@ -447,14 +447,15 @@ xdg_mime_get_mime_type_for_data (const void *data, } const char * -xdg_mime_get_mime_type_for_file (const char *file_name) +xdg_mime_get_mime_type_for_file (const char *file_name, + struct stat *statbuf) { const char *mime_type; FILE *file; unsigned char *data; int max_extent; int bytes_read; - struct stat statbuf; + struct stat buf; const char *base_name; if (file_name == NULL) @@ -473,10 +474,17 @@ xdg_mime_get_mime_type_for_file (const char *file_name) if (mime_type != XDG_MIME_TYPE_UNKNOWN) return mime_type; - if (stat (file_name, &statbuf) != 0) - return XDG_MIME_TYPE_UNKNOWN; + if (!statbuf) + { + if (stat (file_name, &buf) != 0) + return XDG_MIME_TYPE_UNKNOWN; + + statbuf = &buf; + } + else + printf ("don't restat\n"); - if (!S_ISREG (statbuf.st_mode)) + if (!S_ISREG (statbuf->st_mode)) return XDG_MIME_TYPE_UNKNOWN; /* FIXME: Need to make sure that max_extent isn't totally broken. This could diff --git a/gtk/xdgmime/xdgmime.h b/gtk/xdgmime/xdgmime.h index 92ee60e26a..d07cfded9d 100644 --- a/gtk/xdgmime/xdgmime.h +++ b/gtk/xdgmime/xdgmime.h @@ -30,6 +30,7 @@ #define __XDG_MIME_H__ #include <stdlib.h> +#include <sys/stat.h> #ifdef __cplusplus extern "C" { @@ -69,7 +70,8 @@ extern const char *xdg_mime_type_unknown; const char *xdg_mime_get_mime_type_for_data (const void *data, size_t len); -const char *xdg_mime_get_mime_type_for_file (const char *file_name); +const char *xdg_mime_get_mime_type_for_file (const char *file_name, + struct stat *statbuf); const char *xdg_mime_get_mime_type_from_file_name (const char *file_name); int xdg_mime_is_valid_mime_type (const char *mime_type); int xdg_mime_mime_type_equal (const char *mime_a, |