Re: [hatari-devel] SDL GUI file and directory selection

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi Andreas,

I added the changes you suggested.

On 15.10.2022 16.21, Andreas Grabher wrote:
Path is always valid (or '\0' in case of /somefile) after File_MakeValidPathName(). So SDLGui_DirSelect() can be further simplified like this:

bool SDLGui_DirSelect(char *dlgname, char *confname, int maxlen)
{
	char *selname;

	selname = SDLGui_FileSelect("Choose a folder", confname, NULL, NULL, false);
	if (selname)
	{
		File_MakeValidPathName(selname);
		strncpy(confname, selname, FILENAME_MAX);

Either you:
1. trust selname to fit into confname, and use use strcpy(), but on all OSes FILENAME_MAX might not be enough for that
* use strncpy() *and* zero terminate the string, or
* use Str_Copy()


=> I opted for last, for consistency with the other fsel function.


		File_ShrinkName(dlgname, selname, maxlen);
		free(selname);
		return true;
	}
	return false;
}
....
I also suggest to rename SdlGui_DirSelect() to SDLGui_DirSelect() for matching the naming scheme of the other functions.

Added "Conf" to function name for consistency.


	- Eero




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/