Here's some code to do it, if anyone cares. From the Yahoo! Pager library in Fire, of all places...
static char *yahoo_urlencode(const char *instr)
{
register int ipos, bpos; //input str pos., buffer pos.
static unsigned char *str=NULL;
int len=strlen(instr);
int tmp;
//attempt to reuse buffer
if(NULL==str)
str = (unsigned char *) malloc(3 * len + 1);
else
str = (unsigned char *) realloc(str,3 * len + 1);
//malloc, realloc failed ?
if(errno==ENOMEM)
{
perror("libyahoo[yahoo_urlencode]");
//return ref. to empty string, so's prog. or whatever wont crash
return "";
}
ipos=bpos=0;
while(ipos<len)
{
//using inverted logic frm original code....
if (!isdigit((int) (instr[ipos]))
&& !isalpha((int) instr[ipos]) && instr[ipos] != '_')
{
tmp=instr[ipos] / 16;
str[bpos++]='%';
str[bpos++]=( (tmp < 10)?(tmp+'0')

tmp+'A'-10));
tmp=instr[ipos] % 16;
str[bpos++]=( (tmp < 10)?(tmp+'0')

tmp+'A'-10));
}
else
{
str[bpos++]=instr[ipos];
}
ipos++;
}
str[bpos] = '\0';
//free extra alloc'ed mem.
tmp=strlen(str);
str = (unsigned char *) realloc(str,tmp + 1);
return ( str);
}