示例#1
0
文件: popen.c 项目: Elliriya/GAWK
int
os_pclose( FILE * current)
{
    int cur = fileno(current);
    int fd, rval;

#if defined(OS2) && (_MSC_VER != 510)
    if (_osmode == OS2_MODE)
      return(pclose(current));
#endif

#if defined(__MINGW32__) || (defined(_MSC_VER) && defined(WIN32))
    rval = pclose(current);
    *pipes[cur].pmode = '\0';
    unlink_and_free(pipes[cur].command);
    return rval;
#endif

    /*
    ** check for an open file.
    */
    switch (*pipes[cur].pmode) {
    case 'r':
        /*
        ** input pipes are just files we're done with.
        */
        rval = fclose(current);
        unlink(pipes[cur].name);
	break;
    case 'w':
        /*
        ** output pipes are temporary files we have
        ** to cram down the throats of programs.
        */
        fclose(current);
	rval = -1;
	if ((fd = dup(fileno(stdin))) != -1) {
	  char *mode = pipes[cur].pmode; *mode = 'r';
	  if (current = freopen(pipes[cur].name, mode, stdin)) {
	    rval = os_system(pipes[cur].command);
	    fclose(current);
	    if (dup2(fd, fileno(stdin)) == -1) rval = -1;
	    close(fd);
	  }
	}
        unlink(pipes[cur].name);
	break;
    default:
      return -1;
    }
    /*
    ** clean up current pipe.
    */
    *pipes[cur].pmode = '\0';
    free(pipes[cur].name);
    free(pipes[cur].command);
    return rval;
}
示例#2
0
文件: popen.c 项目: Elliriya/GAWK
int
os_system(const char *cmd)
{
  char *s;
  int i;
  char *cmd1;

#if defined(OS2)
  if (_osmode == OS2_MODE)
    return(system(cmd));
#endif

  if ((cmd1 = scriptify(cmd)) == NULL) return(1);
  if (s = getenv("SHELL"))
    i = spawnlp(P_WAIT, s, s, cmd1 + strlen(s), NULL);
  else
    i = system(cmd1);
  unlink_and_free(cmd1);
  return(i);
}
示例#3
0
文件: dequeue.c 项目: baskarang/icnc
void* deq_popBack(dequeue q) {
  return unlink_and_free(q->tail->prev);
}
示例#4
0
文件: dequeue.c 项目: baskarang/icnc
void* deq_popFront(dequeue q){
  return unlink_and_free(q->head->next);
}
示例#5
0
void *
dq_deq_back(dqueue q)
{
	assert(!dq_empty(q));
	return unlink_and_free(q -> sentinel -> prev);
}
示例#6
0
void *
dq_deq_front(dqueue q)
{
	assert(!dq_empty(q));
	return unlink_and_free(q -> sentinel -> next);
}