On 03/18/2016 03:56 PM, Bernhard Reutner-Fischer wrote:
On March 18, 2016 6:16:46 AM GMT+01:00, Hongxu Jia <hongxu....@windriver.com> 
wrote:



+/* Perform user-specified mapping of __FILE__ prefixes.  Return
+   the new name corresponding to filename.  */
+
+const char *
+remap_file_filename (const char *filename)
+{
+  file_prefix_map *map;
+  char *s;
+  const char *name;
+  size_t name_len;
+
+  for (map = file_prefix_maps; map; map = map->next)
+    if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
+      break;
+  if (!map)
+    return filename;
+  name = filename + map->old_len;
+  name_len = strlen (name) + 1;
+  s = (char *) alloca (name_len + map->new_len);
+  memcpy (s, map->new_prefix, map->new_len);
+  memcpy (s + map->new_len, name, name_len);
+
+  return xstrdup (s);
+}

Please explain why you first alloca() and then strdup the result instead of 
XNEWVEC

1. alloca - allocate memory that is automatically freed when the
    function remap_file_filename returns

2. XNEW - allocate memory for struct file_prefix_map

3. xstrdup - duplicate a string

//Hongxu



Thanks,



Reply via email to