zsh-workers
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: zsh-workers@math.gatech.edu (Zsh hacking and development)
Subject: PATCH: set blocking read on stdin
Date: Fri, 8 May 1998 01:23:15 -0500 (CDT)	[thread overview]
Message-ID: <199805080623.BAA02616@hzoli.home> (raw)

This patch sets blocking read on stdin when the shell reads commands from
there or when it is used by the read builtin.  This is required by POSIX.

Zoli


*** Src/builtin.c.orig	Fri May  8 01:04:12 1998
--- Src/builtin.c	Fri May  8 01:15:15 1998
*************** bin_read(char *name, char **args, char *
*** 3175,3181 ****
  static int
  zread(void)
  {
!     char cc;
  
      /* use zbuf if possible */
      if (zbuf)
--- 3175,3181 ----
  static int
  zread(void)
  {
!     char cc, retry = 0;
  
      /* use zbuf if possible */
      if (zbuf)
*************** zread(void)
*** 3186,3197 ****
  	    return zbuf++, STOUC(*zbuf++ ^ 32);
  	else
  	    return (*zbuf) ? STOUC(*zbuf++) : EOF;
!     /* read a character from readfd */
!     if (read(readfd, &cc, 1) != 1)
! 	/* on EOF, return EOF */
  	return EOF;
!     /* return the character read */
!     return STOUC(cc);
  }
  
  /* holds arguments for testlex() */
--- 3186,3207 ----
  	    return zbuf++, STOUC(*zbuf++ ^ 32);
  	else
  	    return (*zbuf) ? STOUC(*zbuf++) : EOF;
!     for (;;) {
! 	/* read a character from readfd */
! 	switch (read(readfd, &cc, 1)) {
! 	case 1:
! 	    /* return the character read */
! 	    return STOUC(cc);
! 	case -1:
! 	    if (!retry && errno == EWOULDBLOCK &&
! 		readfd == 0 && setblock_stdin()) {
! 		retry = 1;
! 		continue;
! 	    }
! 	    break;
! 	}
  	return EOF;
!     }
  }
  
  /* holds arguments for testlex() */
*** Src/init.c.orig	Sat May  2 03:45:37 1998
--- Src/init.c	Fri May  8 01:15:15 1998
*************** loop(int toplevel, int justonce)
*** 88,95 ****
      for (;;) {
  	freeheap();
  	errflag = 0;
! 	if (interact && isset(SHINSTDIN))
! 	    preprompt();
  	hbegin();		/* init history mech        */
  	intr();			/* interrupts on            */
  	lexinit();              /* initialize lexical state */
--- 88,98 ----
      for (;;) {
  	freeheap();
  	errflag = 0;
! 	if (isset(SHINSTDIN)) {
! 	    setblock_stdin();
! 	    if (interact)
! 		preprompt();
! 	}
  	hbegin();		/* init history mech        */
  	intr();			/* interrupts on            */
  	lexinit();              /* initialize lexical state */
*** Src/utils.c.orig	Sat May  2 03:47:05 1998
--- Src/utils.c	Fri May  8 01:18:58 1998
*************** zstrtol(const char *s, char **t, int bas
*** 1076,1081 ****
--- 1076,1099 ----
  
  /**/
  int
+ setblock_stdin(void)
+ {
+ #ifdef O_NONBLOCK
+     struct stat st;
+     long mode;
+ 
+     if (!fstat(0, &st) && !S_ISREG(st.st_mode)) {
+ 	mode = fcntl(0, F_GETFL);
+ 	if (mode != -1 && (mode & O_NONBLOCK) &&
+ 	    !fcntl(0, F_SETFL, mode & ~O_NONBLOCK))
+ 	    return 1;
+     }
+ #endif
+     return 0;
+ }
+ 
+ /**/
+ int
  checkrmall(char *s)
  {
      fprintf(shout, "zsh: sure you want to delete all the files in ");


                 reply	other threads:[~1998-05-08  6:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199805080623.BAA02616@hzoli.home \
    --to=hzoli@cs.elte.hu \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).