Index: branches/libc-0.6/src/emx/ChangeLog.LIBC
===================================================================
--- branches/libc-0.6/src/emx/ChangeLog.LIBC	(revision 2512)
+++ branches/libc-0.6/src/emx/ChangeLog.LIBC	(revision 2513)
@@ -2,4 +2,9 @@
 
 TODO: open replace on RAMFS fails with error 32!
+
+2006-02-03: knut st. osmundsen <bird-gccos2-spam@anduin.net>
+    - ld:
+        o #20: use make_temp_file instead of mktemp. This involved including
+          libiberty.h which required some adjustments of duplicate code to work.
 
 2006-01-18: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: branches/libc-0.6/src/emx/src/ld/ld.c
===================================================================
--- branches/libc-0.6/src/emx/src/ld/ld.c	(revision 2512)
+++ branches/libc-0.6/src/emx/src/ld/ld.c	(revision 2513)
@@ -43,4 +43,5 @@
 #include <string.h>
 #endif
+#include "libiberty.h"
 
 #if !defined(A_OUT)
@@ -872,6 +873,6 @@
 int cl_refs_allocated;
 
-char *xmalloc (int);
-void *xrealloc (void *, int);
+void *xmalloc (size_t);
+void *xrealloc (void *, size_t);
 void usage (char *, char *);
 void fatal (char *, ...);
@@ -899,5 +900,4 @@
 void symtab_init (void);
 void padfile (int, int);
-char *concat (const char *, const char *, const char *);
 char *get_file_name (struct file_entry *);
 symbol *getsym (char *), *getsym_soft (char *);
@@ -1213,5 +1213,5 @@
 	  discard_locals = DISCARD_ALL;
 	  break;
-	
+
 	case 'y':
 	  {
@@ -1242,5 +1242,5 @@
 	  search_dirs[n_search_dirs - 1] = optarg;
 	  break;
-	
+
 	case 'M':
 	  write_map = 1;
@@ -1309,5 +1309,5 @@
 	      = (struct string_list_element *)
 		xmalloc (sizeof (struct string_list_element));
-	
+
 	    new->str = optarg;
 	    new->next = set_element_prefixes;
@@ -1392,6 +1392,6 @@
 
 	case 'l':
-	  p->filename = concat ("", optarg, "");
-	  p->local_sym_name = concat ("-l", optarg, "");
+	  p->filename = concat ("", optarg, "", NULL);
+	  p->local_sym_name = concat ("-l", optarg, "", NULL);
 	  p->search_dirs_flag = 1;
           p->dynamic = !opt_libs_static;
@@ -1612,5 +1612,5 @@
 	{
           int lendir = strlen (search_dirs[i]);
-	  register char *string = xmalloc (lendir + lenname + 4 + 6 + 1);
+	  register char *string = (char *) xmalloc (lendir + lenname + 4 + 6 + 1);
           int j;
 
@@ -2483,5 +2483,5 @@
 			 entry->filename);
 		read_entry_symbols (desc, subentry);
-		subentry->strings = xmalloc (subentry->strs_size);
+		subentry->strings = (char *) xmalloc (subentry->strs_size);
 		read_entry_strings (desc, subentry);
 
@@ -3419,5 +3419,5 @@
 	  if (!demangler || !(nm = (*demangler)(g->name)))
 	    nm = g->name;
-	  errmsg = xmalloc (strlen (errfmt) + strlen (nm) + 1);
+	  errmsg = (char *) xmalloc (strlen (errfmt) + strlen (nm) + 1);
 	  sprintf (errmsg, errfmt, nm, data_segment ? "data" : "text");
 	  if (nm != g->name)
@@ -3854,6 +3854,5 @@
 void check_exe (void)
 {
-  char *ext, *tmp_dir;
-  size_t tmp_dir_len;
+  char *ext;
 
   if (exe_flag)
@@ -3867,5 +3866,5 @@
       {
         touch_filename = output_filename;
-        exe_filename = concat (output_filename, ".exe", "");
+        exe_filename = concat (output_filename, ".exe", NULL);
       }
     }
@@ -3887,16 +3886,5 @@
   /* Create a temporary a.out executable file. */
 
-  tmp_dir = getenv ("TMPDIR");
-  if (tmp_dir == NULL) tmp_dir = getenv ("TMP");
-  if (tmp_dir == NULL) tmp_dir = getenv ("TEMP");
-  if (tmp_dir == NULL) tmp_dir = ".";
-  tmp_dir_len = strlen (tmp_dir);
-  output_filename = xmalloc (tmp_dir_len + 10);
-  memcpy (output_filename, tmp_dir, tmp_dir_len);
-  if (tmp_dir_len != 0 && strchr ("\\/:", tmp_dir[tmp_dir_len-1]) == NULL)
-    output_filename[tmp_dir_len++] = '\\';
-  strcpy (output_filename + tmp_dir_len, "ldXXXXXX");
-  if (mktemp (output_filename) == NULL)
-    fatal ("mktemp(\"%s\") failed", output_filename);
+  output_filename = make_temp_file ("ldXXXXXX");
 
   if (rsxnt_linked != EMX_DEFAULT && strip_symbols != STRIP_NONE) /* RSXNT */
@@ -5051,5 +5039,5 @@
         if (strncmp (tmp, "-l", 2) != 0
             && (len < 2 || strcmp (tmp+len-2, ".o") != 0))
-          tmp = concat (tmp, ".o", "");   /* Needed by GDB */
+          tmp = concat (tmp, ".o", NULL);   /* Needed by GDB */
         nl.n_un.n_strx = assign_string_table_index (tmp);
       }
@@ -5397,5 +5385,5 @@
 
   if (errno < sys_nerr)
-    s = concat ("", sys_errlist[errno], " for %s");
+    s = concat ("", sys_errlist[errno], " for %s", NULL);
   else
     s = "cannot open %s";
@@ -5413,5 +5401,5 @@
 
   if (errno < sys_nerr)
-    s = concat ("", sys_errlist[errno], " for ");
+    s = concat ("", sys_errlist[errno], " for ", NULL);
   else
     s = "cannot open ";
@@ -5474,22 +5462,4 @@
 }
 
-/* Return a newly-allocated string
-   whose contents concatenate the strings S1, S2, S3.  */
-
-char *
-concat (s1, s2, s3)
-     const char *s1, *s2, *s3;
-{
-  register int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
-  register char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
-
-  strcpy (result, s1);
-  strcpy (result + len1, s2);
-  strcpy (result + len1 + len2, s3);
-  result[len1 + len2 + len3] = 0;
-
-  return result;
-}
-
 /* Parse the string ARG using scanf format FORMAT, and return the result.
    If it does not parse, report fatal error
@@ -5508,7 +5478,7 @@
 /* Like malloc but get fatal error if memory is exhausted.  */
 
-char *
+void *
 xmalloc (size)
-     int size;
+     size_t size;
 {
   register char *result = malloc (size);
@@ -5523,5 +5493,5 @@
 xrealloc (ptr, size)
      void *ptr;
-     int size;
+     size_t size;
 {
   register char *result = realloc (ptr, size);
@@ -5684,5 +5654,5 @@
      */
     pName = (struct lx_tmp *)xmalloc(sizeof(*pName));
-    pName->name = psz = xmalloc(_MAX_PATH);
+    pName->name = psz = (char *)xmalloc(_MAX_PATH);
     if (!make_tempfile(psz, "lddef", ".def"))
     {
