comments on libmagic
Christos Zoulas
christos at zoulas.com
Tue Oct 14 17:51:58 EDT 2003
On Oct 14, 3:28pm, brettf at deepfile.com ("Brett Funderburg") wrote:
-- Subject: Re: comments on libmagic
| Yes, this seems like the best way to preserve backward api compatibility
| for now.
|
| >
| > ms = magic_open(MAGIG_ERROR);
| >
| > if ((result = magic_file(ms, fn)) == NULL) {
| > int error = magic_errno(ms);
| > if (error == 0)
| > // File internal error
| > fprintf("%s: %s\n", fn, magic_error(ms));
| > else
| > // Os error
| > fprintf("%s: %s\n", fn, strerror(error));
| > }
| >
| > In fact, I have implemented all this already...
| >
|
| In my example, I used a hypothetical new api (magic_errno) to get the
| integer value of the error. You're suggesting changing the default
| behavior via a flag, yet your code example above also uses magic_errno.
| Did you intend for this to be 'magic_error' instead?
No, that was what I intended. magic_errno() always returns the system's
errno value if the error was caused by a system related error and 0
if it was an error internal to libmagic.
| Using your example, how would I know whether the call to magic_file
| succeeded or not? With the current libmagic, giving a path to a
| non-existent file still results in a non-NULL value being assigned to
| 'result'. This gives the appearance that the call succeeded. I could see
| two potential problems:
|
| * unable to determine whether magic_file succeeded or failed based on
| return value alone.
| * unable to determine whether magic_file succeeded by calling magic_error
| since there is no 'success' error code. (0 = internal error, non-0 = OS
| error)
|
| What am I missing?
That I am passing MAGIC_ERROR ro magic_open, and this changes the default
behavior of magic_file() to return NULL on system related errors. This is
a new flag that I just added, that causes magic_file() to return NULL in
the cases you want to handle the error yourself.
christos
More information about the File
mailing list