Code cleanup

This commit is contained in:
Pierre Pronchery 2017-12-26 15:10:00 +01:00
parent 4cdc20e9a1
commit 00e1bc4c5d

View File

@ -228,9 +228,9 @@ void mime_delete(Mime * mime)
MimeHandler * mime_get_handler(Mime * mime, char const * type, MimeHandler * mime_get_handler(Mime * mime, char const * type,
char const * action) char const * action)
{ {
char const * program; String const * program;
char * p; String * p;
char * q; String * q;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, type, action); fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, type, action);
@ -242,17 +242,15 @@ MimeHandler * mime_get_handler(Mime * mime, char const * type,
} }
if((program = config_get(mime->config, type, action)) != NULL) if((program = config_get(mime->config, type, action)) != NULL)
return program; return program;
if((p = strchr(type, '/')) == NULL || *(++p) == '\0' if((p = string_find(type, "/")) == NULL || *(++p) == '\0'
|| (p = strdup(type)) == NULL) || (p = string_new(type)) == NULL)
{ /* XXX the error may not be reported */
error_set_code(1, "%s", strerror(errno)); /* XXX may be wrong */
return NULL; return NULL;
} q = string_find(p, "/");
q = strchr(p, '/');
q[1] = '*'; q[1] = '*';
q[2] = '\0'; q[2] = '\0';
program = config_get(mime->config, p, action); program = config_get(mime->config, p, action);
free(p); string_delete(p);
return mimehandler_new_load_by_name(program); return mimehandler_new_load_by_name(program);
} }