示例#1
0
void* xmalloc(size_t size)
{
        void *ret = malloc(size);
        if (!ret && !size)
                ret = malloc(1);
        if (!ret)
                fatal_system_error("Out of memory, malloc failed");
        return ret;
}
示例#2
0
void* xrealloc(void *ptr, size_t size)
{
        void *ret = realloc(ptr, size);
        if (!ret && !size)
                ret = realloc(ptr, 1);
        if (!ret)
                fatal_system_error("Out of memory, realloc failed");
        return ret;
}
示例#3
0
/* Convert relative RCS filename to absolute path */
static char const * getfullRCSname(void)
{
	char *wdbuf = NULL;
	int wdbuflen = 0;

	size_t dlen;

	char const *r;
	char* d;

	if (Gfilename[0] == '/')
		return Gfilename;

	/* If we've already calculated the absolute path, return it */
	if (Gabspath)
		return Gabspath;

	/* Get working directory and strip any trailing slashes */
	wdbuflen = _POSIX_PATH_MAX + 1;
	wdbuf = xmalloc(wdbuflen);
	while (!getcwd(wdbuf, wdbuflen)) {
		if (errno == ERANGE)
			xrealloc(wdbuf, wdbuflen<<1);
		else	fatal_system_error("getcwd");
	}

	/* Trim off trailing slashes */
	dlen = strlen(wdbuf);
	while (dlen && wdbuf[dlen-1] == '/')
		--dlen;
	wdbuf[dlen] = 0;

	/* Ignore leading `./'s in Gfilename. */
	for (r = Gfilename;  r[0]=='.' && r[1] == '/';  r += 2)
		while (r[2] == '/')
			r++;

	/* Build full pathname.  */
	Gabspath = d = xmalloc(dlen + strlen(r) + 2);
	memcpy(d, wdbuf, dlen);
	d += dlen;
	*d++ = '/';
	strcpy(d, r);
	free(wdbuf);

	return Gabspath;
}
示例#4
0
static void
rev_list_file(rev_file *file, analysis_t *out, cvs_master *cm, rev_master *rm) 
{
    struct stat	buf;
    yyscan_t scanner;
    FILE *in;
    cvs_file *cvs;

    in = fopen(file->name, "r");
    if (!in) {
	perror(file->name);
	++err;
	return;
    }
    if (stat(file->name, &buf) == -1) {
	fatal_system_error("%s", file->name);
    }

    cvs = xcalloc(1, sizeof(cvs_file), __func__);
    cvs->gen.master_name = file->name;
    cvs->gen.expand = EXPANDUNSPEC;
    cvs->export_name = file->rectified;
    cvs->mode = buf.st_mode;
    cvs->verbose = verbose;

    yylex_init(&scanner);
    yyset_in(in, scanner);
    yyparse(scanner, cvs);
    yylex_destroy(scanner);

    fclose(in);
    cvs_master_digest(cvs, cm, rm);
    out->total_revisions = cvs->nversions;
    out->skew_vulnerable = cvs->skew_vulnerable;
    out->generator = cvs->gen;
    cvs_file_free(cvs);
}