This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: merge_device_file() - support .hw file with '\r' characters


On Monday 09 September 2013 16:43:23 Alexey Makhalov wrote:
> When .hw file is created in Win environment. It has '\r' characters.
> We have to analyze it also.
> 
> 2013-09-09 Alexey Makhalov <makhaloff@gmail.com>
>         * sim-hw.c (merge_device_file) Remove '\r' at the end of
> device_path as well as '\n'.

the eol scanning code in this func is pretty lazy.  please try this version
instead.
-mike

diff --git a/sim/common/sim-hw.c b/sim/common/sim-hw.c
index 32df314..23b81e2 100644
--- a/sim/common/sim-hw.c
+++ b/sim/common/sim-hw.c
@@ -161,15 +161,19 @@ merge_device_file (struct sim_state *sd,
   line_nr = 0;
   while (fgets (device_path, sizeof (device_path), description))
     {
-      char *device;
+      char *device, *eol;
+
       /* check that a complete line was read */
-      if (strchr (device_path, '\n') == NULL)
+      eol = strchr (device_path, '\n');
+      if (eol == NULL)
 	{
 	  fclose (description);
 	  sim_io_eprintf (sd, "%s:%d: line to long", file_name, line_nr);
 	  return SIM_RC_FAIL;
 	}
-      *strchr (device_path, '\n') = '\0';
+      *eol-- = '\0';
+      if (*eol == '\r')
+	*eol = '\0';
       line_nr++;
       /* skip comments ("#" or ";") and blank lines lines */
       for (device = device_path;

Attachment: signature.asc
Description: This is a digitally signed message part.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]