Commits

Evan Gates  committed dbccb82

add rev.c

  • Participants
  • Parent commits 70771b4

Comments (0)

Files changed (1)

+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+int main(int c,char**v){int r,f=0,i=1;char*b,*e,*p;b=e=p=0;do{if(c>1&&(f=open(v
+[i],O_RDONLY))<0){fprintf(stderr,"%s: cannot open %s: %s\n",*v,v[i],strerror(
+errno));continue;}do{do{if(p==e){char*q=p=b;b=realloc(b,(e-p+1)*2);if(!b){
+fprintf(stderr,"%s: realloc failed\n",*v);free(q);return 1;}p=b+(e-p);e=b+(p-b+
+1)*2;}}while((r=read(f,p,1))&&*p++!='\n');if(p-b){while(p>b)if(*--p!='\n')write
+(1,p,1);write(1,"\n",1);}}while(r);}while(++i<c);free(b);return 0;}