API refactoring : gre
[vpp.git] / vppinfra / tools / elftool.c
index c0184b5..d9d3704 100644 (file)
@@ -101,7 +101,7 @@ static clib_error_t * elf_set_interpreter (elf_main_t * em,
 
   /* Put in new null terminated string. */
   memset (s->contents, 0, vec_len (s->contents));
-  memcpy (s->contents, interp, strlen (interp));
+  clib_memcpy (s->contents, interp, strlen (interp));
 
   return 0;
 }
@@ -227,7 +227,7 @@ set_interpreter_rpath (elf_tool_main_t * tm)
   u32 run_length;
   u8 in_run;
   u64 offset0 = 0, offset1 = 0;
-  clib_error_t * error;
+  clib_error_t * error = 0;
   int fix_in_place = 0;
 
   if (!strcmp (tm->input_file, tm->output_file))
@@ -336,11 +336,11 @@ set_interpreter_rpath (elf_tool_main_t * tm)
     }
   
   if (tm->interpreter_offset)
-    memcpy (&idp[tm->interpreter_offset], tm->set_interpreter, 
+    clib_memcpy (&idp[tm->interpreter_offset], tm->set_interpreter, 
             strlen (tm->set_interpreter)+1);
 
   if (tm->rpath_offset)
-    memcpy (&idp[tm->rpath_offset], tm->set_rpath, 
+    clib_memcpy (&idp[tm->rpath_offset], tm->set_rpath, 
             strlen (tm->set_rpath)+1);
 
   /* Write the output file... */
@@ -358,10 +358,12 @@ set_interpreter_rpath (elf_tool_main_t * tm)
     }
 
  done:
-  if (mmap_length > 0)
+  if (mmap_length > 0 && idp)
     munmap (idp, mmap_length);
-  close (ifd);
-  close (ofd);
+  if (ifd >= 0)
+    close (ifd);
+  if (ofd >= 0)
+    close (ofd);
   return error;
 }
 
@@ -408,7 +410,10 @@ int main (int argc, char * argv[])
     }
 
   if (! tm->input_file)
-    clib_error ("no input file");
+    {
+      error = clib_error_return (0, "no input file");
+      goto done;
+    }
 
   /* Do the typical case a stone-simple way... */
   if (tm->quiet && tm->set_interpreter && tm->set_rpath && tm->output_file)