Created
March 19, 2016 07:23
-
-
Save anonymous/04e1581f78263e60766e to your computer and use it in GitHub Desktop.
lookup.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char* lookup(const char* path) | |
{ | |
// Store the extension in a variable | |
char* extension = strrchr(path, '.'); | |
// if it exists, in case strrchr doesn't really find anything | |
if(extension != NULL) | |
{ | |
// compare and match the extension with the supported list | |
if(strcasecmp(extension, ".css") == 0) | |
{ | |
return "text/css"; | |
} | |
else if(strcasecmp(extension, ".html") == 0) | |
{ | |
return "text/html"; | |
} | |
else if(strcasecmp(extension, ".gif") == 0) | |
{ | |
return "image/gif"; | |
} | |
else if(strcasecmp(extension, ".ico") == 0) | |
{ | |
return "image/x-icon"; | |
} | |
else if(strcasecmp(extension, ".jpg") == 0) | |
{ | |
return "image/jpeg"; | |
} | |
else if(strcasecmp(extension, ".js") == 0) | |
{ | |
return "text/javascript"; | |
} | |
else if(strcasecmp(extension, ".php") == 0) | |
{ | |
return "text/x-php"; | |
} | |
else if(strcasecmp(extension, ".png") == 0) | |
{ | |
return "image/png"; | |
} | |
} | |
// if not found in list or doesn't exist, return NULL | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment