⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipe.c

📁 UNIX下SH的实现源码
💻 C
字号:
#ifdef __DJGPP__

#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <sys/stat.h>
#include <libc/environ.h>
#include "dosutil.h"

int
pipe (int fds[2])
{
  int ifd;
  int ofd;
  static char tmp_template[PATH_MAX + 1];
  static char temp_name[PATH_MAX + 1];
  static unsigned environ_changed = 0;
  char *tname;

  if (environ_changed != __environ_changed)
  {
    _fixpath ("/dev/env/TMPDIR/ppXXXXXX", tmp_template);
    environ_changed = __environ_changed;
  }

  strcpy (temp_name, tmp_template);
  tname = mktemp (temp_name);
  if (tname == NULL)
    return -1;

  ofd = _opentmp(tname, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR);
  if (ofd < 0)
  {
    free (tname);
    return -1;
  }

  /* Move the handle up so it doesn't count against the 20 handle
     inherit limit.  */
  if (ofd < 20)
  {
    int tfd;

    tfd = fcntl (ofd, F_DUPFD, 20);
    close (ofd);
    if (tfd < 0)
    {
      remove (tname);
      return -1;
    }
    ofd = tfd;
  }

  /* Move this handle up too.  */
  ifd = fcntl (ofd, F_DUPFD, 20);
  if (ifd < 0)
  {
    close (ofd);
    remove (tname);
    return -1;
  }

  fds[0] = ifd;
  fds[1] = ofd;

  return 0;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -