changeset 5136:500f269bf0a8

(getwd): If getcwd returns 0, we return 0. (getwd for VMS): Likewise. (read_input_waiting): read_socket_hook delivers events, not characters. Make buf smaller in the case where we actually call read itself.
author Richard M. Stallman <rms@gnu.org>
date Tue, 23 Nov 1993 11:06:13 +0000
parents b8731641d26a
children d11c5909a2d0
files src/sysdep.c
diffstat 1 files changed, 48 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/sysdep.c	Tue Nov 23 11:03:16 1993 +0000
+++ b/src/sysdep.c	Tue Nov 23 11:06:13 1993 +0000
@@ -2093,45 +2093,60 @@
 
 read_input_waiting ()
 {
-  char buf[256 * BUFFER_SIZE_FACTOR];
   struct input_event e;
   int nread, i;
   extern int quit_char;
 
   if (read_socket_hook)
     {
+      struct input_event buf[256];
+
       read_alarm_should_throw = 0;
       if (! setjmp (read_alarm_throw))
-	nread = (*read_socket_hook) (0, buf, 256 * BUFFER_SIZE_FACTOR, 1, 0);
+	nread = (*read_socket_hook) (0, buf, 256, 1, 0);
       else
 	nread = -1;
+
+      /* Scan the chars for C-g and store them in kbd_buffer.  */
+      for (i = 0; i < nread; i++)
+	{
+	  kbd_buffer_store_event (&buf[i]);
+	  /* Don't look at input that follows a C-g too closely.
+	     This reduces lossage due to autorepeat on C-g.  */
+	  if (buf[i].kind == ascii_keystroke
+	      && XINT(buf[i].code) == quit_char)
+	    break;
+	}
     }
   else
-    nread = read (fileno (stdin), buf, 1);
-
-  /* Scan the chars for C-g and store them in kbd_buffer.  */
-  e.kind = ascii_keystroke;
-  e.frame_or_window = selected_frame;
-  e.modifiers = 0;
-  for (i = 0; i < nread; i++)
     {
-      /* Convert chars > 0177 to meta events if desired.
-	 We do this under the same conditions that read_avail_input does.  */
-      if (read_socket_hook == 0)
+      char buf[3];
+      nread = read (fileno (stdin), buf, 1);
+
+      /* Scan the chars for C-g and store them in kbd_buffer.  */
+      e.kind = ascii_keystroke;
+      e.frame_or_window = selected_frame;
+      e.modifiers = 0;
+      for (i = 0; i < nread; i++)
 	{
-	  /* If the user says she has a meta key, then believe her. */
-	  if (meta_key == 1 && (buf[i] & 0x80))
-	    e.modifiers = meta_modifier;
-	  if (meta_key != 2)
-	    buf[i] &= ~0x80;
+	  /* Convert chars > 0177 to meta events if desired.
+	     We do this under the same conditions that read_avail_input does.  */
+	  if (read_socket_hook == 0)
+	    {
+	      /* If the user says she has a meta key, then believe her. */
+	      if (meta_key == 1 && (buf[i] & 0x80))
+		e.modifiers = meta_modifier;
+	      if (meta_key != 2)
+		buf[i] &= ~0x80;
+	    }
+
+	  XSET (e.code, Lisp_Int, buf[i]);
+	  kbd_buffer_store_event (&e);
+	  /* Don't look at input that follows a C-g too closely.
+	     This reduces lossage due to autorepeat on C-g.  */
+	  if (buf[i] == quit_char)
+	    break;
 	}
-
-      XSET (e.code, Lisp_Int, buf[i]);
-      kbd_buffer_store_event (&e);
-      /* Don't look at input that follows a C-g too closely.
-	 This reduces lossage due to autorepeat on C-g.  */
-      if (buf[i] == quit_char)
-	break;
     }
 }
 
@@ -2734,6 +2749,8 @@
 
   BLOCK_INPUT;			/* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
+  if (spath == 0)
+    return spath;
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
   while (*npath && *npath != '/')
@@ -3613,13 +3630,18 @@
 getwd (pathname)
      char *pathname;
 {
-  char *ptr;
+  char *ptr, *val;
   extern char *getcwd ();
 
 #define MAXPATHLEN 1024
 
   ptr = xmalloc (MAXPATHLEN);
-  getcwd (ptr, MAXPATHLEN);
+  val = getcwd (ptr, MAXPATHLEN);
+  if (val == 0)
+    {
+      xfree (ptr);
+      return val;
+    }
   strcpy (pathname, ptr);
   xfree (ptr);