Exemple #1
0
FILE* io_open_read(const char* path, pid_t* thepid) {
  FILE *f;
  struct stat s;
  size_t len = str_len (path);

  if (!len)
    return NULL;

  if (path[len - 1] == '|') {
    /* read from a pipe */

    char *s = str_dup (path);

    s[len - 1] = 0;
#if 0
    /* XXX */
    mutt_endwin (NULL);
#endif
    *thepid = command_filter(s, NULL, &f, NULL);
    mem_free (&s);
  }
  else {
    if (stat (path, &s) < 0)
      return (NULL);
    if (S_ISDIR (s.st_mode)) {
      errno = EINVAL;
      return (NULL);
    }
    f = fopen (path, "r");
    *thepid = -1;
  }
  return (f);
}
void *send(void *fd) 
{ 
	int c; 
	char buf[255]; 


	c = 0; 
	do { 
		memset(buf, 0, 255); 
		read(STDIN_FILENO, buf, 255); 


		command_filter(buf, fd); 


		if (strlen(buf) > 0) { 
			if (write(*(int *)fd, buf, strlen(buf)) == -1) 
				perror("write"); 
		} 
	} while(1); 
}