Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/04e1581f78263e60766e to your computer and use it in GitHub Desktop.
Save anonymous/04e1581f78263e60766e to your computer and use it in GitHub Desktop.
lookup.c
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