File: b64encode.c

package info (click to toggle)
libowfat 0.22-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,148 kB
  • ctags: 976
  • sloc: ansic: 10,424; makefile: 42
file content (30 lines) | stat: -rw-r--r-- 606 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
27
28
29
30
#include <unistd.h>
#include <string.h>
#include "buffer.h"
#include "textcode.h"
#include "havealloca.h"

void b64encode(const char* c,long len) {
  char* buf=alloca(len*2+4);
  buffer_put(buffer_1,buf,fmt_base64(buf,c,len));
  if (isatty(1))
    buffer_putnlflush(buffer_1);
  else
    buffer_flush(buffer_1);
}

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