Remove a few more instances of strncpy.

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index 022e127..552dd1f 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -223,22 +223,29 @@
  */
 unsigned char* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
 {
+  unsigned char* ret = dst;
   if(!n)
     return dst;
   if(MSVCRT___mb_cur_max > 1)
   {
-    unsigned char* ret = dst;
-    while (*src && n--)
+    while (*src && n)
     {
+      n--;
       *dst++ = *src;
       if (MSVCRT_isleadbyte(*src++))
           *dst++ = *src++;
     }
-    while(n--)
-      *dst++ = '\0';
-    return ret;
   }
-  return strncpy(dst, src, n); /* ASCII CP */
+  else
+  {
+    while (n)
+    {
+        n--;
+        if (!(*dst++ = *src++)) break;
+    }
+  }
+  while (n--) *dst++ = 0;
+  return ret;
 }
 
 /*********************************************************************
@@ -246,13 +253,14 @@
  */
 unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
 {
+  unsigned char* ret = dst;
   if(!n)
     return dst;
   if(MSVCRT___mb_cur_max > 1)
   {
-    unsigned char* ret = dst;
-    while (*src && (n-- > 1))
+    while (*src && (n > 1))
     {
+      n--;
       *dst++ = *src;
       if (MSVCRT_isleadbyte(*src++))
       {
@@ -268,11 +276,17 @@
       *dst++ = *src;
       n--;
     }
-    while (n--)
-      *dst++ = '\0';
-    return ret;
   }
-  return strncpy(dst, src, n); /* ASCII CP */
+  else
+  {
+    while (n)
+    {
+        n--;
+        if (!(*dst++ = *src++)) break;
+    }
+  }
+  while (n--) *dst++ = 0;
+  return ret;
 }
 
 /*********************************************************************
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 845cf74..a589e7f 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -1515,9 +1515,9 @@
 		mach_port_t masterPort;
 		
 		char bsdName[6]; /* disk#\0 */
-		
-		strncpy(bsdName, stfs.f_mntfromname+strlen(_PATH_DEV) , 5);
-		bsdName[5] = 0;
+                const char *name = stfs.f_mntfromname + strlen(_PATH_DEV);
+                memcpy( bsdName, name, min(strlen(name)+1,sizeof(bsdName)) );
+                bsdName[sizeof(bsdName)-1] = 0;
 
 		kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
 
diff --git a/include/wine/library.h b/include/wine/library.h
index ecd9d7f..adcb1ea 100644
--- a/include/wine/library.h
+++ b/include/wine/library.h
@@ -39,9 +39,9 @@
 
 typedef void (*load_dll_callback_t)( void *, const char * );
 
-extern void *wine_dlopen( const char *filename, int flag, char *error, int errorsize );
-extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
-extern int wine_dlclose( void *handle, char *error, int errorsize );
+extern void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize );
+extern void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize );
+extern int wine_dlclose( void *handle, char *error, size_t errorsize );
 extern void wine_dll_set_callback( load_dll_callback_t load );
 extern void *wine_dll_load( const char *filename, char *error, int errorsize, int *file_exists );
 extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize,
diff --git a/libs/wine/debug.c b/libs/wine/debug.c
index 44d2fd6..a25e468 100644
--- a/libs/wine/debug.c
+++ b/libs/wine/debug.c
@@ -121,13 +121,15 @@
 {
     struct dll *dll = first_dll;
     struct debug_option *opt;
+    size_t len = strlen(name);
 
     if (!(opt = malloc( sizeof(*opt) ))) return;
     opt->next  = NULL;
     opt->set   = set;
     opt->clear = clear;
-    strncpy( opt->name, name, sizeof(opt->name) );
-    opt->name[sizeof(opt->name)-1] = 0;
+    if (len >= sizeof(opt->name)) len = sizeof(opt->name) - 1;
+    memcpy( opt->name, name, len );
+    opt->name[len] = 0;
     if (last_option) last_option->next = opt;
     else first_option = opt;
     last_option = opt;
diff --git a/libs/wine/loader.c b/libs/wine/loader.c
index 90b94c0..d007398 100644
--- a/libs/wine/loader.c
+++ b/libs/wine/loader.c
@@ -558,7 +558,7 @@
 /***********************************************************************
  *		wine_dlopen
  */
-void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
+void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize )
 {
 #ifdef HAVE_DLOPEN
     void *ret;
@@ -566,18 +566,26 @@
     dlerror(); dlerror();
     ret = dlopen( filename, flag );
     s = dlerror();
-    if (error)
+    if (error && errorsize)
     {
-        strncpy( error, s ? s : "", errorsize );
-        error[errorsize - 1] = '\0';
+        if (s)
+        {
+            size_t len = strlen(s);
+            if (len >= errorsize) len = errorsize - 1;
+            memcpy( error, s, len );
+            error[len] = 0;
+        }
+        else error[0] = 0;
     }
     dlerror();
     return ret;
 #else
     if (error)
     {
-        strncpy( error, "dlopen interface not detected by configure", errorsize );
-        error[errorsize - 1] = '\0';
+        static const char msg[] = "dlopen interface not detected by configure";
+        size_t len = min( errorsize, sizeof(msg) );
+        memcpy( error, msg, len );
+        error[len - 1] = 0;
     }
     return NULL;
 #endif
@@ -586,7 +594,7 @@
 /***********************************************************************
  *		wine_dlsym
  */
-void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
+void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize )
 {
 #ifdef HAVE_DLOPEN
     void *ret;
@@ -594,18 +602,26 @@
     dlerror(); dlerror();
     ret = dlsym( handle, symbol );
     s = dlerror();
-    if (error)
+    if (error && errorsize)
     {
-        strncpy( error, s ? s : "", errorsize );
-        error[errorsize - 1] = '\0';
+        if (s)
+        {
+            size_t len = strlen(s);
+            if (len >= errorsize) len = errorsize - 1;
+            memcpy( error, s, len );
+            error[len] = 0;
+        }
+        else error[0] = 0;
     }
     dlerror();
     return ret;
 #else
     if (error)
     {
-        strncpy( error, "dlopen interface not detected by configure", errorsize );
-        error[errorsize - 1] = '\0';
+        static const char msg[] = "dlopen interface not detected by configure";
+        size_t len = min( errorsize, sizeof(msg) );
+        memcpy( error, msg, len );
+        error[len - 1] = 0;
     }
     return NULL;
 #endif
@@ -614,7 +630,7 @@
 /***********************************************************************
  *		wine_dlclose
  */
-int wine_dlclose( void *handle, char *error, int errorsize )
+int wine_dlclose( void *handle, char *error, size_t errorsize )
 {
 #ifdef HAVE_DLOPEN
     int ret;
@@ -622,18 +638,26 @@
     dlerror(); dlerror();
     ret = dlclose( handle );
     s = dlerror();
-    if (error)
+    if (error && errorsize)
     {
-        strncpy( error, s ? s : "", errorsize );
-        error[errorsize - 1] = '\0';
+        if (s)
+        {
+            size_t len = strlen(s);
+            if (len >= errorsize) len = errorsize - 1;
+            memcpy( error, s, len );
+            error[len] = 0;
+        }
+        else error[0] = 0;
     }
     dlerror();
     return ret;
 #else
     if (error)
     {
-        strncpy( error, "dlopen interface not detected by configure", errorsize );
-        error[errorsize - 1] = '\0';
+        static const char msg[] = "dlopen interface not detected by configure";
+        size_t len = min( errorsize, sizeof(msg) );
+        memcpy( error, msg, len );
+        error[len - 1] = 0;
     }
     return 1;
 #endif
diff --git a/tools/sfnt2fnt.c b/tools/sfnt2fnt.c
index d3d9124..8387421 100644
--- a/tools/sfnt2fnt.c
+++ b/tools/sfnt2fnt.c
@@ -163,7 +163,6 @@
     int num_names;
     const union cptable *cptable;
     FT_SfntName sfntname;
-    char namebuf[4096];
     TT_OS2 *os2;
     cptable = wine_cp_get_table(enc);
     if(!cptable) {
@@ -207,13 +206,12 @@
     num_names = FT_Get_Sfnt_Name_Count(face);
     for(i = 0; i <num_names; i++) {
         FT_Get_Sfnt_Name(face, i, &sfntname);
-        memcpy(namebuf, sfntname.string, sfntname.string_len);
-        namebuf[sfntname.string_len] = '\0';
         if(sfntname.platform_id == 1 && sfntname.encoding_id == 0 &&
            sfntname.language_id == 0 && sfntname.name_id == 0) {
-            strncpy(hdr.dfCopyright, namebuf, 60);
-            hdr.dfCopyright[59] = '\0';
-	}
+            size_t len = min( sfntname.string_len, sizeof(hdr.dfCopyright)-1 );
+            memcpy(hdr.dfCopyright, sfntname.string, len);
+            hdr.dfCopyright[len] = 0;
+        }
     }
 
     os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
diff --git a/tools/winedump/dump.c b/tools/winedump/dump.c
index 4a269ab..b594753 100644
--- a/tools/winedump/dump.c
+++ b/tools/winedump/dump.c
@@ -86,15 +86,16 @@
 const char*	get_time_str(DWORD _t)
 {
     time_t 	t = (time_t)_t;
+    const char *str = ctime(&t);
+    size_t len = strlen(str);
     static char	buf[128];
-
     /* FIXME: I don't get the same values from MS' pedump running under Wine...
      * I wonder if Wine isn't broken wrt to GMT settings...
      */
-    strncpy(buf, ctime(&t), sizeof(buf));
-    buf[sizeof(buf) - 1] = '\0';
-    if (buf[strlen(buf)-1] == '\n')
-	buf[strlen(buf)-1] = '\0';
+    if (len && str[len-1] == '\n') len--;
+    if (len >= sizeof(buf)) len = sizeof(buf) - 1;
+    memcpy( buf, str, len );
+    buf[len] = 0;
     return buf;
 }