Patchwork [gccgo] Use %m instead of strerror

login
register
mail settings
Submitter Ian Taylor
Date Nov. 17, 2010, 10:12 p.m.
Message ID <mcrmxp7y4ze.fsf@google.com>
Download mbox | patch
Permalink /patch/71625/
State New
Headers show

Comments

Ian Taylor - Nov. 17, 2010, 10:12 p.m.
This patch changes gccgo to use %m instead of calling strerror.
Committed to gccgo branch.

Ian

Patch

diff -r 0cd7f1dff9ad go/go.cc
--- a/go/go.cc	Wed Nov 17 13:53:29 2010 -0800
+++ b/go/go.cc	Wed Nov 17 14:10:36 2010 -0800
@@ -73,7 +73,7 @@ 
 	{
 	  file = fopen(filename, "r");
 	  if (file == NULL)
-	    fatal_error("cannot open %s: %s", filename, strerror(errno));
+	    fatal_error("cannot open %s: %m", filename);
 	}
 
       Lex lexer(filename, file);
diff -r 0cd7f1dff9ad go/import-archive.cc
--- a/go/import-archive.cc	Wed Nov 17 13:53:29 2010 -0800
+++ b/go/import-archive.cc	Wed Nov 17 14:10:36 2010 -0800
@@ -147,8 +147,7 @@ 
   struct stat st;
   if (fstat(this->fd_, &st) < 0)
     {
-      error_at(this->location_, "%s: %s", this->filename_.c_str(),
-	       strerror(errno));
+      error_at(this->location_, "%s: %m", this->filename_.c_str());
       return false;
     }
   this->filesize_ = st.st_size;
@@ -157,8 +156,7 @@ 
   if (::lseek(this->fd_, 0, SEEK_SET) < 0
       || ::read(this->fd_, buf, sizeof(armagt)) != sizeof(armagt))
     {
-      error_at(this->location_, "%s: %s", this->filename_.c_str(),
-	       strerror(errno));
+      error_at(this->location_, "%s: %m", this->filename_.c_str());
       return false;
     }
   this->is_thin_archive_ = memcmp(buf, armagt, sizeof(armagt)) == 0;
@@ -208,8 +206,7 @@ 
   if (::lseek(this->fd_, offset, SEEK_SET) < 0
       || ::read(this->fd_, buf, size) != size)
     {
-      error_at(this->location_, "%s: %s", this->filename_.c_str(),
-	       strerror(errno));
+      error_at(this->location_, "%s: %m", this->filename_.c_str());
       return false;
     }
   return true;
@@ -225,16 +222,14 @@ 
   Archive_header hdr;
   if (::lseek(this->fd_, off, SEEK_SET) < 0)
     {
-      error_at(this->location_, "%s: %s", this->filename_.c_str(),
-	       strerror(errno));
+      error_at(this->location_, "%s: %m", this->filename_.c_str());
       return false;
     }
   ssize_t got = ::read(this->fd_, &hdr, sizeof hdr);
   if (got != sizeof hdr)
     {
       if (got < 0)
-	error_at(this->location_, "%s: %s", this->filename_.c_str(),
-		 strerror(errno));
+	error_at(this->location_, "%s: %m", this->filename_.c_str());
       else if (got > 0)
 	error_at(this->location_, "%s: short archive header at %ld",
 		 this->filename_.c_str(), static_cast<long>(off));
@@ -406,7 +401,7 @@ 
   *memfd = open(filename.c_str(), O_RDONLY);
   if (*memfd < 0)
     {
-      error_at(this->location_, "%s: %s", filename.c_str(), strerror(errno));
+      error_at(this->location_, "%s: %m", filename.c_str());
       return false;
     }
   *memoff = 0;
diff -r 0cd7f1dff9ad go/import.cc
--- a/go/import.cc	Wed Nov 17 13:53:29 2010 -0800
+++ b/go/import.cc	Wed Nov 17 14:10:36 2010 -0800
@@ -104,7 +104,7 @@ 
   if (fd < 0)
     {
       if (errno != ENOENT && errno != EISDIR)
-	warning_at(location, 0, "%s: %s", filename.c_str(), strerror(errno));
+	warning_at(location, 0, "%s: %m", filename.c_str());
 
       fd = Import::try_suffixes(&found_filename);
       if (fd < 0)
@@ -184,8 +184,7 @@ 
 
   if (lseek(fd, 0, SEEK_SET) < 0)
     {
-      error_at(location, "lseek %s failed: %s", filename.c_str(),
-	       strerror(errno));
+      error_at(location, "lseek %s failed: %m", filename.c_str());
       return NULL;
     }
 
@@ -233,8 +232,7 @@ 
 
   if (lseek(fd, offset + sec_offset, SEEK_SET) < 0)
     {
-      error_at(location, "lseek %s failed: %s", filename.c_str(),
-	       strerror(errno));
+      error_at(location, "lseek %s failed: %m", filename.c_str());
       return NULL;
     }
 
@@ -242,8 +240,7 @@ 
   ssize_t c = read(fd, buf, sec_length);
   if (c < 0)
     {
-      error_at(location, "read %s failed: %s", filename.c_str(),
-	       strerror(errno));
+      error_at(location, "read %s failed: %m", filename.c_str());
       return NULL;
     }
   if (c < sec_length)
@@ -821,7 +818,7 @@ 
 {
   if (lseek(fd, 0, SEEK_SET) != 0)
     {
-      error("lseek failed: %s", strerror(errno));
+      error("lseek failed: %m");
       this->set_saw_error();
     }
 }
@@ -849,7 +846,7 @@ 
   if (got < 0)
     {
       if (!this->saw_error())
-	error("read failed: %s", strerror(errno));
+	error("read failed: %m");
       this->set_saw_error();
       return false;
     }
@@ -857,7 +854,7 @@ 
   if (lseek(this->fd_, - got, SEEK_CUR) != 0)
     {
       if (!this->saw_error())
-	error("lseek failed: %s", strerror(errno));
+	error("lseek failed: %m");
       this->set_saw_error();
       return false;
     }
@@ -879,7 +876,7 @@ 
   if (lseek(this->fd_, skip, SEEK_CUR) != 0)
     {
       if (!this->saw_error())
-	error("lseek failed: %s", strerror(errno));
+	error("lseek failed: %m");
       this->set_saw_error();
     }
   if (!this->data_.empty())