/* mini program to demonstrate problem with cut and paste, Frank Lübeck */ /* Simplified by Margarita Manterola. */ /* Compile: * gcc -Wall -o minirl -O2 minirl.c -lreadline * gcc -Wall -o minirl -O2 minirl.c $CPPFLAGS $LDFLAGS -lreadline -lncurses * Run: * ./minirl TESTOUT * and paste the content of any text file (say 10kB without long lines), * end program with Ctrl-d. * * Then * diff original-file TESTOUT * shows that in some lines trailing characters get lost. Or lines completely * lost. */ #include #include #include #include int main(int argc, char** argv) { char* s; FILE *out; if (argc == 1) return 1; out = fopen(argv[1], "w"); while (1) { s = readline("> "); if (!s) break; fprintf(out,"%s\n",s); free(s); } fflush(out); return 0; }