示例#1
0
char *
tempnam(const char *dir, const char *pfx)
{
	int sverrno;
	char *name, *f;
	const char *tmp;

	if (!(name = malloc((size_t)MAXPATHLEN)))
		return NULL;

	if (!pfx)
		pfx = "tmp.";

	if ((tmp = getenv("TMPDIR")) != NULL &&
	    (f = gentemp(name, (size_t)MAXPATHLEN, tmp, pfx)) != NULL)
		return f;

	if (dir != NULL &&
	    (f = gentemp(name, (size_t)MAXPATHLEN, dir, pfx)) != NULL)
		return f;

	if ((f = gentemp(name, (size_t)MAXPATHLEN, P_tmpdir, pfx)) != NULL)
		return f;

	if ((f = gentemp(name, (size_t)MAXPATHLEN, _PATH_TMP, pfx)) != NULL)
		return f;

	sverrno = errno;
	free(name);
	errno = sverrno;
	return NULL;
}
示例#2
0
文件: flatten.c 项目: oridb/mc
static Node *
temp(Flattenctx *flatten, Node *e)
{
	Node *t;

	assert(e->type == Nexpr);
	t = gentemp(e->loc, e->expr.type, NULL);
	return t;
}
示例#3
0
文件: simp.c 项目: Zhouxiaoqing/mc
static Node *temp(Simp *simp, Node *e)
{
    Node *t, *dcl;

    assert(e->type == Nexpr);
    t = gentemp(simp, e, e->expr.type, &dcl);
    if (stacknode(e))
        declarelocal(simp, dcl);
    return t;
}
示例#4
0
文件: simp.c 项目: Zhouxiaoqing/mc
/* pat; seq; 
 *      body;;
 *
 * =>
 *      .pseudo = seqinit
 *      jmp :cond
 *      :body
 *           ...body...
 *      :step
 *           ...step...
 *      :cond
 *           ...cond...
 *           cjmp (cond) :match :end
 *      :match
 *           ...match...
 *           cjmp (match) :body :step
 *      :end
 */
static void simpiter(Simp *s, Node *n)
{
    Node *lbody, *lstep, *lcond, *lmatch, *lend;
    Node *idx, *len, *dcl, *seq, *val, *done;
    Node *zero;

    lbody = genlbl();
    lstep = genlbl();
    lcond = genlbl();
    lmatch = genlbl();
    lend = genlbl();

    lappend(&s->loopstep, &s->nloopstep, lstep);
    lappend(&s->loopexit, &s->nloopexit, lend);

    zero = mkintlit(n->line, 0);
    zero->expr.type = tyintptr;

    seq = rval(s, n->iterstmt.seq, NULL);
    idx = gentemp(s, n, tyintptr, &dcl);
    declarelocal(s, dcl);

    /* setup */
    append(s, assign(s, idx, zero));
    jmp(s, lcond);
    simp(s, lbody);
    /* body */
    simp(s, n->iterstmt.body);
    /* step */
    simp(s, lstep);
    simp(s, assign(s, idx, addk(idx, 1)));
    /* condition */
    simp(s, lcond);
    len = seqlen(s, seq, tyintptr);
    done = mkexpr(n->line, Olt, idx, len, NULL);
    cjmp(s, done, lmatch, lend);
    simp(s, lmatch);
    val = load(idxaddr(s, seq, idx));
    umatch(s, n->iterstmt.elt, val, val->expr.type, lbody, lstep);
    simp(s, lend);

    s->nloopstep--;
    s->nloopexit--;
}