コード例 #1
0
ファイル: ServerPasswd.cpp プロジェクト: rallan9/inetfs
bool
ServerPasswd::getKeys(string_list_t& keys)
{
	map_array_t entries;
	if (getEntries(entries) && entries.size() > 0)
	{
		map_array_t::iterator it;
		for (it = entries.begin(); it != entries.end(); it++)
		{
			keys.push_back(it->second[SP_KEY].c_str() + 1);
		}
		return true;
	}
	return false;
}
コード例 #2
0
ファイル: mimedb.cpp プロジェクト: Soares/fish-shell
/**
   Try to find the specified file in any of the possible directories
   where mime files can be located.  This code is shamelessly stolen
   from xdg_run_command_on_dirs.

   \param list Full file paths will be appended to this list.
   \param f The relative filename search for the the data directories.
   \param all If zero, then stop after the first filename.
   \return The number of filenames added to the list.
*/
static int append_filenames( string_list_t &list, const char *f, int all )
{
	size_t prev_count = list.size();
	char *result;
	const char *xdg_data_home;
	const char *xdg_data_dirs;
	const char *ptr;

	xdg_data_home = getenv ("XDG_DATA_HOME");
	if (xdg_data_home)
    {
		result = file_exists( xdg_data_home, f ); 
		if (result)
		{
            list.push_back(result);
			if ( !all )
				return 1;
		}
    }
	else
    {
		const char *home;

		home = getenv ("HOME");
		if (home != NULL)
		{
			char *guessed_xdg_home;

			guessed_xdg_home = (char *)my_malloc (strlen (home) + strlen ("/.local/share") + 1);
			if( !guessed_xdg_home )
				return 0;
			
			strcpy (guessed_xdg_home, home);
			strcat (guessed_xdg_home, "/.local/share");
			result = file_exists( guessed_xdg_home, f ); 
			free (guessed_xdg_home);

			if (result)
			{
                list.push_back(result);
				if ( !all )
					return 1;
			}
		}
    }

	xdg_data_dirs = getenv ("XDG_DATA_DIRS");
	if (xdg_data_dirs == NULL)
		xdg_data_dirs = "/usr/local/share:/usr/share";

	ptr = xdg_data_dirs;

	while (*ptr != '\000')
    {
		const char *end_ptr;
		char *dir;
		int len;

		end_ptr = ptr;
		while (*end_ptr != ':' && *end_ptr != '\000')
			end_ptr ++;

		if (end_ptr == ptr)
		{
			ptr++;
			continue;
		}

        len = end_ptr - ptr;
		dir = (char *)my_malloc (len + 1);
		if( !dir )
			return 0;
		
		strncpy (dir, ptr, len);
		dir[len] = '\0';
		result = file_exists( dir, f ); 
		
		free (dir);

		if (result)
		{
            list.push_back(result);
			if ( !all ) {
				return 1;
			}
		}

		ptr = end_ptr;
    }
	return list.size() - prev_count;
}