[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using libmagic in Emacs?
From: |
Andreas Schwab |
Subject: |
Re: using libmagic in Emacs? |
Date: |
Fri, 21 Aug 2009 00:08:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
address@hidden 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
> <http://www.gnu.org/licenses/>. */
> /* 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 <magic.h>
> +#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, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
- Re: using libmagic in Emacs?, (continued)
- Re: using libmagic in Emacs?, Richard Stallman, 2009/08/20
- Re: using libmagic in Emacs?, Stefan Monnier, 2009/08/21
- Re: using libmagic in Emacs?, Stephen J. Turnbull, 2009/08/22
- Re: using libmagic in Emacs?, Stefan Monnier, 2009/08/22
- Re: using libmagic in Emacs?, Stefan Monnier, 2009/08/20
- Re: using libmagic in Emacs?, joakim, 2009/08/20
- Re: using libmagic in Emacs?,
Andreas Schwab <=
- Re: using libmagic in Emacs?, joakim, 2009/08/21
- Re: using libmagic in Emacs?, Eli Zaretskii, 2009/08/21
- Re: using libmagic in Emacs?, joakim, 2009/08/21
- Re: using libmagic in Emacs?, Rupert Swarbrick, 2009/08/21
- Re: using libmagic in Emacs?, Andreas Schwab, 2009/08/21
- RE: using libmagic in Emacs?, Drew Adams, 2009/08/21
- Re: using libmagic in Emacs?, Eli Zaretskii, 2009/08/21
- Re: using libmagic in Emacs?, joakim, 2009/08/21
- Re: using libmagic in Emacs?, Andreas Schwab, 2009/08/21
- Re: using libmagic in Emacs?, joakim, 2009/08/22