gettext-devel
meson
-build:meson:
+build:autotools:
before_script:
- dnf update -y --nogpgcheck
- dnf install -y --nogpgcheck $DEPENDENCIES
# Compile shared-mime-info
- git clone https://gitlab.freedesktop.org/xdg/shared-mime-info.git
- cd shared-mime-info
+ - meson _build -Dxdgmime-path=$PWD/../
+ - ninja -C _build test
+
+build:meson:
+ before_script:
+ - dnf update -y --nogpgcheck
+ - dnf install -y --nogpgcheck $DEPENDENCIES
+ script:
- meson _build
+ - ninja -C _build
+
+ # Compile shared-mime-info
+ - git clone https://gitlab.freedesktop.org/xdg/shared-mime-info.git
+ - cd shared-mime-info
+ - meson _build -Dxdgmime-path=$PWD/../_build/
- ninja -C _build test
--- /dev/null
+project('xdgmime', 'c',
+ version: '0.0',
+ default_options: ['c_std=c99', 'warning_level=1', 'debug=true'],
+ meson_version: '>=0.48.0',
+)
+
+add_project_arguments(
+ '-D_POSIX_C_SOURCE=200809L',
+ '-DXDG_PREFIX=xdg_test',
+ '-DHAVE_MMAP',
+ '-Wmissing-prototypes',
+ '-Wno-sign-compare',
+ language: 'c',
+ native: true,
+)
+
+subdir('src')
+.POSIX:
+.PHONY: all clean
-CFLAGS=-Wall -Wmissing-prototypes -Wno-sign-compare -g -DXDG_PREFIX=xdg_test -DHAVE_MMAP
+C_STD = -std=c99 -D_POSIX_C_SOURCE=200809L
+ALL_CFLAGS = $(C_STD) -c -g -DXDG_PREFIX=xdg_test -DHAVE_MMAP -Wall -Wmissing-prototypes -Wno-sign-compare $(CFLAGS)
+
+.c.o:
+ $(CC) $(ALL_CFLAGS) -o $@ $<
all: test-mime test-mime-data print-mime-data
-test-mime: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+test-mime: test-mime.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+ $(CC) $(LDFLAGS) -o $@ $?
-test-mime-data: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+test-mime-data: test-mime-data.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+ $(CC) $(LDFLAGS) -o $@ $?
-print-mime-data: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+print-mime-data: print-mime-data.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+ $(CC) $(LDFLAGS) -o $@ $?
clean:
rm -f *~ *.o test-mime test-mime-data print-mime-data
-
--- /dev/null
+libcommon = static_library('common',
+ 'xdgmime.c',
+ 'xdgmimeglob.c',
+ 'xdgmimeint.c',
+ 'xdgmimemagic.c',
+ 'xdgmimealias.c',
+ 'xdgmimeparent.c',
+ 'xdgmimecache.c',
+ 'xdgmimeicon.c',
+ native: true,
+)
+
+test_mime = executable('test-mime',
+ 'test-mime.c',
+ link_with: libcommon,
+ native: true,
+ install: false,
+)
+meson.override_find_program('test-mime', test_mime)
+
+test_mime_data = executable('test-mime-data',
+ 'test-mime-data.c',
+ link_with: libcommon,
+ native: true,
+ install: false,
+)
+meson.override_find_program('test-mime-data', test_mime_data)
+
+print_mime_data = executable('print-mime-data',
+ 'print-mime-data.c',
+ link_with: libcommon,
+ native: true,
+ install: false,
+)
+meson.override_find_program('print-mime-data', print_mime_data)
* Copyright (C) 2005 Matthias Clasen <mclasen@redhat.com>
* Copyright (C) 2012 Bastien Nocera <hadess@hadess.net>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#include <stdio.h>
* Copyright (C) 2005 Red Hat, Inc.
* Copyright (C) 2005 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <libgen.h>
#include "xdgmime.h"
else
{
if (verbose > 0)
- printf ("%s, '%s' test: expected %s, got %s\n",
- filename, test, mt_expected, mt);
+ fprintf (stderr, "%s, '%s' test: expected %s, got %s\n",
+ filename, test, mt_expected, mt);
}
}
if (file == NULL)
{
- printf ("Could not open %s\n", path);
+ fprintf (stderr, "Could not open %s\n", path);
error++;
return;
if (data == NULL)
{
- printf ("Failed to allocate memory for file %s\n", filename);
+ fprintf (stderr, "Failed to allocate memory for file %s\n", filename);
error++;
fclose (file);
if (ferror (file))
{
- printf ("Error reading file %s\n", path);
+ fprintf (stderr, "Error reading file %s\n", path);
error++;
free (data);
if (file == NULL)
{
- printf ("Could not open %s\n", filename);
+ fprintf (stderr, "Could not open %s\n", filename);
exit (1);
}
space = strchr (rest, ' ');
if (!space)
{
- printf ("Malformed line in %s:%d\n\t%s\n", filename, lineno, line);
+ fprintf (stderr, "Malformed line in %s:%d\n\t%s\n", filename, lineno, line);
continue;
}
read_from_file (argv[i]);
}
- if (error > 0 || failed > 0)
- {
- printf ("%d errors, %d comparisons, %d failed",
- error, total, failed);
- if (xfailed > 0)
- printf (" (%d expected)", xfailed);
- if (xmatch > 0)
- printf (", %d unexpected successes", xmatch);
- printf ("\n");
-
- if (xmatch > 0)
- return 1;
- if (xfailed == failed)
- return 0;
- return 1;
- }
-
+ printf ("%d errors, %d comparisons, %d failed",
+ error, total, failed);
+ if (xfailed > 0)
+ printf (" (%d expected)", xfailed);
+ if (xmatch > 0)
+ printf (", %d unexpected successes", xmatch);
+ printf ("\n");
+
+ if (error > 0 || xmatch > 0 || failed != xfailed)
+ return 1;
return 0;
}
* Copyright (C) 2003,2004 Red Hat, Inc.
* Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#include "xdgmime.h"
#include "xdgmimeglob.h"
#include <string.h>
+#include <strings.h>
#include <stdio.h>
* Copyright (C) 2003,2004 Red Hat, Inc.
* Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
#include <unistd.h>
#include <assert.h>
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
typedef struct XdgDirTimeList XdgDirTimeList;
typedef struct XdgCallbackList XdgCallbackList;
static XdgIconList *icon_list = NULL;
static XdgIconList *generic_icon_list = NULL;
+static char **xdg_dirs = NULL; /* NULL terminated */
+
XdgMimeCache **_caches = NULL;
static int n_caches = 0;
assert (directory != NULL);
- file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
+ file_name = malloc (strlen (directory) + strlen ("/mime.cache") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/mime.cache");
if (stat (file_name, &st) == 0)
{
XdgMimeCache *cache = _xdg_mime_cache_new_from_file (file_name);
}
free (file_name);
- file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/globs2");
+ file_name = malloc (strlen (directory) + strlen ("/globs2") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/globs2");
if (stat (file_name, &st) == 0)
{
_xdg_mime_glob_read_from_file (global_hash, file_name, TRUE);
else
{
free (file_name);
- file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/globs");
+ file_name = malloc (strlen (directory) + strlen ("/globs") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/globs");
if (stat (file_name, &st) == 0)
{
_xdg_mime_glob_read_from_file (global_hash, file_name, FALSE);
}
}
- file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/magic");
+ file_name = malloc (strlen (directory) + strlen ("/magic") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/magic");
if (stat (file_name, &st) == 0)
{
_xdg_mime_magic_read_from_file (global_magic, file_name);
free (file_name);
}
- file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/aliases");
+ file_name = malloc (strlen (directory) + strlen ("/aliases") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/aliases");
_xdg_mime_alias_read_from_file (alias_list, file_name);
free (file_name);
- file_name = malloc (strlen (directory) + strlen ("/mime/subclasses") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/subclasses");
+ file_name = malloc (strlen (directory) + strlen ("/subclasses") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/subclasses");
_xdg_mime_parent_read_from_file (parent_list, file_name);
free (file_name);
- file_name = malloc (strlen (directory) + strlen ("/mime/icons") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/icons");
+ file_name = malloc (strlen (directory) + strlen ("/icons") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/icons");
_xdg_mime_icon_read_from_file (icon_list, file_name);
free (file_name);
- file_name = malloc (strlen (directory) + strlen ("/mime/generic-icons") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/generic-icons");
+ file_name = malloc (strlen (directory) + strlen ("/generic-icons") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/generic-icons");
_xdg_mime_icon_read_from_file (generic_icon_list, file_name);
free (file_name);
return FALSE; /* Keep processing */
}
-/* Runs a command on all the directories in the search path */
+/* Set @xdg_dirs from the environment. It must not have been set already. */
static void
-xdg_run_command_on_dirs (XdgDirectoryFunc func,
- void *user_data)
+xdg_init_dirs (void)
{
- const char *xdg_data_home;
- const char *xdg_data_dirs;
+ const char *xdg_data_home, *home, *xdg_data_dirs;
const char *ptr;
+ size_t n_dirs = 0;
+ size_t i, current_dir;
+
+ assert (xdg_dirs == NULL);
xdg_data_home = getenv ("XDG_DATA_HOME");
- if (xdg_data_home)
+ home = getenv ("HOME");
+ xdg_data_dirs = getenv ("XDG_DATA_DIRS");
+
+ if (xdg_data_dirs == NULL)
+ xdg_data_dirs = "/usr/local/share/:/usr/share/";
+
+ /* Work out how many dirs we’re dealing with. */
+ if (xdg_data_home != NULL || home != NULL)
+ n_dirs++;
+ n_dirs++; /* initial entry in @xdg_data_dirs */
+ for (i = 0; xdg_data_dirs[i] != '\0'; i++)
+ if (xdg_data_dirs[i] == ':')
+ n_dirs++;
+
+ xdg_dirs = calloc (n_dirs + 1 /* NULL terminator */, sizeof (char *));
+ current_dir = 0;
+
+ /* $XDG_DATA_HOME */
+ if (xdg_data_home != NULL)
{
- if ((func) (xdg_data_home, user_data))
- return;
+ char *mime_subdir;
+
+ mime_subdir = malloc (strlen (xdg_data_home) + strlen ("/mime/") + 1);
+ strcpy (mime_subdir, xdg_data_home);
+ strcat (mime_subdir, "/mime/");
+
+ xdg_dirs[current_dir++] = mime_subdir;
}
- else
+ else if (home != NULL)
{
- const char *home;
+ char *guessed_xdg_home;
- home = getenv ("HOME");
- if (home != NULL)
- {
- char *guessed_xdg_home;
- int stop_processing;
-
- guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/") + 1);
- strcpy (guessed_xdg_home, home);
- strcat (guessed_xdg_home, "/.local/share/");
- stop_processing = (func) (guessed_xdg_home, user_data);
- free (guessed_xdg_home);
+ guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/mime/") + 1);
+ strcpy (guessed_xdg_home, home);
+ strcat (guessed_xdg_home, "/.local/share/mime/");
- if (stop_processing)
- return;
- }
+ xdg_dirs[current_dir++] = guessed_xdg_home;
}
- xdg_data_dirs = getenv ("XDG_DATA_DIRS");
- if (xdg_data_dirs == NULL)
- xdg_data_dirs = "/usr/local/share/:/usr/share/";
-
+ /* $XDG_DATA_DIRS */
ptr = xdg_data_dirs;
while (*ptr != '\000')
const char *end_ptr;
char *dir;
int len;
- int stop_processing;
end_ptr = ptr;
while (*end_ptr != ':' && *end_ptr != '\000')
- end_ptr ++;
+ end_ptr ++;
if (end_ptr == ptr)
- {
- ptr++;
- continue;
- }
+ {
+ ptr++;
+ continue;
+ }
if (*end_ptr == ':')
- len = end_ptr - ptr;
+ len = end_ptr - ptr;
else
- len = end_ptr - ptr + 1;
- dir = malloc (len + 1);
+ len = end_ptr - ptr + 1;
+ dir = malloc (len + strlen ("/mime/") + 1);
strncpy (dir, ptr, len);
dir[len] = '\0';
- stop_processing = (func) (dir, user_data);
- free (dir);
+ strcat (dir, "/mime/");
- if (stop_processing)
- return;
+ xdg_dirs[current_dir++] = dir;
ptr = end_ptr;
}
+
+ /* NULL terminator */
+ xdg_dirs[current_dir] = NULL;
+
+ need_reread = TRUE;
+}
+
+/* Runs a command on all the directories in the search path (@xdg_dirs). */
+static void
+xdg_run_command_on_dirs (XdgDirectoryFunc func,
+ void *user_data)
+{
+ size_t i;
+
+ if (xdg_dirs == NULL)
+ xdg_init_dirs ();
+
+ for (i = 0; xdg_dirs[i] != NULL; i++)
+ {
+ if ((func) (xdg_dirs[i], user_data))
+ return;
+ }
+}
+
+/* Allows the calling code to override the directories used by xdgmime, without
+ * having to change environment variables in a running process (which is not
+ * thread safe). This is intended to be used by tests. The changes will be
+ * picked up by xdg_mime_init() next time public API is called.
+ *
+ * This will set @xdg_dirs. Directories in @dirs must be complete, including
+ * the conventional `/mime` subdirectory. This is to allow tests to override
+ * them without the need to create a subdirectory. */
+void
+xdg_mime_set_dirs (const char * const *dirs)
+{
+ size_t i;
+
+ for (i = 0; xdg_dirs != NULL && xdg_dirs[i] != NULL; i++)
+ free (xdg_dirs[i]);
+ free (xdg_dirs);
+ xdg_dirs = NULL;
+
+ if (dirs != NULL)
+ {
+ for (i = 0; dirs[i] != NULL; i++);
+ xdg_dirs = calloc (i + 1 /* NULL terminator */, sizeof (char*));
+ for (i = 0; dirs[i] != NULL; i++)
+ xdg_dirs[i] = strdup (dirs[i]);
+ xdg_dirs[i] = NULL;
+ }
+
+ need_reread = TRUE;
}
/* Checks file_path to make sure it has the same mtime as last time it was
assert (directory != NULL);
/* Check the mime.cache file */
- file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
+ file_name = malloc (strlen (directory) + strlen ("/mime.cache") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/mime.cache");
invalid = xdg_check_file (file_name, &exists);
free (file_name);
if (invalid)
}
/* Check the globs file */
- file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/globs");
+ file_name = malloc (strlen (directory) + strlen ("/globs") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/globs");
invalid = xdg_check_file (file_name, NULL);
free (file_name);
if (invalid)
}
/* Check the magic file */
- file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
- strcpy (file_name, directory); strcat (file_name, "/mime/magic");
+ file_name = malloc (strlen (directory) + strlen ("/magic") + 1);
+ strcpy (file_name, directory); strcat (file_name, "/magic");
invalid = xdg_check_file (file_name, NULL);
free (file_name);
if (invalid)
char **result;
int i, n;
+ xdg_mime_init ();
+
if (_caches)
return _xdg_mime_cache_list_mime_parents (mime);
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
XdgMimeDestroy destroy);
void xdg_mime_remove_callback (int callback_id);
+void xdg_mime_set_dirs (const char * const *dirs);
+
/* Private versions of functions that don't call xdg_mime_init () */
int _xdg_mime_mime_type_equal (const char *mime_a,
const char *mime_b);
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 200 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_ALIAS_H__
*
* Copyright (C) 2005 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
#define MAP_FAILED ((void *) -1)
#endif
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
#define MAJOR_VERSION 1
#define MINOR_VERSION_MIN 1
#define MINOR_VERSION_MAX 2
if (fd != -1)
close (fd);
+#else /* HAVE_MMAP */
+ cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache));
+ cache->minor = 0;
+ cache->ref_count = 1;
+ cache->buffer = NULL;
+ cache->size = 0;
#endif /* HAVE_MMAP */
return cache;
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 4);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
xdg_uint32_t offset;
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 4);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
+
min = 0;
max = n_entries - 1;
while (max >= min)
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 12);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
xdg_uint32_t offset;
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 12);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
+
min = 0;
max = n_entries - 1;
while (max >= min)
{
XdgMimeCache *cache = _caches[i];
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 20);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
+
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 20);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
for (j = 0; j < n_entries && n < n_mime_types; j++)
{
{
XdgMimeCache *cache = _caches[i];
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 16);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
- xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
+ xdg_uint32_t offset;
+
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 16);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
+ offset = GET_UINT32 (cache->buffer, list_offset + 4);
n = cache_glob_node_lookup_suffix (cache,
n_entries, offset,
{
XdgMimeCache *cache = _caches[i];
+ if (cache->buffer == NULL)
+ continue;
+
offset = GET_UINT32 (cache->buffer, 24);
max_extent = MAX (max_extent, GET_UINT32 (cache->buffer, offset + 4));
}
int prio;
const char *match;
+ if (cache->buffer == NULL)
+ continue;
+
match = cache_magic_lookup_data (cache, data, len, &prio);
if (prio > priority)
{
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
-
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
xdg_uint32_t offset, n_parents, parent_offset;
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 8);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
+
min = 0;
max = n_entries - 1;
while (max >= min)
for (j = 0; j < n_parents; j++)
{
parent_offset = GET_UINT32 (cache->buffer, offset + 4 + 4 * j);
- if (_xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
+ if (strcmp (cache->buffer + parent_offset, mime) != 0 &&
+ strcmp (cache->buffer + parent_offset, umime) != 0 &&
+ _xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
return 1;
}
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
-
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
+
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, 8);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
for (j = 0; j < n_entries; j++)
{
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
- xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, header);
- xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+ xdg_uint32_t list_offset;
+ xdg_uint32_t n_entries;
xdg_uint32_t offset;
+ if (cache->buffer == NULL)
+ continue;
+
+ list_offset = GET_UINT32 (cache->buffer, header);
+ n_entries = GET_UINT32 (cache->buffer, list_offset);
+
min = 0;
max = n_entries - 1;
while (max >= min)
xdg_uint32_t list_offset;
xdg_uint32_t n_entries;
xdg_uint32_t offset;
+
+ if (cache->buffer == NULL)
+ continue;
+
list_offset = GET_UINT32 (cache->buffer, 16);
n_entries = GET_UINT32 (cache->buffer, list_offset);
offset = GET_UINT32 (cache->buffer, list_offset + 4);
*
* Copyright (C) 2005 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_CACHE_H__
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_GLOB_H__
*
* Copyright (C) 2008 Red Hat, Inc.
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
*
* Copyright (C) 2008 Red Hat, Inc.
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_ICON_H__
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_INT_H__
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
XdgMimeMagicMatchlet *matchlet;
matchlet = malloc (sizeof (XdgMimeMagicMatchlet));
+ if (matchlet == NULL)
+ return NULL;
matchlet->indent = 0;
matchlet->offset = 0;
return XDG_MIME_MAGIC_ERROR;
matchlet = _xdg_mime_magic_matchlet_new ();
+
+ /* OOM */
+ if (matchlet == NULL)
+ return XDG_MIME_MAGIC_ERROR;
+
matchlet->indent = indent;
matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
if (end_of_file)
/* We clean up the matchlet, byte swapping if needed */
if (matchlet->word_size > 1)
{
+#if LITTLE_ENDIAN
unsigned int i;
+#endif
if (matchlet->value_length % matchlet->word_size != 0)
{
_xdg_mime_magic_matchlet_free (matchlet);
{
case XDG_MIME_MAGIC_SECTION:
match = _xdg_mime_magic_match_new ();
+
+ /* OOM */
+ if (match == NULL)
+ return;
+
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_ERROR:
state = _xdg_mime_magic_parse_error (magic_file);
+
+ /* After a parse error we can only be at EOF or reset to starting a
+ * new section. */
+ assert (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_SECTION);
+
break;
case XDG_MIME_MAGIC_EOF:
default:
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_MAGIC_H__
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifdef HAVE_CONFIG_H
{
key.mime = (char *)mime;
key.parents = NULL;
+ key.n_parents = 0;
entry = bsearch (&key, list->parents, list->n_mimes,
sizeof (XdgMimeParents), &parent_entry_cmp);
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 200 Matthias Clasen <mclasen@redhat.com>
*
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
*/
#ifndef __XDG_MIME_PARENT_H__