www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000365

When Created: 04/05/2004 19:27:31
Against DJGPP version: 2.03
By whom: obi_wonton@hotmail.com
Abstract: Problems with the I/O in DJGPP
This is a condensed version of a little program i've been building for fun. It's a file shredder, but after the first shred it stops working in DJGPP. After the second overwrite, the pattern in the file should be a 0x00 followed by a 0xFF, but it remains the same pattern as in the first shred: 0xFF followed by 0x00. I it works just as it should in Borland C++ builder or VC++, but not in DJGPP. Another problem is that some of the file opening modes don't work in DJGPP. Why can't I use ios::nocreate? Is there something wrong with file IO in DJGPP?


#include <iostream>
using namespace std;



fstream file;


static inline void openFile(char* argv){
	file.open(argv,ios::binary|ios::in|ios::out);
	if(file==NULL){
		cerr<<"Error in opening file \""<<argv<<"\", try again.";
		exit(1);
	}
}

int main(int argc, char** argv){

//BEGIN MAIN

if(argc!=2){
	cerr<<"Usage: wipe [file]";
	exit(1);
}


//Write over one

openFile(argv[1]);

do{
	file.put(0xFF);
	file.put(0x00);
}while(file.peek()!=EOF);

file.close();

//Write over two

openFile(argv[1]);

do{
	file.put(0x00);
	file.put(0xFF);
}while(file.peek()!=EOF);

file.close();

}



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010