Example #1
0
int __darwin_execvpe(const char *file, char *const argv[], char *const envp[])
{
	TRACE1(file);
	
	const char* path = findInPath(file);
	if (!path)
	{
		errno = DARWIN_ENOENT;
		return -1;
	}
	
	if (!MachO::isMachO(path))
	{
		int rv = execv(path, argv);
		errnoOut();
		return rv;
	}
	else
	{
		argv = prependLoaderPath(argv, path);
		int rv = execvpe(g_loader_path, argv, envp);
		errnoOut();
		
		delete [] argv;
		return rv;
	}
}
Example #2
0
File: samsa.c Project: dacut/juliet
/*****************************************************************
 * getExeDir(const char* argv0)
 * 
 *  returns directory of running exe
 */
char *getExeDir(const char* argv0) {

    char *last = NULL;
    
#if defined(LINUX)
    char buffer[PATH_MAX + 1];
    
    int size = readlink ("/proc/self/exe", buffer, sizeof(buffer)-2);
    
    buffer[size+1] = '\0';
#elif defined(FREEBSD)
    Dl_info info;
    char buffer[PATH_MAX + 1];
    if (dladdr( (const void*)&main, &info) == 0) {
        return NULL;
    }
    strncpy(buffer, info.dli_fname, PATH_MAX);
    buffer[PATH_MAX] = '\0';

#elif defined(WIN32)
    char buffer[512];
    DWORD dwRet = GetModuleFileName(NULL, buffer, 512);
        
    // FIXME - handle this right - it could be that 512 isn't enough
#else
    char buffer[PATH_MAX+1];
    char *rc;
    const char *exename;
    rc = strchr(argv0, '/');
    if (rc) {
        /* is an absolute or relative path so just use that */
        exename = argv0;
    } else {
        /* search in path */
       exename = findInPath(argv0);
       if (!exename) {
           return NULL;
       }
    }
    rc = realpath(exename, buffer);
    if (exename != argv0) {
        free((void*)exename);
    }
    if (!rc) {
        return NULL;
    }
#endif

    last = strrchr(buffer, PATH_SEPARATOR_CHAR);

    if (last != NULL) { 
        *last = '\0';
        return strdup(buffer);
    }
    
    return NULL;
}
Example #3
0
int __darwin_execvp(const char *file, char *const argv[])
{
	TRACE1(file);
	
	const char* path = findInPath(file);
	if (!path)
	{
		std::cout << "Path failed to be located: " << file << std::endl;
		errno = DARWIN_ENOENT;
		return -1;
	}
	
	return __darwin_execv(path, argv);
}
Example #4
0
QString findD3dCompiler(Platform platform, const QString &qtBinDir, unsigned wordSize)
{
    const QString prefix = QStringLiteral("D3Dcompiler_");
    const QString suffix = QLatin1String(windowsSharedLibrarySuffix);
    // Get the DLL from Kit 8.0 onwards
    const QString kitDir = QString::fromLocal8Bit(qgetenv("WindowsSdkDir"));
    if (!kitDir.isEmpty()) {
        QString redistDirPath = QDir::cleanPath(kitDir) + QStringLiteral("/Redist/D3D/");
        if (platform & ArmBased) {
            redistDirPath += QStringLiteral("arm");
        } else {
            redistDirPath += wordSize == 32 ? QStringLiteral("x86") : QStringLiteral("x64");
        }
        QDir redistDir(redistDirPath);
        if (redistDir.exists()) {
            const QFileInfoList files = redistDir.entryInfoList(QStringList(prefix + QLatin1Char('*') + suffix), QDir::Files);
            if (!files.isEmpty())
                return files.front().absoluteFilePath();
        }
    }
    QStringList candidateVersions;
    for (int i = 47 ; i >= 40 ; --i)
        candidateVersions.append(prefix + QString::number(i) + suffix);
    // Check the bin directory of the Qt SDK (in case it is shadowed by the
    // Windows system directory in PATH).
    foreach (const QString &candidate, candidateVersions) {
        const QFileInfo fi(qtBinDir + QLatin1Char('/') + candidate);
        if (fi.isFile())
            return fi.absoluteFilePath();
    }
    // Find the latest D3D compiler DLL in path (Windows 8.1 has d3dcompiler_47).
    if (platform & IntelBased) {
        QString errorMessage;
        unsigned detectedWordSize;
        foreach (const QString &candidate, candidateVersions) {
            const QString dll = findInPath(candidate);
            if (!dll.isEmpty()
                && readPeExecutable(dll, &errorMessage, 0, &detectedWordSize, 0)
                && detectedWordSize == wordSize) {
                return dll;
            }
        }
    }
Example #5
0
int main(int argc, char **argv)
{
	loginit(LEVEL_TRACE);
	/* parse command line */
	std::string indir;
	Argv opts;
	opts.addBoolOption("recusive,r","recursive the directory");
	opts.startGroup("Hidden",false);
	opts.addTextOption("inputdir,d","directory for scan").setOptionPostion("inputdir,d",1);
	opts.stopGroup();
	if (!opts.parse(argc,argv))
	{
		/* command options parsing error */
		opts.showHelp(std::cout);
		LOG(error)<< "Input error";
		return 1;
	}
	else
	{
		indir=opts.getTextOption("inputdir","");
	}
	if (indir.size()<1)
	{
		/* inputdir isnot specified */
		opts.showHelp(std::cout,true);
		LOG(error)<< "Directory must be specified";
		return 1;
	}
	LOG(trace)<< "Current Path:"<<bfs::current_path().generic_string();
	LOG(trace)<< "Input directory:"<<indir;

	bfs::path p(indir);
	bfs::path fullp;
	/* checek input directory */
	if (!bfs::exists(p))
	{
		LOG(error)<<"Not exists";
		return 1;
	}
	else
	{
		if (!bfs::is_directory(p))
		{
			LOG(error)<<"Not a directory";
			return 1;
		}
		else
		{
			/* bfs::absolute will remain '..' or '.' */
			fullp=bfs::canonical(p);
			LOG(trace)<<"Full path:"<<fullp.generic_string();
		}
	}

	/* list files */
	walk(fullp,item_action,opts.getBoolOption("recusive"));

	/* generate a unique filename, used for temperary file */
	std::cout<<bfs::unique_path().generic_string()<<std::endl;

	/* make dir */
	bfs::path tmpfile("temp/abc/def");
	/* path.parent_path() must exist for bfs::create_directory(path) */
	/* makedirs(path) will call create_directory() repeatly until path is created */
	makedirs(tmpfile);
	/* create a temperary file */
	tmpfile/=bfs::unique_path();
	LOG(trace)<<tmpfile.generic_string();
	std::ofstream ofs(tmpfile.generic_string());
	ofs<<"test\n";
	ofs.close();
	/* remove directory */
	bfs::remove_all("temp");
	/* other file operation:
	 * copy, copy_directory, copy_file, copy_symlink
	 *   copy will automaticall choose copy_directory/copy_file/copy_symlink
	 * remove, remove_all
	 *   remove for file, remove_all for directory
	 * rename
	 */

	std::vector<bfs::path> vec;
	findInPath("vim",{"."},vec);
	std::copy(vec.cbegin(),vec.cend(),std::ostream_iterator<bfs::path>(std::cout,"\n"));
	return 0;
}