GRASS on Linux 0.96c

alastair small g asmall2 at mamut.wlu.ca
Thu Jul 16 20:27:34 EDT 1992


Hi there,

I'm trying to compile GRASS4.0 under LINUX 0.96c using gcc 2.2.2
and am running into problems, hopefully someone will be able to help me,
or point me in the right direction.

When I run GISGEN or gmake4.0 in the src/libes/gis directory I get the following

rm -f OBJ/popen.o
cc -O -DGETHOSTNAME_OK -I/grass/src/libes -DUSE_TERMIO -c popen.c

popen.c: In function 'popen':
popen.c:15: argument 'cmd' doesn't match prototype
popen.c:15: argument 'mode' doesn't match prototype
popen.c: In function 'pclose':
popen.c:54: warning: assignment from incompatible pointer type
popen.c:55:   "          "        "       "          "      "
popen.c:56:   "          "	  " 	  "	     "      "
popen.c:64: warning: passing arg 2 of 'signal' from incompatible pointer
type
popen.c:65:   "
popen.c:66:   "

make: *** [OBJ/popen.o] Error 1.


I'm no C wizard so please politely tell me if I should go home and read up
on functions first!. I have included the popen.c file below. Thanks for any
help.

Alastair J. Small
asmall2 at mach1.wlu.ca 

-------------------------------------------------------------------------
#include <stdio.h>
#include <signal.h>
#define tst(a,b)        (*mode == 'r'? (b) : (a))

#define READ      0
#define WRITE     1

static  int     popen_pid[50];

FILE *
popen(cmd,mode)
    char    *cmd;
    char    *mode;
{
    int p[2];
    int me, you, pid;

    fflush (stdout);
    fflush (stderr);

    if(pipe(p) < 0)
	return NULL;
    me = tst(p[WRITE], p[READ]);
    you = tst(p[READ], p[WRITE]);
    if((pid = fork()) == 0)
    {
/* me and you reverse roles in child */
	close(me);
	close(tst(0, 1));
	dup(you);
	close(you);
	execl("/bin/sh", "sh", "-c", cmd, 0);
	_exit(1);
    }

    if(pid == -1)
	return NULL;
    popen_pid[me] = pid;
    close(you);

    return(fdopen(me, mode));
}

pclose(ptr)
    FILE *ptr;
{
    int f, r, (*sighup)(), (*sigint)(), (*sigquit)();
    int status;

    f = fileno(ptr);
    fclose(ptr);

    sigint  = signal(SIGINT, SIG_IGN);
    sigquit = signal(SIGQUIT, SIG_IGN);
    sighup  = signal(SIGHUP, SIG_IGN);

    while((r = wait(&status)) != popen_pid[f] && r != -1)
	    ;

    if(r == -1)
	status = -1;

    signal(SIGINT, sigint);
    signal(SIGQUIT, sigquit);
    signal(SIGHUP, sighup);

    return(status);
}



More information about the grass-user mailing list