From: Anantha Kesari H Y Date: Wed, 29 Jun 2005 08:59:30 +0000 (+0000) Subject: NetWare LibC has pipe/popen support X-Git-Tag: php-5.1.0b3~273 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5aeda297119d3538abf7ca8dcb79f45e7aedc5d;p=php NetWare LibC has pipe/popen support --- diff --git a/netware/pipe.c b/netware/pipe.c deleted file mode 100644 index c302fdf3e0..0000000000 --- a/netware/pipe.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * FILENAME : pipe.c - * DESCRIPTION : Functions to implement pipes on NetWare. - * Author : Anantha Kesari H Y, Venkat Raghavan S, Srivathsa M - * - */ - -#include -#include -#include - -#include "netware/pipe.h" -#include "netware/mktemp.h" - - -/* Following definitions unavailable in LibC, hence borrowed from CLib */ -#define P_WAIT 0 -#define P_NOWAIT 1 - -#define WHITESPACE " \t" -#define MAX_ARGS 10 - - -FILE* popen(const char* commandline, const char* mode) -{ - int err, count; - char pszPipestr[32] = {'\0'}; - char *command = NULL, *argv[MAX_ARGS] = {'\0'}; - int fd = -1; - fd_set myfds; - wiring_t wiring; - pid_t pid=0; - FILE *fp=NULL; - char *ptr = NULL; - int ptrLen = 0, argc = 0, i = 0; - - - /* Get a temporary name */ - (void) tmpnam(strecpy(pszPipestr, "PHP/php$pipe/")); - - wiring.infd=FD_UNUSED; - wiring.outfd=FD_UNUSED; - wiring.errfd=FD_UNUSED; - - /* Open a pipe */ - if ( *mode=='r') { - fd = pipe_open (pszPipestr, O_RDONLY); - if (fd == -1) - return NULL; - - wiring.outfd=fd; - } else if (*mode=='w') { - fd = pipe_open (pszPipestr, O_WRONLY); - if (fd == -1) - return NULL; - - wiring.infd=fd; - } else { - consoleprintf ("Unsupported pipe open mode \n"); - return NULL; - } - - /* Get the file pointer */ - fp = fdopen(fd, mode); - if (fp == NULL) { - consoleprintf ("Failure in fdopen \n"); - close (fd); - return NULL; - } - - /* Separate commandline string into words */ - ptr = strtok((char*)commandline, WHITESPACE); - ptrLen = strlen(ptr); - - /* Get the command */ - command = (char*)malloc(ptrLen + 1); - if(command == NULL) { - consoleprintf ("Failure in memory allocation \n"); - close (fd); - fclose (fp); - return NULL; - } - strcpy (command, ptr); - - /* Command as the first argument into prcessve */ - argv[argc] = (char*)malloc(ptrLen + 1); - if(argv[argc] == NULL) { - consoleprintf ("Failure in memory allocation \n"); - close (fd); - fclose (fp); - if(command) { - free(command); - command = NULL; - } - return NULL; - } - strcpy (argv[argc], ptr); - argc++; - - /* Get more arguments if any to be passed to prcessve */ - ptr = strtok(NULL, WHITESPACE); - while (ptr && (argc < MAX_ARGS)) - { - ptrLen = strlen(ptr); - - argv[argc] = (char*)malloc(ptrLen + 1); - if(argv[argc] == NULL) { - consoleprintf ("Failure in memory allocation \n"); - close (fd); - fclose (fp); - if(command) { - free(command); - command = NULL; - } - return NULL; - } - strcpy (argv[argc], ptr); - argc++; - - ptr = strtok(NULL, WHITESPACE); - } - argv[argc] = NULL; - - FD_ZERO(&myfds); - FD_SET(fd, &myfds); - - pid = processve(command, PROC_CURRENT_SPACE, NULL, &wiring, - &myfds, NULL, (const char **)argv ); - if (pid == -1) { - consoleprintf ("Failure in processve call \n"); - close (fd); - fclose(fp); - if(command) { - free(command); - command = NULL; - } - for(i=0; i