Enlightenment CVS committal Author : raster Project : e17 Module : libs/efreet
Dir : e17/libs/efreet/src/lib Modified Files: efreet_mime.c efreet_private.h Log Message: and for the picky - there's less copies for tolowoer. i also saw some BAD BAD leaks. bad! alloc pointer but not freeing them! also fixed up #include of alloca.h if needed. =================================================================== RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_mime.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -3 -r1.25 -r1.26 --- efreet_mime.c 11 Aug 2007 13:20:16 -0000 1.25 +++ efreet_mime.c 12 Aug 2007 10:00:02 -0000 1.26 @@ -257,47 +257,45 @@ */ const char *efreet_mime_globs_type_get(const char *file) { - Efreet_Mime_Glob *g; - char *s, *sl; - const char *ext, *mime; - + Efreet_Mime_Glob *g; + char *s, *sl, *p; + const char *ext, *mime; + /* * Check in the extension hash for the type */ - sl = alloca(strlen(file) + 1); - strcpy(sl, file); - for (s = sl; *s; s++) *s = tolower(*s); - ext = strchr(sl,'.'); - while(ext) + ext = strchr(file, '.'); + sl = alloca(strlen(ext) + 1); + for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s); + *p = 0; + p = sl; + while (p) { - ++ext; - - if (ext && (mime = ecore_hash_get(wild, ext))) - return mime; - - ext = strchr(ext,'.'); + p++; + if (p && (mime = ecore_hash_get(wild, p))) return mime; + p = strchr(p, '.'); } - /* - * Fallback to the other globs if not found - */ - ecore_list_first_goto(globs); - while ((g = ecore_list_next(globs))) - { + /* + * Fallback to the other globs if not found + */ + ecore_list_first_goto(globs); + while ((g = ecore_list_next(globs))) + { if (efreet_mime_glob_match(file, g->glob)) - return g->mime; - } - - s = strdup(file); - ecore_list_first_goto(globs); - while ((g = ecore_list_next(globs))) - { - if (efreet_mime_glob_case_match(s, g->glob)) - return g->mime; - } - FREE(s); - - return NULL; + return g->mime; + } + + ext = alloca(strlen(file) + 1); + for (s = file, p = ext; *s; s++, p++) *p = tolower(*s); + *p = 0; + ecore_list_first_goto(globs); + while ((g = ecore_list_next(globs))) + { + if (efreet_mime_glob_case_match(ext, g->glob)) + return g->mime; + } + return NULL; } /** @@ -1196,18 +1194,14 @@ static int efreet_mime_glob_match(const char *str, const char *glob) { - if (!str || !glob) - return 0; - - if (glob[0] == '\0') - { - if (str[0] == '\0') return 1; + if (!str || !glob) return 0; + if (glob[0] == 0) + { + if (str[0] == 0) return 1; return 0; - } - - if (!fnmatch(glob, str, 0)) return 1; - - return 0; + } + if (!fnmatch(glob, str, 0)) return 1; + return 0; } /** @@ -1215,30 +1209,24 @@ * @param str: String (filename) to match * @param glob: Glob to match str to * @return Returns 1 on success, 0 on failure - * @brief Compares str to glob, case insensitive + * @brief Compares str to glob, case insensitive (expects str already in lower case) */ static int efreet_mime_glob_case_match(char *str, const char *glob) { - const char *p; - char *tglob, *tp; - - if (glob[0] == '\0') - { - if (str[0] == '\0') return 1; + const char *p; + char *tglob, *tp; + + if (!str || !glob) return 0; + if (glob[0] == 0) + { + if (str[0] == 0) return 1; return 0; - } - - for (tp = str; *tp != '\0'; tp++) *tp = tolower(*tp); - - tglob = NEW(1, strlen(glob) + 1); - for (tp = tglob, p = glob; *p != 0; p++, tp++) *tp = tolower(*p); - *tp = 0; - - if (!fnmatch(str, p, 0)) return 1; - - IF_FREE(tglob); - - return 0; + } + tglob = alloca(strlen(glob) + 1); + for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p); + *tp = 0; + if (!fnmatch(str, tglob, 0)) return 1; + return 0; } =================================================================== RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_private.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- efreet_private.h 17 Jul 2007 15:07:59 -0000 1.8 +++ efreet_private.h 12 Aug 2007 10:00:02 -0000 1.9 @@ -11,6 +11,7 @@ * @{ */ +#include "config.h" #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -24,11 +25,14 @@ #include <fnmatch.h> #include <limits.h> +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif + #include <Ecore.h> #include <Ecore_File.h> #include <Ecore_Str.h> -#include "config.h" #include "efreet_xml.h" #include "efreet_ini.h" ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs