From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Schwab Newsgroups: gmane.emacs.devel Subject: Re: using libmagic in Emacs? Date: Fri, 21 Aug 2009 00:08:21 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1250806128 21064 80.91.229.12 (20 Aug 2009 22:08:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Aug 2009 22:08:48 +0000 (UTC) Cc: Stefan Monnier , Emacs Development To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 21 00:08:41 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MeFoG-0002mB-Nw for ged-emacs-devel@m.gmane.org; Fri, 21 Aug 2009 00:08:41 +0200 Original-Received: from localhost ([127.0.0.1]:41785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeFoF-0005x4-Gv for ged-emacs-devel@m.gmane.org; Thu, 20 Aug 2009 18:08:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeFoB-0005wz-Bt for emacs-devel@gnu.org; Thu, 20 Aug 2009 18:08:35 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeFo7-0005wn-DS for emacs-devel@gnu.org; Thu, 20 Aug 2009 18:08:35 -0400 Original-Received: from [199.232.76.173] (port=38516 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeFo7-0005wk-8e for emacs-devel@gnu.org; Thu, 20 Aug 2009 18:08:31 -0400 Original-Received: from mail-out.m-online.net ([212.18.0.10]:52026) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MeFo6-0005Bf-Mg for emacs-devel@gnu.org; Thu, 20 Aug 2009 18:08:31 -0400 Original-Received: from mail01.m-online.net (mail.m-online.net [192.168.3.149]) by mail-out.m-online.net (Postfix) with ESMTP id AD2101C0018E; Fri, 21 Aug 2009 00:08:25 +0200 (CEST) Original-Received: from localhost (dynscan2.mnet-online.de [192.168.1.215]) by mail.m-online.net (Postfix) with ESMTP id 96627902A7; Fri, 21 Aug 2009 00:08:25 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Original-Received: from mail.mnet-online.de ([192.168.3.149]) by localhost (dynscan2.mnet-online.de [192.168.1.215]) (amavisd-new, port 10024) with ESMTP id zEgC2Lf6hvat; Fri, 21 Aug 2009 00:08:24 +0200 (CEST) Original-Received: from igel.home (DSL01.83.171.185.220.ip-pool.NEFkom.net [83.171.185.220]) by mail.mnet-online.de (Postfix) with ESMTP; Fri, 21 Aug 2009 00:08:23 +0200 (CEST) Original-Received: by igel.home (Postfix, from userid 501) id 3CF05C8C06; Fri, 21 Aug 2009 00:08:22 +0200 (CEST) X-Yow: This is my WILLIAM BENDIX memorial CORNER where I worship William Bendix like a GOD!! In-Reply-To: (joakim@verona.se's message of "Thu, 20 Aug 2009 21:19:28 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114465 Archived-At: 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. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."