close (fildes[0]);   if ((*word)[*word_length - 1] == '\n') (*word)[--*word_length] = '\0';  return 0;
exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,	   int flags, wordexp_t *pwordexp, const char *ifs,	   const char *ifs_white){  int fildes[2];  int bufsize = 128;  int buflen;  int i;  char *buffer;  pid_t pid;  /* Don't fork() unless necessary */  if (!comm || !*comm)    return 0;  if (pipe (fildes))    /* Bad */    return WRDE_NOSPACE;  if ((pid = fork ()) < 0)    {      /* Bad */      return WRDE_NOSPACE;    }  if (pid == 0)    {      /* Child */      const char *args[4] = { _PATH_BSHELL, "-c", comm, NULL };      /* Redirect input and output */      dup2 (fildes[1], 1);      /* Close stderr if we have to */      if ((flags & WRDE_SHOWERR) == 0)	close (2);      __execve (_PATH_BSHELL, (char *const *) args, __environ);      /* Bad.  What now?  */      abort ();    }  /* Parent */  close (fildes[1]);  buffer = __alloca (bufsize);  if (!pwordexp)    { /* Quoted - no field splitting */      while (1)	{	  if ((buflen = read (fildes[0], buffer, bufsize)) < 1)	    {	      if (__waitpid (pid, NULL, WNOHANG) == 0)		continue;	      if ((buflen = read (fildes[0], buffer, bufsize)) < 1)		break;	    }	  *word = w_addmem (*word, word_length, max_length, buffer, buflen);	  if (*word == NULL)	    {	      close (fildes[0]);	      return WRDE_NOSPACE;	    }	}      close (fildes[0]);      /* bash chops off a terminating linefeed, which seems sensible */      if ((*word)[*word_length - 1] == '\n')	(*word)[--*word_length] = '\0';      return 0;    }  else    /* Not quoted - split fields */    {      int copying = 0;      /* 'copying' is:       *  0 when searching for first character in a field not IFS white space       *  1 when copying the text of a field       *  2 when searching for possible non-whitespace IFS       */      while (1)	{	  if ((buflen = read (fildes[0], buffer, bufsize)) < 1)	    {	      if (__waitpid (pid, NULL, WNOHANG) == 0)		continue;	      if ((read (fildes[0], buffer, bufsize)) < 1)		break;	    }	  for (i = 0; i < buflen; ++i)	    {	      if (strchr (ifs, buffer[i]) != NULL)		{		  /* Current character is IFS */		  if (strchr (ifs_white, buffer[i]) == NULL)		    {		      /* Current character is IFS but not whitespace */		      if (copying == 2)			{			  /*            current character			   *                   |			   *                   V			   * eg: text<space><comma><space>moretext			   *			   * So, strip whitespace IFS (like at the start)			   */			  copying = 0;			  continue;			}		      copying = 0;		      /* fall through and delimit field.. */		    }		  else		    {		      /* Current character is IFS white space */		      /* If not copying a field, ignore it */		      if (copying != 1)			continue;		      /* End of field (search for non-IFS afterwards) */		      copying = 2;		    }		  /* First IFS white space, or IFS non-whitespace.		   * Delimit the field. */		  if (!*word)		    {		      /* This field is null, so make it an empty string */		      *word = w_addchar (*word, word_length, max_length, 0);		      if (*word == NULL)			{			  close (fildes[0]);			  return WRDE_NOSPACE;			}		    }		  if (w_addword (pwordexp, *word) == WRDE_NOSPACE)		    {		      /* Should do __waitpid? */		      close (fildes[0]);		      return WRDE_NOSPACE;		    }		  *word = NULL;		  *word_length = 0;		  *max_length = 0;		  /* fall back round the loop.. */		}	      else		{		  /* Not IFS character */		  copying = 1;		  *word = w_addchar (*word, word_length, max_length,				     buffer[i]);		  if (*word == NULL)		    {		      close (fildes[0]);		      return WRDE_NOSPACE;		    }		}	    }	}    }  close (fildes[0]);  return 0;}