Quizzer

 view release on metacpan or  search on metacpan

exercises/compile-tcsh/tcsh-6.10.00/tc.func.c  view on Meta::CPAN

#ifdef convex
			stderror(ERR_SYSTEM, progname, strerror(errno));
#endif /* convex */
			goto eof;
		    }
		    for (i = 0; i < n; i++)
  			buf[i] = (Char) tbuf[i];
		    p = buf;
		}
		n--;
		if ((*lp++ = *p++) == '\n') {
		    lp[-1] = '\0';
		    break;
		}
	    }
	    for (lp = line; *lp; lp++) {
		if (isspc(*lp)) {
		    *lp++ = '\0';
		    while (isspc(*lp))
			lp++;
		    vec = (Char **) xmalloc((size_t)
					    (2 * sizeof(Char **)));
		    vec[0] = Strsave(lp);
		    vec[1] = NULL;
		    setq(strip(line), vec, &aliases, VAR_READWRITE);
		    break;
		}
	    }
	}
    }

eof:
    (void) close(fd);
    tw_cmd_free();
    if (gargv)
	blkfree(gargv), gargv = 0;
    resexit(oldexit);
}
#endif /* OBSOLETE */


/*
 * set the shell-level var to 1 or apply change to it.
 */
void
shlvl(val)
    int val;
{
    char *cp;

    if ((cp = getenv("SHLVL")) != NULL) {

	if (loginsh)
	    val = 1;
	else
	    val += atoi(cp);

	if (val <= 0) {
	    if (adrof(STRshlvl) != NULL)
		unsetv(STRshlvl);
	    Unsetenv(STRKSHLVL);
	}
	else {
	    Char    buff[BUFSIZE];

	    (void) Itoa(val, buff, 0, 0);
	    set(STRshlvl, Strsave(buff), VAR_READWRITE);
	    tsetenv(STRKSHLVL, buff);
	}
    }
    else {
	set(STRshlvl, SAVE("1"), VAR_READWRITE);
	tsetenv(STRKSHLVL, str2short("1"));
    }
}


/* fixio():
 *	Try to recover from a read error
 */
int
fixio(fd, e)
    int fd, e;
{
    switch (e) {
    case -1:	/* Make sure that the code is reachable */

#ifdef EWOULDBLOCK
    case EWOULDBLOCK:
# define FDRETRY
#endif /* EWOULDBLOCK */

#if defined(POSIX) && defined(EAGAIN)
# if !defined(EWOULDBLOCK) || EWOULDBLOCK != EAGAIN
    case EAGAIN:
#  define FDRETRY
# endif /* !EWOULDBLOCK || EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */

	e = 0;
#ifdef FDRETRY
# ifdef F_SETFL
/*
 * Great! we have on suns 3 flavors and 5 names...
 * I hope that will cover everything.
 * I added some more defines... many systems have different defines.
 * Rather than dealing with getting the right includes, we'll just
 * cover all the known possibilities here.  -- sterling@netcom.com
 */
#  ifndef O_NONBLOCK
#   define O_NONBLOCK 0
#  endif /* O_NONBLOCK */
#  ifndef O_NDELAY
#   define O_NDELAY 0
#  endif /* O_NDELAY */
#  ifndef FNBIO
#   define FNBIO 0
#  endif /* FNBIO */
#  ifndef _FNBIO
#   define _FNBIO 0
#  endif /* _FNBIO */
#  ifndef FNONBIO
#   define FNONBIO 0
#  endif /* FNONBIO */
#  ifndef FNONBLOCK
#   define FNONBLOCK 0
#  endif /* FNONBLOCK */
#  ifndef _FNONBLOCK
#   define _FNONBLOCK 0
#  endif /* _FNONBLOCK */
#  ifndef FNDELAY
#   define FNDELAY 0
#  endif /* FNDELAY */

exercises/compile-tcsh/tcsh-6.10.00/tc.func.c  view on Meta::CPAN

		    char *s, *domain;
		    char dbuf[MAXHOSTNAMELEN], cbuf[MAXHOSTNAMELEN];
		    struct addrinfo hints, *res = NULL;

		    memset(&hints, 0, sizeof(hints));
		    hints.ai_family = PF_UNSPEC;
		    hints.ai_socktype = SOCK_STREAM;
		    hints.ai_flags = AI_PASSIVE | AI_CANONNAME;
#if defined(UTHOST) && !defined(HAVENOUTMP)
		    if (strlen(name) < utmphostsize())
#else
		    if (name != NULL)
#endif
		    {
			if (getaddrinfo(name, NULL, &hints, &res) != 0)
			    res = NULL;
		    } else if (gethostname(dbuf, sizeof(dbuf) - 1) == 0 &&
			       (domain = strchr(dbuf, '.')) != NULL) {
			for (s = strchr(name, '.');
			     s != NULL; s = strchr(s + 1, '.')) {
			    if (*(s + 1) != '\0' &&
				(ptr = strstr(domain, s)) != NULL) {
				len = s - name;
				if (len + strlen(ptr) >= sizeof(cbuf))
				    break;
				strncpy(cbuf, name, len);
				strcpy(cbuf + len, ptr);
				if (getaddrinfo(cbuf, NULL, &hints, &res) != 0)
				    res = NULL;
				break;
			    }
			}
		    }
		    if (res != NULL) {
			if (res->ai_canonname != NULL) {
			    strncpy(hbuf, res->ai_canonname, sizeof(hbuf));
			    host = hbuf;
			}
			freeaddrinfo(res);
		    }
#else
		    if ((hp = gethostbyname(name)) == NULL) {
			/* Try again eliminating the trailing domain */
			if ((ptr = strchr(name, '.')) != NULL) {
			    *ptr = '\0';
			    if ((hp = gethostbyname(name)) != NULL)
				host = hp->h_name;
			    *ptr = '.';
			}
		    }
		    else
			host = hp->h_name;
#endif
		}
	    }
	}
    }
#endif

    if (host)
	tsetenv(STRREMOTEHOST, str2short(host));

#if defined(UTHOST) && !defined(HAVENOUTMP)
    if (sptr)
	*sptr = ':';
#endif
}


/*
 * From: <lesv@ppvku.ericsson.se> (Lennart Svensson)
 */
void 
remotehost()
{
    /* Don't get stuck if the resolver does not work! */
    signalfun_t osig = sigset(SIGALRM, palarm);

    jmp_buf_t osetexit;
    getexit(osetexit);

    (void) alarm(2);

    if (setexit() == 0)
	getremotehost();

    resexit(osetexit);

    (void) alarm(0);
    (void) sigset(SIGALRM, osig);

#ifdef YPBUGS
    /* From: casper@fwi.uva.nl (Casper H.S. Dik), for Solaris 2.3 */
    fix_yp_bugs();
#endif /* YPBUGS */

}
#endif /* REMOTEHOST */



( run in 1.912 second using v1.01-cache-2.11-cpan-5511b514fd6 )