~ubuntu-branches/ubuntu/quantal/libfm/quantal

« back to all changes in this revision

Viewing changes to src/base/fm-mime-type.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-02-21 21:55:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110221215543-m7gn2snkhpk1kk9u
Tags: 0.1.15+git-3625952cea-0ubuntu1
* New upstream snapshot (2011-02-15)
 - Use x-schemas-handler (LP: #683922)
* debian/patches/
 - 90_add_gobject_link.patch: Remove, merged upstream.
 - 02-libfm-0.1.14-API-changes.patch: Refresh.
 - 03_disable_deprecated_gio_module.patch: Refresh.
 - 04_fix_docs_linker.patch: Fix DSO linking in docs/.
* debian/libfm0.install:
 - Remove usr/lib/libfm/gnome-terminal, dropped upstream.
 - Remove gio module, dropped upstream.
* debian/rules:
 - Add --enable-gtk-doc to configure.
* debian/libfm-gtk0.symbols:
 - Update with new symbols.
* debian/apport/source_libfm.py
 - Fix location of pcmanfm config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
 
89
89
    if( S_ISREG(pstat->st_mode) )
90
90
    {
91
 
                gboolean uncertain;
92
 
                char* type = g_content_type_guess( base_name, NULL, 0, &uncertain );
93
 
                if( uncertain )
94
 
                {
95
 
                        int fd, len;
96
 
                        if( pstat->st_size == 0 ) /* empty file = text file with 0 characters in it. */
97
 
                                return fm_mime_type_get_for_type( "text/plain" );
98
 
                        fd = open(file_path, O_RDONLY);
99
 
                        if( fd >= 0 )
100
 
                        {
101
 
                        #ifdef HAVE_MMAP
102
 
                                const char* buf;
103
 
                                len = pstat->st_size > 4096 ? 4096 : pstat->st_size;
104
 
                                buf = (const char*)mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
105
 
                                if(G_LIKELY(buf != MAP_FAILED))
106
 
                                {
107
 
                                        g_free(type);
108
 
                                        type = g_content_type_guess( NULL, buf, len, &uncertain );
109
 
                                        munmap(buf, len);
110
 
                                }
111
 
                        #else
112
 
                                char buf[4096];
113
 
                                len = read(fd, buf, 4096);
114
 
                                g_free(type);
115
 
                                type = g_content_type_guess( NULL, buf, len, &uncertain );
116
 
                        #endif
117
 
                                close(fd);
118
 
                        }
119
 
                }
120
 
                mime_type = fm_mime_type_get_for_type( type );
121
 
                g_free(type);
122
 
                return mime_type;
 
91
        gboolean uncertain;
 
92
        char* type = g_content_type_guess( base_name, NULL, 0, &uncertain );
 
93
        if( uncertain )
 
94
        {
 
95
            int fd, len;
 
96
            if( pstat->st_size == 0 ) /* empty file = text file with 0 characters in it. */
 
97
                return fm_mime_type_get_for_type( "text/plain" );
 
98
            fd = open(file_path, O_RDONLY);
 
99
            if( fd >= 0 )
 
100
            {
 
101
            #ifdef HAVE_MMAP
 
102
                const char* buf;
 
103
                len = pstat->st_size > 4096 ? 4096 : pstat->st_size;
 
104
                buf = (const char*)mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
 
105
                if(G_LIKELY(buf != MAP_FAILED))
 
106
                {
 
107
                    g_free(type);
 
108
                    type = g_content_type_guess( NULL, buf, len, &uncertain );
 
109
                    munmap(buf, len);
 
110
                }
 
111
            #else
 
112
                char buf[4096];
 
113
                len = read(fd, buf, 4096);
 
114
                g_free(type);
 
115
                type = g_content_type_guess( NULL, buf, len, &uncertain );
 
116
            #endif
 
117
                close(fd);
 
118
            }
 
119
        }
 
120
        mime_type = fm_mime_type_get_for_type( type );
 
121
        g_free(type);
 
122
        return mime_type;
123
123
    }
124
124
 
125
125
    if( S_ISDIR(pstat->st_mode) )
137
137
        return fm_mime_type_get_for_type( "inode/socket" );
138
138
#endif
139
139
    /* impossible */
140
 
    g_error( "Invalid stat mode: %s", base_name );
141
 
    return NULL;
 
140
    g_debug( "Invalid stat mode: %d, %s", pstat->st_mode & S_IFMT, base_name );
 
141
    /* FIXME: some files under /proc/self has st_mode = 0, which causes problems.
 
142
     *        currently we treat them as files of unknown type. */
 
143
    return fm_mime_type_get_for_type( "application/octet-stream" );
142
144
}
143
145
 
144
146
FmMimeType* fm_mime_type_get_for_type( const char* type )