New libmagic patch, mostly fixing Andreas concerns, and some more error handling. I dont understand the autoheader comment below though. When I originaly compiled, the config.h wasnt generated with the libmagic info included, did I do something wrong? Is autoheader supposed to generate config.in? When does that happen? /Joakim Andreas Schwab writes: > joakim@verona.se writes: > >> diff --git a/configure.in b/configure.in >> index f4096db..cb74523 100644 >> --- a/configure.in >> +++ b/configure.in >> @@ -137,6 +137,8 @@ OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts]) >> OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support]) >> OPTION_DEFAULT_ON([m17n-flt],[don't use m17n-flt for text shaping]) >> >> +OPTION_DEFAULT_ON([filemagic],[don't compile with filemagic support]) > > IMHO the option should be named libmagic, since that's how the library > is named. > >> diff --git a/src/config.in b/src/config.in >> index 404e00b..c966a09 100644 >> --- a/src/config.in >> +++ b/src/config.in >> @@ -262,6 +262,9 @@ along with GNU Emacs. If not, see . */ >> /* Define to 1 if you have the gpm library (-lgpm). */ >> #undef HAVE_GPM >> >> +/* Define to 1 if you have the filemagic library (-lmagic). */ >> +#undef HAVE_LIBMAGIC >> + >> /* Define to 1 if you have the `grantpt' function. */ >> #undef HAVE_GRANTPT >> > > This is generated by autoheader. > >> diff --git a/src/fileio.c b/src/fileio.c >> index 3702d4c..375502e 100644 >> --- a/src/fileio.c >> +++ b/src/fileio.c >> @@ -205,6 +205,10 @@ Lisp_Object Vdirectory_sep_char; >> int write_region_inhibit_fsync; >> #endif >> >> +#ifdef HAVE_LIBMAGIC >> +#include >> +#endif >> + >> /* Non-zero means call move-file-to-trash in Fdelete_file or >> Fdelete_directory. */ >> int delete_by_moving_to_trash; >> @@ -2997,6 +3001,45 @@ DEFUN ("unix-sync", Funix_sync, Sunix_sync, 0, 0, "", >> >> #endif /* HAVE_SYNC */ >> >> +#ifdef HAVE_LIBMAGIC >> +DEFUN ("file-magic-file", Ffile_magic_file, Sfile_magic_file, 1,1,0, >> + doc: /* Return (MIME_TYPE MIME_ENCODING DESCRIPTION) for FILENAME. >> +Return nil on error. */) >> + (filename) >> + Lisp_Object filename; >> +{ >> + magic_t cookie=NULL; >> + if (!STRINGP (filename)) goto libmagic_error; > > Just use CHECK_STRING. > >> + char* f = SDATA (filename); >> + char* rvs; > > No C99 features yet. Be careful with raw string pointers and GC. > >> + cookie = magic_open (MAGIC_NONE); >> + magic_load (cookie,NULL); //load default database > > if (cookie == NULL) ? > >> + >> + magic_setflags (cookie, MAGIC_MIME_TYPE); >> + rvs = magic_file (cookie, f); >> + if (rvs == NULL) goto libmagic_error; > > Use report_file_error, provided that magic_file sets errno appropriately. > >> + Lisp_Object file_freetext = make_specified_string (rvs, strlen(rvs), strlen(rvs), NULL); > > Use build_string. > > Andreas.