Skip to content

Instantly share code, notes, and snippets.

@fknaopen
Created December 14, 2011 04:48
Show Gist options
  • Save fknaopen/1475301 to your computer and use it in GitHub Desktop.
Save fknaopen/1475301 to your computer and use it in GitHub Desktop.
get cgi-name from URL
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------------*/
/*
* @brief get cgi(included "/" ) from URL (URL文字列からcgi名('/'を含む)を取得)
* @param [in] in URL-strings
* @retval *p cgi-strings
* @retval *"\0" error
*/
/*------------------------------------------------------------------------------*/
char * func_cut_cgi( const char * in )
{
static char *blank = "\0";
char *p;
// check argument
if ( in != NULL ){
p = strrchr( in, '/' );
if ( NULL == p ) {
p = blank;
}
}else {
// invalid argument
p = blank;
}
return p;
}
// test
main() {
char *url;
url = "http://www.a.b.c/cgi/jobs.cgi?h=99&z=3";
printf( "URL[%s] -> cgi[%s]\n", url, func_cut_cgi( url ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment