Example #1
0
/* getBasenameCwd: return basename in buf */
static char *
getBasenameCwd(char *buf)
{
	struct dirent *dp;
	DIR *dirp;
	ino_t inoD, inoP;

	inoD = getIno(".");
	inoP = getIno("..");

	if (inoD == -1 || inoP == -1) {
		fprintf(stderr, "failed to get inode numbers");
		return NULL;
	}

	if (inoD == inoP) {
		strcpy(buf, "/");
		return buf;
	} 
		
	dirp = opendir("..");
	if (dirp == NULL)
		errExit("opendir: ..");

	for (;;) {
		errno = 0;
		dp = readdir(dirp);
		if (dp == NULL)
			break;

		if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
			continue;

		if (dp->d_ino == inoD) {
			strcpy(buf, dp->d_name);
			return buf;
		}
	}
	return NULL;
}
Example #2
0
long* getInos(char* path, int max) {
	if(path == NULL || max <= 0 || max > getAlphaCaseCombinationNum(path)) {
		errno = EPERM;
		return NULL;
	}

	long* inos = (long *) malloc(sizeof(long) * max);
	char* fileName = strstr(path, basename(path));
	int allCombinationNum = getCaseCombinationNum(fileName);
	int i = 0;
	for(int bitmap = 0; bitmap < allCombinationNum; bitmap++) {
		if(setCombination(fileName, bitmap)) {
			long ino = getIno(path);
			if(ino == -1) {
				free(inos);
				return NULL;
			}
			inos[i++] = ino;
		}
		if(i == max)
			break;
	}
	return inos;
}