From 73d5a30a1d93eb79761f2472c685afb8e42a8646 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Wed, 24 May 2023 13:06:12 +0200 Subject: [PATCH] Squashed 'xdgmime-source/' changes from 28b70c4..3e7ee2d 3e7ee2d Add SPDX-License-Identifier tags in source files d385402 src/: LGPLv2+ -> LGPLv2.1+ 0122cb5 xdgmime: Finer handling for cases where mmap() is not available c501188 xdgmime: Prevent infinite loops from badly-formed MIME registrations 462198f xdgmime: Add xdg_mime_set_dirs() method to override XDG envvars 1414820 Add missing S_ISREG definitions for VS2022 ecbc52c xdgmimemagic: Add an assertion to clarify state after hitting an error 95e3187 test-mime-data: output errors to stderr fe2f298 ci: Test meson build ade1de1 build: Add meson support 0722d76 ci: Fix shared-mime-info test not exercising our build 92f6a09 xdgmimemagic: Fix unused variable warning when !LITTLE_ENDIAN 50a624b Fix segfaults due to strict ISO C99 mode enforcement 7cc63be Makefile: Add support for POSIX make d64963b test-mime-data: fail when an error occurs 1c521ab add OOM handling in mimemagic 1318486 Silence an uninitialize variable warning 3ae3ed6 xdgmime: Call xdg_mime_init() before xdg_mime_list_mime_parents() git-subtree-dir: xdgmime-source git-subtree-split: 3e7ee2dc8edde524858ad9a109dabe26980cf2e5 --- .gitlab-ci.yml | 16 +++- meson.build | 17 ++++ src/Makefile | 18 +++- src/meson.build | 35 +++++++ src/print-mime-data.c | 18 +--- src/test-mime-data.c | 60 ++++-------- src/test-mime.c | 19 +--- src/xdgmime.c | 213 ++++++++++++++++++++++++++---------------- src/xdgmime.h | 20 +--- src/xdgmimealias.c | 18 +--- src/xdgmimealias.h | 18 +--- src/xdgmimecache.c | 117 ++++++++++++++++------- src/xdgmimecache.h | 18 +--- src/xdgmimeglob.c | 18 +--- src/xdgmimeglob.h | 18 +--- src/xdgmimeicon.c | 18 +--- src/xdgmimeicon.h | 18 +--- src/xdgmimeint.c | 18 +--- src/xdgmimeint.h | 18 +--- src/xdgmimemagic.c | 37 ++++---- src/xdgmimemagic.h | 18 +--- src/xdgmimeparent.c | 19 +--- src/xdgmimeparent.h | 18 +--- 23 files changed, 353 insertions(+), 434 deletions(-) create mode 100644 meson.build create mode 100644 src/meson.build diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a1ea511..9be9c50 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,7 @@ variables: gettext-devel meson -build:meson: +build:autotools: before_script: - dnf update -y --nogpgcheck - dnf install -y --nogpgcheck $DEPENDENCIES @@ -25,5 +25,19 @@ build:meson: # 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 diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..2b16fda --- /dev/null +++ b/meson.build @@ -0,0 +1,17 @@ +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') diff --git a/src/Makefile b/src/Makefile index 6c97f94..44c44f7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,14 +1,22 @@ +.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 - diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..ceb407c --- /dev/null +++ b/src/meson.build @@ -0,0 +1,35 @@ +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) diff --git a/src/print-mime-data.c b/src/print-mime-data.c index 2549e73..f51528e 100644 --- a/src/print-mime-data.c +++ b/src/print-mime-data.c @@ -6,23 +6,7 @@ * Copyright (C) 2005 Matthias Clasen * Copyright (C) 2012 Bastien Nocera * - * 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 diff --git a/src/test-mime-data.c b/src/test-mime-data.c index 1dbc636..14fb94e 100644 --- a/src/test-mime-data.c +++ b/src/test-mime-data.c @@ -5,28 +5,13 @@ * Copyright (C) 2005 Red Hat, Inc. * Copyright (C) 2005 Matthias Clasen * - * 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 #include #include +#include #include #include "xdgmime.h" @@ -63,8 +48,8 @@ check_mime_type (const char *mt, 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); } } @@ -114,7 +99,7 @@ test_by_data (const char *dir, if (file == NULL) { - printf ("Could not open %s\n", path); + fprintf (stderr, "Could not open %s\n", path); error++; return; @@ -125,7 +110,7 @@ test_by_data (const char *dir, 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); @@ -136,7 +121,7 @@ test_by_data (const char *dir, if (ferror (file)) { - printf ("Error reading file %s\n", path); + fprintf (stderr, "Error reading file %s\n", path); error++; free (data); @@ -200,7 +185,7 @@ read_from_file (const char *filename) if (file == NULL) { - printf ("Could not open %s\n", filename); + fprintf (stderr, "Could not open %s\n", filename); exit (1); } @@ -217,7 +202,7 @@ read_from_file (const char *filename) 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; } @@ -312,22 +297,15 @@ main (int argc, char *argv[]) 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; } diff --git a/src/test-mime.c b/src/test-mime.c index e68222a..a194871 100644 --- a/src/test-mime.c +++ b/src/test-mime.c @@ -2,27 +2,12 @@ * Copyright (C) 2003,2004 Red Hat, Inc. * Copyright (C) 2003,2004 Jonathan Blandford * - * 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 +#include #include diff --git a/src/xdgmime.c b/src/xdgmime.c index 90a0ed0..b640651 100644 --- a/src/xdgmime.c +++ b/src/xdgmime.c @@ -6,23 +6,7 @@ * Copyright (C) 2003,2004 Red Hat, Inc. * Copyright (C) 2003,2004 Jonathan Blandford * - * 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 @@ -45,6 +29,10 @@ #include #include +#ifndef S_ISREG +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#endif + typedef struct XdgDirTimeList XdgDirTimeList; typedef struct XdgCallbackList XdgCallbackList; @@ -60,6 +48,8 @@ static XdgCallbackList *callback_list = NULL; 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; @@ -144,8 +134,8 @@ xdg_mime_init_from_directory (const char *directory, 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); @@ -164,8 +154,8 @@ xdg_mime_init_from_directory (const char *directory, } 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); @@ -174,8 +164,8 @@ xdg_mime_init_from_directory (const char *directory, 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); @@ -187,8 +177,8 @@ xdg_mime_init_from_directory (const char *directory, } } - 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); @@ -199,69 +189,81 @@ xdg_mime_init_from_directory (const char *directory, 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') @@ -269,33 +271,82 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func, 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 @@ -350,8 +401,8 @@ xdg_check_dir (const char *directory, 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) @@ -365,8 +416,8 @@ xdg_check_dir (const char *directory, } /* 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) @@ -376,8 +427,8 @@ xdg_check_dir (const char *directory, } /* 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) @@ -824,6 +875,8 @@ xdg_mime_list_mime_parents (const char *mime) char **result; int i, n; + xdg_mime_init (); + if (_caches) return _xdg_mime_cache_list_mime_parents (mime); diff --git a/src/xdgmime.h b/src/xdgmime.h index 6a34edf..abba067 100644 --- a/src/xdgmime.h +++ b/src/xdgmime.h @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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 */ @@ -119,6 +103,8 @@ int xdg_mime_register_reload_callback (XdgMimeCallback callback, 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); diff --git a/src/xdgmimealias.c b/src/xdgmimealias.c index 07d89eb..857d274 100644 --- a/src/xdgmimealias.c +++ b/src/xdgmimealias.c @@ -6,23 +6,7 @@ * Copyright (C) 2004 Red Hat, Inc. * Copyright (C) 2004 Matthias Clasen * - * 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 diff --git a/src/xdgmimealias.h b/src/xdgmimealias.h index 3c28012..05df009 100644 --- a/src/xdgmimealias.h +++ b/src/xdgmimealias.h @@ -6,23 +6,7 @@ * Copyright (C) 2004 Red Hat, Inc. * Copyright (C) 200 Matthias Clasen * - * 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__ diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c index acaed9d..05378fc 100644 --- a/src/xdgmimecache.c +++ b/src/xdgmimecache.c @@ -5,23 +5,7 @@ * * Copyright (C) 2005 Matthias Clasen * - * 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 @@ -72,6 +56,10 @@ #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 @@ -157,6 +145,12 @@ _xdg_mime_cache_new_from_file (const char *file_name) 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; @@ -302,10 +296,16 @@ cache_alias_lookup (const char *alias) 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) @@ -348,10 +348,16 @@ cache_glob_lookup_literal (const char *file_name, 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) @@ -404,8 +410,14 @@ cache_glob_lookup_fnmatch (const char *file_name, { 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++) { @@ -528,9 +540,16 @@ cache_glob_lookup_suffix (const char *file_name, { 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, @@ -637,6 +656,9 @@ _xdg_mime_cache_get_max_buffer_extents (void) { 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)); } @@ -663,6 +685,9 @@ cache_get_mime_type_for_data (const void *data, int prio; const char *match; + if (cache->buffer == NULL) + continue; + match = cache_magic_lookup_data (cache, data, len, &prio); if (prio > priority) { @@ -864,11 +889,16 @@ _xdg_mime_cache_mime_type_subclass (const char *mime, 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) @@ -889,7 +919,9 @@ _xdg_mime_cache_mime_type_subclass (const char *mime, 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; } @@ -928,9 +960,14 @@ _xdg_mime_cache_list_mime_parents (const char *mime) 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++) { @@ -980,10 +1017,16 @@ cache_lookup_icon (const char *mime, int header) 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) @@ -1060,6 +1103,10 @@ _xdg_mime_cache_glob_dump (void) 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); diff --git a/src/xdgmimecache.h b/src/xdgmimecache.h index 27f42d0..48aa752 100644 --- a/src/xdgmimecache.h +++ b/src/xdgmimecache.h @@ -5,23 +5,7 @@ * * Copyright (C) 2005 Matthias Clasen * - * 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__ diff --git a/src/xdgmimeglob.c b/src/xdgmimeglob.c index 5071418..a07305c 100644 --- a/src/xdgmimeglob.c +++ b/src/xdgmimeglob.c @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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 diff --git a/src/xdgmimeglob.h b/src/xdgmimeglob.h index 0018292..7ecee9a 100644 --- a/src/xdgmimeglob.h +++ b/src/xdgmimeglob.h @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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__ diff --git a/src/xdgmimeicon.c b/src/xdgmimeicon.c index 05c9473..4aaa564 100644 --- a/src/xdgmimeicon.c +++ b/src/xdgmimeicon.c @@ -5,23 +5,7 @@ * * 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 diff --git a/src/xdgmimeicon.h b/src/xdgmimeicon.h index b5f2583..f724430 100644 --- a/src/xdgmimeicon.h +++ b/src/xdgmimeicon.h @@ -5,23 +5,7 @@ * * 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__ diff --git a/src/xdgmimeint.c b/src/xdgmimeint.c index 5eaa715..0655fa0 100644 --- a/src/xdgmimeint.c +++ b/src/xdgmimeint.c @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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 diff --git a/src/xdgmimeint.h b/src/xdgmimeint.h index 9e8b2cb..041c4f4 100644 --- a/src/xdgmimeint.h +++ b/src/xdgmimeint.h @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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__ diff --git a/src/xdgmimemagic.c b/src/xdgmimemagic.c index fd49fa8..98a1274 100644 --- a/src/xdgmimemagic.c +++ b/src/xdgmimemagic.c @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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 @@ -103,6 +87,8 @@ _xdg_mime_magic_matchlet_new (void) XdgMimeMagicMatchlet *matchlet; matchlet = malloc (sizeof (XdgMimeMagicMatchlet)); + if (matchlet == NULL) + return NULL; matchlet->indent = 0; matchlet->offset = 0; @@ -355,6 +341,11 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file, 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) @@ -479,7 +470,9 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_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); @@ -767,6 +760,11 @@ _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic, { 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); @@ -784,6 +782,11 @@ _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic, 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: diff --git a/src/xdgmimemagic.h b/src/xdgmimemagic.h index 35c8039..81125c2 100644 --- a/src/xdgmimemagic.h +++ b/src/xdgmimemagic.h @@ -6,23 +6,7 @@ * Copyright (C) 2003 Red Hat, Inc. * Copyright (C) 2003 Jonathan Blandford * - * 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__ diff --git a/src/xdgmimeparent.c b/src/xdgmimeparent.c index 511bbac..e03a78f 100644 --- a/src/xdgmimeparent.c +++ b/src/xdgmimeparent.c @@ -6,23 +6,7 @@ * Copyright (C) 2004 Red Hat, Inc. * Copyright (C) 2004 Matthias Clasen * - * 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 @@ -111,6 +95,7 @@ _xdg_mime_parent_list_lookup (XdgParentList *list, { key.mime = (char *)mime; key.parents = NULL; + key.n_parents = 0; entry = bsearch (&key, list->parents, list->n_mimes, sizeof (XdgMimeParents), &parent_entry_cmp); diff --git a/src/xdgmimeparent.h b/src/xdgmimeparent.h index b564f41..b656e38 100644 --- a/src/xdgmimeparent.h +++ b/src/xdgmimeparent.h @@ -6,23 +6,7 @@ * Copyright (C) 2004 Red Hat, Inc. * Copyright (C) 200 Matthias Clasen * - * 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__ -- 2.39.2