[4/6] Remove sentinel from remote_fio_func_map

Message ID 20231231-remote-fileio-v1-4-249cc6c440d9@tromey.com
State New
Headers
Series Make remote-fileio per-target |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey Dec. 31, 2023, 8:25 p.m. UTC
  With foreach, a static array like remote_fio_func_map does not need a
sentinel entry.  This patch removes it and slightly rearranges the
code to suit.
---
 gdb/remote-fileio.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index f6990989da6..e001c220522 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1154,11 +1154,9 @@  remote_fileio_data::do_request (remote_target *remote, char *buf)
     { "gettimeofday", &remote_fileio_data::func_gettimeofday },
     { "isatty", &remote_fileio_data::func_isatty },
     { "system", &remote_fileio_data::func_system },
-    { nullptr, nullptr }
   };
 
   char *c;
-  int idx;
 
   quit_handler = remote_fileio_quit_handler;
 
@@ -1167,13 +1165,14 @@  remote_fileio_data::do_request (remote_target *remote, char *buf)
     *c++ = '\0';
   else
     c = strchr (buf, '\0');
-  for (idx = 0; remote_fio_func_map[idx].name; ++idx)
-    if (!strcmp (remote_fio_func_map[idx].name, buf))
-      break;
-  if (!remote_fio_func_map[idx].name)
-    remote_fileio_reply (remote, -1, FILEIO_ENOSYS);
-  else
-    (this->*remote_fio_func_map[idx].func) (remote, c);
+  for (const auto &entry : remote_fio_func_map)
+    if (!strcmp (entry.name, buf))
+      {
+	(this->*entry.func) (remote, c);
+	return;
+      }
+	
+  remote_fileio_reply (remote, -1, FILEIO_ENOSYS);
 }
 
 /* Close any open descriptors, and reinitialize the file mapping.  */