delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/05/03/15:33:54

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
X-Authentication-Warning: modi.xraylith.wisc.edu: khan owned process doing -bs
Date: Mon, 3 May 1999 14:33:33 -0500 (CDT)
From: Mumit Khan <khan AT xraylith DOT wisc DOT edu>
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: (fixed patch) "%E" formatting for the humans
In-Reply-To: <199905031744.MAA00299@modi.xraylith.wisc.edu>
Message-ID: <Pine.SUN.3.93.990503141844.753D-100000@modi.xraylith.wisc.edu>
MIME-Version: 1.0

[ I sent an old copy out by accident, sorry. Please ignore the last 
  one in favor of this. ]

This is a trivial, but useful change that tells you things like:
  
  dlopen: The specified module could not be found.

instead of 

  dlopen: Win32 error 127.

Note the comment about the buffer size issue in __small_vsprintf. Anyone
more familiar with how the various message buffers are allocated in winsup, 
please take a look.


Mon May  3 11:32:32 1999  Mumit Khan  <khan AT xraylith DOT wisc DOT edu>

	* smallprint.c (__small_vsprintf): Properly format win32 error 
	messages.
	* dlfcn.cc (set_dl_error): Lose the "Win32 ".


Index: smallprint.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/smallprint.c,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 smallprint.c
--- smallprint.c	1999/05/03 15:22:19	1.1.1.1
+++ smallprint.c	1999/05/03 18:13:31
@@ -97,8 +97,40 @@ __small_vsprintf (char *dst, const char 
 	      }
 	      break;
 	    case 'E':
-	      strcpy (dst, "error ");
-	      dst = rn (dst + 6, 10, 1, GetLastError (), len, pad);
+	      {
+		/* 
+		 * NOTE: Currently there is no policy for how long the
+		 * the buffers are, and looks like 256 is a smallest one
+		 * (dlfcn.cc). Other than error 1395 (length 213) and 
+		 * error 1015 (length 249), the rest are all under 188 
+		 * characters, and so I'll use 189 as the buffer length. 
+		 * For those longer error messages, FormatMessage will 
+		 * return FALSE, and we'll get the old behaviour such as
+		 * ``Win32 error 1395'' etc.
+		 */
+		const int bufferlen = 189;
+		int errnum = GetLastError ();
+		if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+				   | FORMAT_MESSAGE_IGNORE_INSERTS,
+				   NULL,  
+				   errnum,
+				   MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+				   (LPTSTR) dst,
+				   bufferlen,
+				   NULL))
+		  {
+		    /* Get rid the trailing CR/NL pair. */
+		    int msglen = strlen (dst);
+		    dst += msglen - 2;
+		  }
+		else
+		  {
+		    /* Fallback in case buffer is too small or some other
+		       error. */
+		    strcpy (dst, "Win32 error ");
+		    dst = rn (dst + 6, 10, 1, errnum, len, pad);
+		  }
+	      }
 	      break;
 	    case 'd':
 	      dst = rn (dst, 10, 1, va_arg (ap, int), len, pad);
Index: dlfcn.cc
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/dlfcn.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 dlfcn.cc
--- dlfcn.cc	1999/05/03 15:22:19	1.1.1.1
+++ dlfcn.cc	1999/05/03 16:29:57
@@ -27,7 +27,7 @@ static char _dl_buffer[256];
 static void
 set_dl_error (const char *str)
 {
-  __small_sprintf (_dl_buffer, "%s: Win32 %E", str);
+  __small_sprintf (_dl_buffer, "%s: %E", str);
   _dl_error = 1;
 }
 
Regards,
Mumit

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019