Esempio n. 1
0
int __darwin_stat64(const char* path, struct __darwin_stat64* mac)
{
	TRACE2(path, mac);
	struct stat64 linux_buf;
	
	if (Darling::MachOMgr::instance()->hasSysRoot())
	{
		const char* prefixed;
		std::string lpath = Darling::MachOMgr::instance()->sysRoot();
		
		lpath += '/';
		lpath += path;
		
		prefixed = translatePathCI(lpath.c_str());
		if (::access(prefixed, F_OK) == 0)
			path = prefixed;
		else
			path = translatePathCI(path);
	}
	else
		path = translatePathCI(path);
	
	int ret = stat64(translatePathCI(path), &linux_buf);
	if (ret == -1)
		errnoOut();
	
	convertStat64(&linux_buf, mac);
	return ret;
}
Esempio n. 2
0
static const char* findInPath(const char* file)
{
	static __thread char buffer[DARWIN_MAXPATHLEN];
	
	if (*file == '/')
		return file;
	
	if (strchr(file, '/') != 0)
	{
		// No PATH resolution, only fix the case
		strcpy(buffer, file);
		translatePathCI(buffer);
		return buffer;
	}
	
	const char* path = getenv("PATH");
	if (!path)
	{
		// Get the default path.
		size_t len = confstr(_CS_PATH, 0, 0);
		char* buf = reinterpret_cast<char*>( alloca(len + 1) );
		buf[0] = ':';
		
		confstr(_CS_PATH, buf + 1, len);
		
		path = buf;
	}

	const char* p = path;
	do
	{
		const char* end = strchrnul(p, ':');
		size_t len = end-p;
		memcpy(buffer, p, len);
		if (buffer[len-1] != '/')
			buffer[len++] = '/';
		
		strcpy(buffer+len, file);
		
		translatePathCI(buffer);
		
		if (::access(buffer, X_OK) == 0)
			return buffer;
	}
	while (*p++);

	return 0;
}
Esempio n. 3
0
char* translatePathCI(const char* path)
{
	//TRACE1(path);
	static char buf[DARWIN_MAXPATHLEN];
	if (path != &buf[0])
		strcpy(buf, path);
	translatePathCI(buf);
	return buf;
	//return strdup(path);
}
Esempio n. 4
0
__darwin_FILE* __darwin_fopen(const char* path, const char* mode)
{
	TRACE2(path, mode);
	if (!strchr(mode, 'w') && g_sysroot[0])
	{
		const char* prefixed;
		std::string lpath = g_sysroot;
		lpath += '/';
		lpath += path;
		
		prefixed = translatePathCI(lpath.c_str());
		if (::access(prefixed, F_OK) == 0)
			path = prefixed;
		else
			path = translatePathCI(path);
	}
	else
		path = translatePathCI(path);
	
	if (!strchr(mode, 'x'))
		return InitDarwinFILE(fopen(path, mode));
	else // DARWIN_EXTSN
	{
		std::string m = mode;
		size_t pos = m.find('x');
		m.erase(pos, 1);
		
		int flags = O_CREAT | O_EXCL;
		if (m.find('a') != std::string::npos)
			flags |= O_APPEND;
		if (m.find('+') != std::string::npos)
			flags |= O_RDWR;
		else
			flags |= O_WRONLY;
		
		int fd = ::open(path, flags, 0666);
		if (fd == -1)
			return 0;
		else
			return __darwin_fdopen(fd, m.c_str());
	}
}
Esempio n. 5
0
int main(int argc, char** argv)
{
	if (argc != 2)
		return 1;
	
	char buf[PATH_MAX];
	strcpy(buf, argv[1]);
	translatePathCI(buf);
	
	std::cout << buf << std::endl;
}
Esempio n. 6
0
int __darwin_stat(const char* path, struct __darwin_stat* mac)
{
  TRACE2(path, mac);
  struct stat64 linux_buf;
  int ret = stat64(translatePathCI(path), &linux_buf);
  if (ret == -1)
		errnoOut();
  
  convertStat(&linux_buf, mac);
  return ret;
}
Esempio n. 7
0
int __darwin_posix_spawn(pid_t* pid, const char* path, const __darwin_posix_spawn_file_actions_t* file_actions, const __darwin_posix_spawnattr_t* attrp,
		        char* const argv[], char* const envp[])
{
	TRACE6(pid, path, file_actions, attrp, argv, envp);
	char* const* argv_copy = nullptr;
	int err;

	path = translatePathCI(path);

	if (MachO::isMachO(path))
		argv = argv_copy = Darling::prependLoaderPath(argv, path);	

	err = AutoErrnoPosix(posix_spawn, pid, path, file_actions->native, attrp->native, argv, envp);

	delete [] argv_copy;
	return err;
}
Esempio n. 8
0
int __darwin_execv(const char *path, char *const argv[])
{
	TRACE1(path);
	path = translatePathCI(path);
	
	if (!MachO::isMachO(path))
	{
		int rv = execv(path, argv);
		errnoOut();
		return rv;
	}
	else
	{
		argv = prependLoaderPath(argv, path);
		int rv = execvp(g_loader_path, argv);
		
		std::cout << "Executing with loader at " << g_loader_path << std::endl;
		
		errnoOut();
		
		delete [] argv;
		return rv;
	}
}
Esempio n. 9
0
int __darwin_execv(const char *path, char *const argv[])
{
	TRACE1(path);
	path = translatePathCI(path);
	
	if (!MachO::isMachO(path))
	{
		int rv = execv(path, argv);
		errnoOut();
		return rv;
	}
	else
	{
		argv = Darling::prependLoaderPath(argv, path);
		int rv = execvp(g_dyld_path, argv); // TODO: change to execv?
		
		LOG << "Executing with loader at " << g_dyld_path << std::endl;
		
		errnoOut();
		
		delete [] argv;
		return rv;
	}
}
Esempio n. 10
0
int __darwin_posix_spawn_file_actions_addopen(__darwin_posix_spawn_file_actions_t* file_actions, int filedes, const char* path, int oflag, mode_t mode)
{
	return AutoErrnoPosix(posix_spawn_file_actions_addopen, file_actions->native, filedes, translatePathCI(path), Darling::openflagsDarwinToNative(oflag), mode);
}
Esempio n. 11
0
__darwin_FILE* __darwin_freopen(const char* path, const char* mode, __darwin_FILE* fp)
{
	return InitDarwinFILE(freopen(translatePathCI(path), mode, fp->linux_fp));
}
Esempio n. 12
0
int __darwin_statfs64(const char* path, struct __darwin_statfs64* buf)
{
	return __darwin_statfsGen(translatePathCI(path), buf);
}