unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: Nordlöw <per.nordlow@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Efficiently checking the initial contents of a file
Date: Thu, 22 May 2008 18:58:44 +0200	[thread overview]
Message-ID: <87ej7unum3.fsf@ambire.localdomain> (raw)
In-Reply-To: <1d68e58f-5183-49a5-a588-aa7826dee7c0@l64g2000hse.googlegroups.com> ("Nordlöw"'s message of "Mon, 19 May 2008 00:20:26 -0700 (PDT)")

() Nordlöw <per.nordlow@gmail.com>
() Mon, 19 May 2008 00:20:26 -0700 (PDT)

   Is I see it the most general and efficient solution
   to this problem would be to

Hmm, i tend to find "most general" and "most efficient"
to be mutually exclusive.  Perhaps we have different
ideas of what is general and what is efficient.

Here is a relatively efficient and highly parsimonious
way, made by squeezing the ideas previously presented
by others into a lower-bound wrap-check:

(defun elf-p (filename)
  (when (< 4 (nth 7 (file-attributes filename)))
    (with-temp-buffer
      (insert-file-contents filename nil 0 4)
      (string= "\x7fELF" (buffer-string)))))

For a "most general" way, i'm in the process of
implementing a file(1)-workalike in Emacs Lisp.  For a
peek at its design, you can see the sexp-based ruleset
(and a Scheme prototype linked therefrom) at:

http://www.gnuvola.org/data/  (de-uglified magic file)

Lastly, if the original problem uses `elf-p' as a
filter, unless you labor under a pitifully degrading
(eg., usloth) environment, you may find the "best way"
is to use `file-executable-p' instead.

thi




      reply	other threads:[~2008-05-22 16:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 10:16 Efficiently checking the initial contents of a file Nordlöw
2008-05-16 11:08 ` Juanma Barranquero
2008-05-16 11:12 ` David Hansen
2008-05-16 11:15 ` Eli Zaretskii
     [not found] ` <mailman.11680.1210937109.18990.help-gnu-emacs@gnu.org>
2008-05-16 12:52   ` Nordlöw
2008-05-16 14:03     ` Juanma Barranquero
     [not found]     ` <mailman.11696.1210946594.18990.help-gnu-emacs@gnu.org>
2008-05-19  7:20       ` Nordlöw
2008-05-22 16:58         ` Thien-Thi Nguyen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ej7unum3.fsf@ambire.localdomain \
    --to=ttn@gnuvola.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=per.nordlow@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).