Back to index

libcitadel  8.12
Classes | Defines | Typedefs | Enumerations | Functions
xdgmimemagic.c File Reference
#include <assert.h>
#include "xdgmimemagic.h"
#include "xdgmimeint.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  XdgMimeMagicMatch
struct  XdgMimeMagicMatchlet
struct  XdgMimeMagic

Defines

#define getc_unlocked(fp)   getc (fp)
#define MAX_NUMBER_SIZE   30

Typedefs

typedef struct XdgMimeMagicMatch
typedef struct XdgMimeMagicMatchlet

Enumerations

enum  XdgMimeMagicState { XDG_MIME_MAGIC_SECTION, XDG_MIME_MAGIC_MAGIC, XDG_MIME_MAGIC_ERROR, XDG_MIME_MAGIC_EOF }

Functions

static XdgMimeMagicMatch_xdg_mime_magic_match_new (void)
static XdgMimeMagicMatchlet_xdg_mime_magic_matchlet_new (void)
static void _xdg_mime_magic_matchlet_free (XdgMimeMagicMatchlet *mime_magic_matchlet)
static void _xdg_mime_magic_match_free (XdgMimeMagicMatch *mime_magic_match)
static unsigned char * _xdg_mime_magic_read_to_newline (FILE *magic_file, int *end_of_file)
static int _xdg_mime_magic_read_a_number (FILE *magic_file, int *end_of_file)
static XdgMimeMagicState _xdg_mime_magic_parse_header (FILE *magic_file, XdgMimeMagicMatch *match)
static XdgMimeMagicState _xdg_mime_magic_parse_error (FILE *magic_file)
static XdgMimeMagicState _xdg_mime_magic_parse_magic_line (FILE *magic_file, XdgMimeMagicMatch *match)
static int _xdg_mime_magic_matchlet_compare_to_data (XdgMimeMagicMatchlet *matchlet, const void *data, size_t len)
static int _xdg_mime_magic_matchlet_compare_level (XdgMimeMagicMatchlet *matchlet, const void *data, size_t len, int indent)
static int _xdg_mime_magic_match_compare_to_data (XdgMimeMagicMatch *match, const void *data, size_t len)
static void _xdg_mime_magic_insert_match (XdgMimeMagic *mime_magic, XdgMimeMagicMatch *match)
XdgMimeMagic_xdg_mime_magic_new (void)
void _xdg_mime_magic_free (XdgMimeMagic *mime_magic)
int _xdg_mime_magic_get_buffer_extents (XdgMimeMagic *mime_magic)
const char * _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, const void *data, size_t len, const char *mime_types[], int n_mime_types)
static void _xdg_mime_update_mime_magic_extents (XdgMimeMagic *mime_magic)
static XdgMimeMagicMatchlet_xdg_mime_magic_matchlet_mirror (XdgMimeMagicMatchlet *matchlets)
static void _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic, FILE *magic_file)
void _xdg_mime_magic_read_from_file (XdgMimeMagic *mime_magic, const char *file_name)

Class Documentation

struct XdgMimeMagicMatch

Definition at line 65 of file xdgmimemagic.c.

Collaboration diagram for XdgMimeMagicMatch:
Class Members
XdgMimeMagicMatchlet * matchlet
const char * mime_type
XdgMimeMagicMatch * next
int priority
struct XdgMimeMagicMatchlet

Definition at line 74 of file xdgmimemagic.c.

Collaboration diagram for XdgMimeMagicMatchlet:
Class Members
int indent
unsigned char * mask
XdgMimeMagicMatchlet * next
int offset
unsigned int range_length
unsigned char * value
unsigned int value_length
unsigned int word_size
struct XdgMimeMagic

Definition at line 87 of file xdgmimemagic.c.

Collaboration diagram for XdgMimeMagic:
Class Members
XdgMimeMagicMatch * match_list
int max_extent

Define Documentation

#define getc_unlocked (   fp)    getc (fp)

Definition at line 51 of file xdgmimemagic.c.

#define MAX_NUMBER_SIZE   30

Typedef Documentation

typedef struct XdgMimeMagicMatch

Definition at line 54 of file xdgmimemagic.c.

typedef struct XdgMimeMagicMatchlet

Definition at line 55 of file xdgmimemagic.c.


Enumeration Type Documentation

Enumerator:
XDG_MIME_MAGIC_SECTION 
XDG_MIME_MAGIC_MAGIC 
XDG_MIME_MAGIC_ERROR 
XDG_MIME_MAGIC_EOF 

Definition at line 57 of file xdgmimemagic.c.


Function Documentation

void _xdg_mime_magic_free ( XdgMimeMagic mime_magic)

Definition at line 643 of file xdgmimemagic.c.

{
  if (mime_magic) {
    _xdg_mime_magic_match_free (mime_magic->match_list);
    free (mime_magic);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 652 of file xdgmimemagic.c.

{
  return mime_magic->max_extent;
}

Here is the caller graph for this function:

static void _xdg_mime_magic_insert_match ( XdgMimeMagic mime_magic,
XdgMimeMagicMatch match 
) [static]

Definition at line 603 of file xdgmimemagic.c.

{
  XdgMimeMagicMatch *list;

  if (mime_magic->match_list == NULL)
    {
      mime_magic->match_list = match;
      return;
    }

  if (match->priority > mime_magic->match_list->priority)
    {
      match->next = mime_magic->match_list;
      mime_magic->match_list = match;
      return;
    }

  list = mime_magic->match_list;
  while (list->next != NULL)
    {
      if (list->next->priority < match->priority)
       {
         match->next = list->next;
         list->next = match;
         return;
       }
      list = list->next;
    }
  list->next = match;
  match->next = NULL;
}

Here is the caller graph for this function:

const char* _xdg_mime_magic_lookup_data ( XdgMimeMagic mime_magic,
const void *  data,
size_t  len,
const char *  mime_types[],
int  n_mime_types 
)

Definition at line 658 of file xdgmimemagic.c.

{
  XdgMimeMagicMatch *match;
  const char *mime_type;
  int n;
  int priority;
  int had_match;

  mime_type = NULL;
  priority = 0;
  had_match = 0;
  for (match = mime_magic->match_list; match; match = match->next)
    {
      if (_xdg_mime_magic_match_compare_to_data (match, data, len))
       {
         if (!had_match || match->priority > priority ||
             (mime_type != NULL && _xdg_mime_mime_type_subclass (match->mime_type, mime_type)))
           {
             mime_type = match->mime_type;
             priority = match->priority;
           }
         else if (had_match && match->priority == priority &&
                 !_xdg_mime_mime_type_subclass (mime_type, match->mime_type))
           /* multiple unrelated patterns with the same priority matched,
            * so we can't tell what type this is. */
           mime_type = NULL;

         had_match = 1;
       }
      else 
       {
         for (n = 0; n < n_mime_types; n++)
           {
             if (mime_types[n] && 
                _xdg_mime_mime_type_equal (mime_types[n], match->mime_type))
              mime_types[n] = NULL;
           }
       }
    }

  if (mime_type == NULL)
    {
      for (n = 0; n < n_mime_types; n++)
       {
         if (mime_types[n])
           mime_type = mime_types[n];
       }
    }

  return mime_type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _xdg_mime_magic_match_compare_to_data ( XdgMimeMagicMatch match,
const void *  data,
size_t  len 
) [static]

Definition at line 595 of file xdgmimemagic.c.

{
  return _xdg_mime_magic_matchlet_compare_level (match->matchlet, data, len, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _xdg_mime_magic_match_free ( XdgMimeMagicMatch mime_magic_match) [static]

Definition at line 139 of file xdgmimemagic.c.

{
  XdgMimeMagicMatch *ptr, *next;

  ptr = mime_magic_match;
  while (ptr)
    {
      next = ptr->next;

      if (ptr->mime_type)
       free ((void *) ptr->mime_type);
      if (ptr->matchlet)
       _xdg_mime_magic_matchlet_free (ptr->matchlet);
      free (ptr);

      ptr = next;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XdgMimeMagicMatch* _xdg_mime_magic_match_new ( void  ) [static]

Definition at line 94 of file xdgmimemagic.c.

{
  return calloc (1, sizeof (XdgMimeMagicMatch));
}

Here is the caller graph for this function:

static int _xdg_mime_magic_matchlet_compare_level ( XdgMimeMagicMatchlet matchlet,
const void *  data,
size_t  len,
int  indent 
) [static]

Definition at line 564 of file xdgmimemagic.c.

{
  while ((matchlet != NULL) && (matchlet->indent == indent))
    {
      if (_xdg_mime_magic_matchlet_compare_to_data (matchlet, data, len))
       {
         if ((matchlet->next == NULL) ||
             (matchlet->next->indent <= indent))
           return TRUE;

         if (_xdg_mime_magic_matchlet_compare_level (matchlet->next,
                                                data,
                                                len,
                                                indent + 1))
           return TRUE;
       }

      do
       {
         matchlet = matchlet->next;
       }
      while (matchlet && matchlet->indent > indent);
    }

  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _xdg_mime_magic_matchlet_compare_to_data ( XdgMimeMagicMatchlet matchlet,
const void *  data,
size_t  len 
) [static]

Definition at line 522 of file xdgmimemagic.c.

{
  int i, j;
  for (i = matchlet->offset; i < matchlet->offset + matchlet->range_length; i++)
    {
      int valid_matchlet = TRUE;

      if (i + matchlet->value_length > len)
       return FALSE;

      if (matchlet->mask)
       {
         for (j = 0; j < matchlet->value_length; j++)
           {
             if ((matchlet->value[j] & matchlet->mask[j]) !=
                ((((unsigned char *) data)[j + i]) & matchlet->mask[j]))
              {
                valid_matchlet = FALSE;
                break;
              }
           }
       }
      else
       {
         for (j = 0; j <  matchlet->value_length; j++)
           {
             if (matchlet->value[j] != ((unsigned char *) data)[j + i])
              {
                valid_matchlet = FALSE;
                break;
              }
           }
       }
      if (valid_matchlet)
       return TRUE;
    }
  return FALSE;
}

Here is the caller graph for this function:

static void _xdg_mime_magic_matchlet_free ( XdgMimeMagicMatchlet mime_magic_matchlet) [static]

Definition at line 121 of file xdgmimemagic.c.

{
  if (mime_magic_matchlet)
    {
      if (mime_magic_matchlet->next)
       _xdg_mime_magic_matchlet_free (mime_magic_matchlet->next);
      if (mime_magic_matchlet->value)
       free (mime_magic_matchlet->value);
      if (mime_magic_matchlet->mask)
       free (mime_magic_matchlet->mask);
      free (mime_magic_matchlet);
    }
}

Here is the caller graph for this function:

Definition at line 738 of file xdgmimemagic.c.

{
  XdgMimeMagicMatchlet *new_list;
  XdgMimeMagicMatchlet *tmp;

  if ((matchlets == NULL) || (matchlets->next == NULL))
    return matchlets;

  new_list = NULL;
  tmp = matchlets;
  while (tmp != NULL)
    {
      XdgMimeMagicMatchlet *matchlet;

      matchlet = tmp;
      tmp = tmp->next;
      matchlet->next = new_list;
      new_list = matchlet;
    }

  return new_list;

}

Here is the caller graph for this function:

Definition at line 101 of file xdgmimemagic.c.

{
  XdgMimeMagicMatchlet *matchlet;

  matchlet = malloc (sizeof (XdgMimeMagicMatchlet));

  matchlet->indent = 0;
  matchlet->offset = 0;
  matchlet->value_length = 0;
  matchlet->value = NULL;
  matchlet->mask = NULL;
  matchlet->range_length = 1;
  matchlet->word_size = 1;
  matchlet->next = NULL;

  return matchlet;
}

Here is the caller graph for this function:

Definition at line 637 of file xdgmimemagic.c.

{
  return calloc (1, sizeof (XdgMimeMagic));
}

Here is the caller graph for this function:

static XdgMimeMagicState _xdg_mime_magic_parse_error ( FILE *  magic_file) [static]

Definition at line 294 of file xdgmimemagic.c.

{
  int c;

  while (1)
    {
      c = getc_unlocked (magic_file);
      if (c == EOF)
       return XDG_MIME_MAGIC_EOF;
      if (c == '\n')
       return XDG_MIME_MAGIC_SECTION;
    }
}

Here is the caller graph for this function:

static XdgMimeMagicState _xdg_mime_magic_parse_header ( FILE *  magic_file,
XdgMimeMagicMatch match 
) [static]

Definition at line 245 of file xdgmimemagic.c.

{
  int c;
  char *buffer;
  char *end_ptr;
  int end_of_file = 0;

  assert (magic_file != NULL);
  assert (match != NULL);

  c = getc_unlocked (magic_file);
  if (c == EOF)
    return XDG_MIME_MAGIC_EOF;
  if (c != '[')
    return XDG_MIME_MAGIC_ERROR;

  match->priority = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
  if (end_of_file)
    return XDG_MIME_MAGIC_EOF;
  if (match->priority == -1)
    return XDG_MIME_MAGIC_ERROR;

  c = getc_unlocked (magic_file);
  if (c == EOF)
    return XDG_MIME_MAGIC_EOF;
  if (c != ':')
    return XDG_MIME_MAGIC_ERROR;

  buffer = (char *)_xdg_mime_magic_read_to_newline (magic_file, &end_of_file);
  if (end_of_file)
    return XDG_MIME_MAGIC_EOF;

  end_ptr = buffer;
  while (*end_ptr != ']' && *end_ptr != '\000' && *end_ptr != '\n')
    end_ptr++;
  if (*end_ptr != ']')
    {
      free (buffer);
      return XDG_MIME_MAGIC_ERROR;
    }
  *end_ptr = '\000';

  match->mime_type = strdup (buffer);
  free (buffer);

  return XDG_MIME_MAGIC_MAGIC;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XdgMimeMagicState _xdg_mime_magic_parse_magic_line ( FILE *  magic_file,
XdgMimeMagicMatch match 
) [static]

Definition at line 313 of file xdgmimemagic.c.

{
  XdgMimeMagicMatchlet *matchlet;
  int c;
  int end_of_file;
  int indent = 0;
  int bytes_read;

  assert (magic_file != NULL);

  /* Sniff the buffer to make sure it's a valid line */
  c = getc_unlocked (magic_file);
  if (c == EOF)
    return XDG_MIME_MAGIC_EOF;
  else if (c == '[')
    {
      ungetc (c, magic_file);
      return XDG_MIME_MAGIC_SECTION;
    }
  else if (c == '\n')
    return XDG_MIME_MAGIC_MAGIC;

  /* At this point, it must be a digit or a '>' */
  end_of_file = FALSE;
  if (isdigit (c))
    {
      ungetc (c, magic_file);
      indent = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
      if (end_of_file)
       return XDG_MIME_MAGIC_EOF;
      if (indent == -1)
       return XDG_MIME_MAGIC_ERROR;
      c = getc_unlocked (magic_file);
      if (c == EOF)
       return XDG_MIME_MAGIC_EOF;
    }

  if (c != '>')
    return XDG_MIME_MAGIC_ERROR;

  matchlet = _xdg_mime_magic_matchlet_new ();
  matchlet->indent = indent;
  matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
  if (end_of_file)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_EOF;
    }
  if (matchlet->offset == -1)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_ERROR;
    }
  c = getc_unlocked (magic_file);
  if (c == EOF)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_EOF;
    }
  else if (c != '=')
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_ERROR;
    }

  /* Next two bytes determine how long the value is */
  matchlet->value_length = 0;
  c = getc_unlocked (magic_file);
  if (c == EOF)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_EOF;
    }
  matchlet->value_length = c & 0xFF;
  matchlet->value_length = matchlet->value_length << 8;

  c = getc_unlocked (magic_file);
  if (c == EOF)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_EOF;
    }
  matchlet->value_length = matchlet->value_length + (c & 0xFF);

  matchlet->value = malloc (matchlet->value_length);

  /* OOM */
  if (matchlet->value == NULL)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      return XDG_MIME_MAGIC_ERROR;
    }
  bytes_read = fread (matchlet->value, 1, matchlet->value_length, magic_file);
  if (bytes_read != matchlet->value_length)
    {
      _xdg_mime_magic_matchlet_free (matchlet);
      if (feof (magic_file))
       return XDG_MIME_MAGIC_EOF;
      else
       return XDG_MIME_MAGIC_ERROR;
    }

  c = getc_unlocked (magic_file);
  if (c == '&')
    {
      matchlet->mask = malloc (matchlet->value_length);
      /* OOM */
      if (matchlet->mask == NULL)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         return XDG_MIME_MAGIC_ERROR;
       }
      bytes_read = fread (matchlet->mask, 1, matchlet->value_length, magic_file);
      if (bytes_read != matchlet->value_length)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         if (feof (magic_file))
           return XDG_MIME_MAGIC_EOF;
         else
           return XDG_MIME_MAGIC_ERROR;
       }
      c = getc_unlocked (magic_file);
    }

  if (c == '~')
    {
      matchlet->word_size = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
      if (end_of_file)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         return XDG_MIME_MAGIC_EOF;
       }
      if (matchlet->word_size != 0 &&
         matchlet->word_size != 1 &&
         matchlet->word_size != 2 &&
         matchlet->word_size != 4)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         return XDG_MIME_MAGIC_ERROR;
       }
      c = getc_unlocked (magic_file);
    }

  if (c == '+')
    {
      matchlet->range_length = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
      if (end_of_file)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         return XDG_MIME_MAGIC_EOF;
       }
      if (matchlet->range_length == -1)
       {
         _xdg_mime_magic_matchlet_free (matchlet);
         return XDG_MIME_MAGIC_ERROR;
       }
      c = getc_unlocked (magic_file);
    }


  if (c == '\n')
    {
      /* We clean up the matchlet, byte swapping if needed */
      if (matchlet->word_size > 1)
       {
#if LITTLE_ENDIAN
         int i;
#endif
         if (matchlet->value_length % matchlet->word_size != 0)
           {
             _xdg_mime_magic_matchlet_free (matchlet);
             return XDG_MIME_MAGIC_ERROR;
           }
         /* FIXME: need to get this defined in a <config.h> style file */
#if LITTLE_ENDIAN
         for (i = 0; i < matchlet->value_length; i = i + matchlet->word_size)
           {
             if (matchlet->word_size == 2)
              *((xdg_uint16_t *) matchlet->value + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->value + i)));
             else if (matchlet->word_size == 4)
              *((xdg_uint32_t *) matchlet->value + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->value + i)));
             if (matchlet->mask)
              {
                if (matchlet->word_size == 2)
                  *((xdg_uint16_t *) matchlet->mask + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->mask + i)));
                else if (matchlet->word_size == 4)
                  *((xdg_uint32_t *) matchlet->mask + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->mask + i)));

              }
           }
#endif
       }

      matchlet->next = match->matchlet;
      match->matchlet = matchlet;


      return XDG_MIME_MAGIC_MAGIC;
    }

  _xdg_mime_magic_matchlet_free (matchlet);
  if (c == EOF)
    return XDG_MIME_MAGIC_EOF;

  return XDG_MIME_MAGIC_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _xdg_mime_magic_read_a_number ( FILE *  magic_file,
int *  end_of_file 
) [static]

Definition at line 199 of file xdgmimemagic.c.

{
  /* LONG_MAX is about 20 characters on my system */
#define MAX_NUMBER_SIZE 30
  char number_string[MAX_NUMBER_SIZE + 1];
  int pos = 0;
  int c;
  long retval = -1;

  while (TRUE)
    {
      c = getc_unlocked (magic_file);

      if (c == EOF)
       {
         *end_of_file = TRUE;
         break;
       }
      if (! isdigit (c))
       {
         ungetc (c, magic_file);
         break;
       }
      number_string[pos] = (char) c;
      pos++;
      if (pos == MAX_NUMBER_SIZE)
       break;
    }
  if (pos > 0)
    {
      number_string[pos] = '\000';
      errno = 0;
      retval = strtol (number_string, NULL, 10);

      if ((retval < INT_MIN) || (retval > INT_MAX) || (errno != 0))
       return -1;
    }

  return retval;
}

Here is the caller graph for this function:

void _xdg_mime_magic_read_from_file ( XdgMimeMagic mime_magic,
const char *  file_name 
)

Definition at line 805 of file xdgmimemagic.c.

{
  FILE *magic_file;
  char header[12];

  magic_file = fopen (file_name, "r");

  if (magic_file == NULL)
    return;

  if (fread (header, 1, 12, magic_file) == 12)
    {
      if (memcmp ("MIME-Magic\0\n", header, 12) == 0)
        _xdg_mime_magic_read_magic_file (mime_magic, magic_file);
    }

  fclose (magic_file);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _xdg_mime_magic_read_magic_file ( XdgMimeMagic mime_magic,
FILE *  magic_file 
) [static]

Definition at line 763 of file xdgmimemagic.c.

{
  XdgMimeMagicState state;
  XdgMimeMagicMatch *match = NULL; /* Quiet compiler */

  state = XDG_MIME_MAGIC_SECTION;

  while (state != XDG_MIME_MAGIC_EOF)
    {
      switch (state)
       {
       case XDG_MIME_MAGIC_SECTION:
         match = _xdg_mime_magic_match_new ();
         state = _xdg_mime_magic_parse_header (magic_file, match);
         if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
           _xdg_mime_magic_match_free (match);
         break;
       case XDG_MIME_MAGIC_MAGIC:
         state = _xdg_mime_magic_parse_magic_line (magic_file, match);
         if (state == XDG_MIME_MAGIC_SECTION ||
             (state == XDG_MIME_MAGIC_EOF && match->mime_type))
           {
             match->matchlet = _xdg_mime_magic_matchlet_mirror (match->matchlet);
             _xdg_mime_magic_insert_match (mime_magic, match);
           }
         else if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
           _xdg_mime_magic_match_free (match);
         break;
       case XDG_MIME_MAGIC_ERROR:
         state = _xdg_mime_magic_parse_error (magic_file);
         break;
       case XDG_MIME_MAGIC_EOF:
       default:
         /* Make the compiler happy */
         assert (0);
       }
    }
  _xdg_mime_update_mime_magic_extents (mime_magic);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned char* _xdg_mime_magic_read_to_newline ( FILE *  magic_file,
int *  end_of_file 
) [static]

Definition at line 162 of file xdgmimemagic.c.

{
  unsigned char *retval;
  int c;
  int len, pos;

  len = 128;
  pos = 0;
  retval = malloc (len);
  *end_of_file = FALSE;

  while (TRUE)
    {
      c = getc_unlocked (magic_file);
      if (c == EOF)
       {
         *end_of_file = TRUE;
         break;
       }
      if (c == '\n' || c == '\000')
       break;
      retval[pos++] = (unsigned char) c;
      if (pos % 128 == 127)
       {
         len = len + 128;
         retval = realloc (retval, len);
       }
    }

  retval[pos] = '\000';
  return retval;
}

Here is the caller graph for this function:

static void _xdg_mime_update_mime_magic_extents ( XdgMimeMagic mime_magic) [static]

Definition at line 715 of file xdgmimemagic.c.

{
  XdgMimeMagicMatch *match;
  int max_extent = 0;

  for (match = mime_magic->match_list; match; match = match->next)
    {
      XdgMimeMagicMatchlet *matchlet;

      for (matchlet = match->matchlet; matchlet; matchlet = matchlet->next)
       {
         int extent;

         extent = matchlet->value_length + matchlet->offset + matchlet->range_length;
         if (max_extent < extent)
           max_extent = extent;
       }
    }

  mime_magic->max_extent = max_extent;
}

Here is the caller graph for this function: