diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2011-12-26 19:18:46 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2011-12-26 19:18:46 -0800 |
commit | 8d2f107d61a8b0e099ab9a59b8a32c236da5a5fc (patch) | |
tree | 89f718ab74f8400332534aee237c6f925348f05c /xdgmime.cpp | |
parent | 3f16ace6784caab54fb054836ee93902e9701913 (diff) |
Some changes to migrate towards C++ and a multithreaded model
Diffstat (limited to 'xdgmime.cpp')
-rw-r--r-- | xdgmime.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/xdgmime.cpp b/xdgmime.cpp index 1b66b05f..819a669f 100644 --- a/xdgmime.cpp +++ b/xdgmime.cpp @@ -2,13 +2,13 @@ /* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. * * More info can be found at http://www.freedesktop.org/standards/ - * + * * 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 @@ -93,7 +93,7 @@ xdg_dir_time_list_new (void) { XdgDirTimeList *retval; - retval = calloc (1, sizeof (XdgDirTimeList)); + retval = (XdgDirTimeList *)calloc (1, sizeof (XdgDirTimeList)); retval->checked = XDG_CHECKED_UNCHECKED; return retval; @@ -122,7 +122,7 @@ xdg_mime_init_from_directory (const char *directory) assert (directory != NULL); - file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/globs") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/globs"); if (stat (file_name, &st) == 0) { @@ -139,7 +139,7 @@ xdg_mime_init_from_directory (const char *directory) free (file_name); } - file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/magic") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/magic"); if (stat (file_name, &st) == 0) { @@ -156,12 +156,12 @@ xdg_mime_init_from_directory (const char *directory) free (file_name); } - file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/aliases") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/aliases"); _xdg_mime_alias_read_from_file (alias_list, file_name); free (file_name); - file_name = malloc (strlen (directory) + strlen ("/mime/subclasses") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/subclasses") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/subclasses"); _xdg_mime_parent_read_from_file (parent_list, file_name); free (file_name); @@ -194,7 +194,7 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func, char *guessed_xdg_home; int stop_processing; - guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/") + 1); + guessed_xdg_home = (char *)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); @@ -232,7 +232,7 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func, len = end_ptr - ptr; else len = end_ptr - ptr + 1; - dir = malloc (len + 1); + dir = (char *)malloc (len + 1); strncpy (dir, ptr, len); dir[len] = '\0'; stop_processing = (func) (dir, user_data); @@ -290,7 +290,7 @@ xdg_check_dir (const char *directory, assert (directory != NULL); /* Check the globs file */ - file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/globs") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/globs"); invalid = xdg_check_file (file_name); free (file_name); @@ -301,7 +301,7 @@ xdg_check_dir (const char *directory, } /* Check the magic file */ - file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); + file_name = (char *)malloc (strlen (directory) + strlen ("/mime/magic") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/magic"); invalid = xdg_check_file (file_name); free (file_name); @@ -437,10 +437,10 @@ xdg_mime_get_mime_type_for_file (const char *file_name) * be large and need getting from a stream instead of just reading it all * in. */ max_extent = _xdg_mime_magic_get_buffer_extents (global_magic); - data = malloc (max_extent); + data = (unsigned char *)malloc (max_extent); if (data == NULL) return XDG_MIME_TYPE_UNKNOWN; - + file = fopen (file_name, "r"); if (file == NULL) { @@ -500,7 +500,7 @@ xdg_mime_shutdown (void) xdg_dir_time_list_free (dir_time_list); dir_time_list = NULL; } - + if (global_hash) { _xdg_glob_hash_free (global_hash); @@ -522,8 +522,8 @@ xdg_mime_shutdown (void) { _xdg_mime_parent_list_free ( parent_list); } - - + + for (list = callback_list; list; list = list->next) (list->callback) (list->data); @@ -534,7 +534,7 @@ int xdg_mime_get_max_buffer_extents (void) { xdg_mime_init (); - + return _xdg_mime_magic_get_buffer_extents (global_magic); } @@ -577,7 +577,7 @@ xdg_mime_media_type_equal (const char *mime_a, xdg_mime_init (); sep = strchr (mime_a, '/'); - + if (sep && strncmp (mime_a, mime_b, sep - mime_a + 1) == 0) return 1; @@ -616,7 +616,7 @@ xdg_mime_mime_type_subclass (const char *mime, if (strcmp (umime, ubase) == 0) return 1; -#if 0 +#if 0 /* Handle supertypes */ if (xdg_mime_is_super_type (ubase) && xdg_mime_media_type_equal (umime, ubase)) @@ -624,13 +624,13 @@ xdg_mime_mime_type_subclass (const char *mime, #endif /* Handle special cases text/plain and application/octet-stream */ - if (strcmp (ubase, "text/plain") == 0 && + if (strcmp (ubase, "text/plain") == 0 && strncmp (umime, "text/", 5) == 0) return 1; if (strcmp (ubase, "application/octet-stream") == 0) return 1; - + parents = _xdg_mime_parent_list_lookup (parent_list, umime); for (; parents && *parents; parents++) { @@ -653,7 +653,7 @@ xdg_mime_get_mime_parents (const char *mime) return _xdg_mime_parent_list_lookup (parent_list, umime); } -void +void xdg_mime_dump (void) { printf ("*** ALIASES ***\n\n"); @@ -674,7 +674,7 @@ xdg_mime_register_reload_callback (XdgMimeCallback callback, static int callback_id = 1; /* Make a new list element */ - list_el = calloc (1, sizeof (XdgCallbackList)); + list_el = (XdgCallbackList *)calloc (1, sizeof (XdgCallbackList)); list_el->callback_id = callback_id; list_el->callback = callback; list_el->data = data; |