Fix gcc2 build - remove iusing of ios:exceptions

* Fixing gcc2 build by removing exceptions using, that are looking like
  not supported by our version of compiler.
* Thanks to Alexander von Gluck for pointing the problem out.
This commit is contained in:
Siarzhuk Zharski
2012-01-15 17:38:41 +00:00
parent 68450f5d44
commit db3aecc840
+25 -32
View File
@@ -30,11 +30,9 @@ const char* kUsageMessage = \
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
status_t result = B_ERROR;
if ((argc == 2 && strcmp(argv[1], "--help") == 0) || argc > 2) { if ((argc == 2 && strcmp(argv[1], "--help") == 0) || argc > 2) {
cerr << kUsageMessage; cerr << kUsageMessage;
return result; return B_ERROR;
} }
BPath device; BPath device;
@@ -49,14 +47,14 @@ main(int argc, char** argv)
BVolume bootVolume; BVolume bootVolume;
if (volumeRoster.GetBootVolume(&bootVolume) != B_OK) { if (volumeRoster.GetBootVolume(&bootVolume) != B_OK) {
cerr << "Can not find boot device" << endl; cerr << "Can not find boot device" << endl;
return result; return B_ERROR;
} }
BDiskDeviceRoster roster; BDiskDeviceRoster roster;
BDiskDevice bootDevice; BDiskDevice bootDevice;
if(roster.FindPartitionByVolume(bootVolume, &bootDevice, NULL) != B_OK) { if(roster.FindPartitionByVolume(bootVolume, &bootDevice, NULL) != B_OK) {
cerr << "Can not find boot device" << endl; cerr << "Can not find boot device" << endl;
return result; return B_ERROR;
} }
bootDevice.GetPath(&device); bootDevice.GetPath(&device);
@@ -65,23 +63,23 @@ main(int argc, char** argv)
if (strcmp(device.Leaf(), "raw") != 0) { if (strcmp(device.Leaf(), "raw") != 0) {
cerr << device.Path() << " is not a raw device" << endl; cerr << device.Path() << " is not a raw device" << endl;
return result; return B_ERROR;
} }
fstream fs; fstream fs;
fs.exceptions(ios::failbit | ios::badbit);
try {
fs.open(device.Path(), fstream::in | fstream::out | fstream::binary); fs.open(device.Path(), fstream::in | fstream::out | fstream::binary);
if (!fs.is_open()) {
cerr << "Can't open " << device.Path() << endl;
return B_ERROR;
}
unsigned char MBR[kMBRSize]; unsigned char MBR[kMBRSize];
fs.read((char*)MBR, kMBRSize); fs.read((char*)MBR, kMBRSize);
if (fs.gcount() < kMBRSize ) { if (fs.fail() || fs.gcount() < kMBRSize ) {
stringstream error; cerr << "Cannot read " << kMBRSize
error << "only " << fs.gcount() << " of " << kMBRSize << " bytes from " << device.Path() << endl;
<< " bytes was read from " << device.Path(); fs.close();
throw fstream::failure(error.str()); return B_ERROR;
} }
// update only the code area and the MBR signature // update only the code area and the MBR signature
@@ -95,31 +93,26 @@ main(int argc, char** argv)
string choice; string choice;
getline(cin, choice, '\n'); getline(cin, choice, '\n');
if (choice == "no" || choice == "" || choice != "yes") if (choice == "no" || choice == "" || choice != "yes") {
throw fstream::failure("users cancel"); cerr << "MBR was NOT written" << endl;
fs.close();
return B_ERROR;
}
cerr << "Rewriting MBR for " << device.Path() << endl; cerr << "Rewriting MBR for " << device.Path() << endl;
fs.seekg(0, ios::beg); fs.seekg(0, ios::beg);
fs.write((char*)MBR, kMBRSize); fs.write((char*)MBR, kMBRSize);
fs.flush(); if (fs.fail()) {
cerr << "Cannot write " << kMBRSize
cerr << "MBR was written OK" << endl; << " bytes to " << device.Path() << endl;
result = B_OK; fs.close();
return B_ERROR;
} catch (fstream::failure exception) {
cerr << "MBR was NOT written" << endl;
cerr << "Error: ";
if (fs.is_open())
cerr << exception.what();
else
cerr << "Can't open " << device.Path();
cerr << endl;
} }
if (fs.is_open())
fs.close(); fs.close();
return result; cerr << "MBR was written OK" << endl;
return B_OK;
} }