File: urlencode.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (26 lines) | stat: -rw-r--r-- 523 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <string.h>
#include "buffer.h"
#include "textcode.h"
#include "havealloca.h"
#include <unistd.h>

void urlencode(const char* c) {
  char* buf=alloca(strlen(c)*3+1);
  buffer_put(buffer_1,buf,fmt_urlencoded(buf,c,strlen(c)));
  buffer_putnlflush(buffer_1);
}

int main(int argc,char* argv[]) {
  int i;
  for (i=1; i<argc; ++i) {
    urlencode(argv[i]);
  }
  if (argc<2) {
    char src[1024];
    int len=read(0,src,sizeof(src)-1);
    if (len==-1) return(1);
    src[len]=0;
    urlencode(src);
  }
  return 0;
}