* don't know which option to pass to fopen() in order to create a file if it

doesn't exist, so I just used a BFile instead... this should fix part of
  ticket #1423, if someone wants to look into the gateway retrieval
  (settings.cpp) to fix the other half of the bug, that would be great


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22366 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-09-29 07:22:18 +00:00
parent c96bc8d3f1
commit f691c77a30
@@ -345,22 +345,28 @@ EthernetSettingsView::_SaveConfiguration()
void void
EthernetSettingsView::_SaveDNSConfiguration() EthernetSettingsView::_SaveDNSConfiguration()
{ {
FILE* fp = fopen("/etc/resolv.conf", "w"); BFile file("/etc/resolv.conf",
if (fp == NULL) B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() < B_OK) {
fprintf(stderr, "failed to open /etc/resolv.conf for writing: %s\n",
strerror(file.InitCheck()));
return; return;
}
fprintf(fp, "# Generated by Network Preflet\n"); BString content("# Generated by Network Preflet\n");
// loop over all adapters // loop over all adapters
for (int i = 0; i < fSettings.CountItems(); i++) { for (int i = 0; i < fSettings.CountItems(); i++) {
Settings* settings = fSettings.ItemAt(i); Settings* settings = fSettings.ItemAt(i);
for (int j = 0; j < settings->fNameservers.CountItems(); j++) { for (int j = 0; j < settings->fNameservers.CountItems(); j++) {
if (settings->fNameservers.ItemAt(j)->Length() > 0) { if (settings->fNameservers.ItemAt(j)->Length() > 0) {
fprintf(fp, "nameserver\t%s\n", content << "nameserver\t"
settings->fNameservers.ItemAt(j)->String()); << settings->fNameservers.ItemAt(j)->String()
<< "\n";
} }
} }
} }
fclose(fp);
file.Write(content.String(), content.Length());
} }