89
89
if( S_ISREG(pstat->st_mode) )
92
char* type = g_content_type_guess( base_name, NULL, 0, &uncertain );
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);
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))
108
type = g_content_type_guess( NULL, buf, len, &uncertain );
113
len = read(fd, buf, 4096);
115
type = g_content_type_guess( NULL, buf, len, &uncertain );
120
mime_type = fm_mime_type_get_for_type( type );
92
char* type = g_content_type_guess( base_name, NULL, 0, &uncertain );
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);
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))
108
type = g_content_type_guess( NULL, buf, len, &uncertain );
113
len = read(fd, buf, 4096);
115
type = g_content_type_guess( NULL, buf, len, &uncertain );
120
mime_type = fm_mime_type_get_for_type( type );
125
125
if( S_ISDIR(pstat->st_mode) )
137
137
return fm_mime_type_get_for_type( "inode/socket" );
140
g_error( "Invalid stat mode: %s", base_name );
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" );
144
146
FmMimeType* fm_mime_type_get_for_type( const char* type )