Author: peterw Date: Fri Oct 26 03:27:44 2007 New Revision: 29892
URL: http://svn.reactos.org/svn/reactos?rev=29892&view=rev Log: - Make tee behave properly with regards to overwriting files.
Modified: trunk/tools/RosBE-Windows/Tools/tee.c
Modified: trunk/tools/RosBE-Windows/Tools/tee.c URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosBE-Windows/Tools/tee.c?rev... ============================================================================== --- trunk/tools/RosBE-Windows/Tools/tee.c (original) +++ trunk/tools/RosBE-Windows/Tools/tee.c Fri Oct 26 03:27:44 2007 @@ -31,38 +31,25 @@ return 0; }
- FILE = fopen(argv[1], "r"); - if (FILE) + FILE = fopen(argv[1], "w"); + if (!FILE) { - fprintf(stderr, "%s: Error file "%s" already exists.\n", argv[0], argv[1]); - if (fclose(FILE)) - { - fprintf(stderr, "%s: Error closing file "%s"\n", argv[0], argv[1]); - } + fprintf(stderr, "%s: Error cannot create/open file "%s".\n", argv[0], argv[1]); return -1; } - else + while (!feof(stdin)) { - FILE = fopen(argv[1], "w"); - if (!FILE) + charbuff = fgetc(stdin); + if (!feof(stdin)) { - fprintf(stderr, "%s: Error cannot create file "%s".\n", argv[0], argv[1]); - return -1; + fputc(charbuff, stdout); + fputc(charbuff, FILE); } - while (!feof(stdin)) - { - charbuff = fgetc(stdin); - if (!feof(stdin)) - { - fputc(charbuff, stdout); - fputc(charbuff, FILE); - } - } - if (fclose(FILE)) - { - fprintf(stderr, "%s: Error closing file "%s"\n", argv[0], argv[1]); - return -1; - } + } + if (fclose(FILE)) + { + fprintf(stderr, "%s: Error closing file "%s"\n", argv[0], argv[1]); + return -1; }
return 0;