Exemplo n.º 1
0
int repo_open(repo* rep, const char* mountpt, const char* repo) {
	int err = 0;
	rep->mountpt = strdup(mountpt);
	if (!rep->mountpt) {
		err = -ENOMEM;
		goto err;
	}
	rep->repo = strdup(repo);
	if (!rep->repo) {
		err = -ENOMEM;
		goto err;
	}

	stat_t stbuf;
	err = gen_stat(rep->mountpt, &stbuf);
	if (err) {
		goto err;
	}

	err = gen_stat(rep->repo, &stbuf);
	if (err) {
		goto err;
	}

	err = setmaxid(rep);
	if (err) {
		goto err;
	}

	return 0;
err:
	repo_destroy(rep);
	return err;
}
Exemplo n.º 2
0
int getmaxid (char *fname)
{

	FILE *f;
	f = fopen (fname, "r");
	//printf ("*** ZVM Try to open %s device.\n", fname);
	if (!f)
	{
		printf ("*** ZVM Warning. Error open file %s with maxID document. MaxID set to 1.\n", fname);
		setmaxid(MAXID_DEV_NAME_OUT, 1);
		return 1;
	}
	char maxidchar[20];
	int maxid;
	maxid = 0;
	int i;
	i = 0;
	int c;
	while ((c=(char)getc (f)) != EOF)
	{
		//printf (" *** %c\n", c);
		if (isdigit(c))
			maxidchar[i++] = c;
	}
	maxidchar [i] = '\0';
	//printf ("*** ZVM 1. maxID  = %s\n", maxidchar);
	maxid = atoi (maxidchar);
	fclose (f);
	//pritnf ("*** ZVM 2. maxID =  %d\n", maxid);
	if (maxid <= 0)
	{
		maxid = 1;
		printf ("*** ZVM Wrong readed MaxID form %s. maxID set to 1.\n", fname);
		setmaxid (MAXID_DEV_NAME_OUT ,1);
	}
	printf ("*** ZVM maxid = %d\n", maxid);
	return maxid;
}