示例#1
0
int main( int argc , char * argv[] )  {
    std::thread pth1(print_block,50,'*');
    std::thread pth2(print_block,50,'$');

    pth1.join();
    pth2.join();
    return EXIT_SUCCESS;
}
示例#2
0
	// creates all intermediate dirs as necessary 
	// returns 0 on success.
	static int createDir(const char *odir, char sep = '/')
	{
		/*
		foo/bar
		./foo/bar
		/foo/bar
		c:\foo/bar
		\\host\foo\bar
		*/

		// create working copy of path
		char *dir = strdup(odir);
		if(!dir)
			return 1;

#ifdef WIN32
		// convert all backslashes to forward slashes
		char *tmp = dir;
		while(*tmp)
		{
			if(*tmp == '\\')
				*tmp = '/';
			tmp++;
		}
		// except in th case of "C:\foobar" and "\\host\foo\bar"
		if(dir[0] == '/' && dir[1] == '/')
			dir[0] = dir[1] = '\\';
		if(dir[1] == ':' && dir[2] == '/')
			dir[2] = '\\';
#endif

#ifdef WIN32
		char *cwd = _getcwd(0, 1);
#else
		char *cwd = getcwd(0, 1);
#endif

		int r = 0;
		Args pa(dir, '/');
		for(int i = 0; i < pa.length(); i++)
		{
			const char *pth = pa.get(i);
#ifndef WIN32
			// can't remember why i had to do do this on linux/mac, but it win32 pukes on it
			S pth2(pth,"/");
			pth = pth2.chars;
#endif
			if(!isDir(pth))
			{
#ifdef WIN32
				r = _mkdir(pth);
#else
				r = mkdir(pth, 0700);
#endif
				if(r)
				{
					break;
				}
			}
#ifdef WIN32
			r = _chdir(pth);
#else
			r = chdir(pth);
#endif
			if(r)
			{
				break;
			}
		}
#ifdef WIN32
		_chdir(cwd);
#else
		chdir(cwd);
#endif
		free(cwd);
		free(dir);
		return r;
	}