rem: errno = EINVAL;
context: expandPath (char *dest, size_t len, const char *src){	char *destend;	char *destptr;#define CHECKLEN(n) \		if (destptr + (n) >= destend) \		{ \			errno = ENAMETOOLONG; \			return -1; \		} \		else \			(void) 0	destptr = dest;	destend = dest + len;	if (src[0] == '~')	{		const char *home;		size_t homelen;				if (src[1] != '/')		{			errno = EINVAL;			return -1;		}		home = getHomeDir ();		if (home == NULL)		{			errno = ENOENT;			return -1;		}		homelen = strlen (home);				CHECKLEN (homelen);		memcpy (destptr, home, homelen);		destptr += homelen;		src++;  /* skip the ~ */	}	while (*src != '\0')	{		switch (*src)		{#ifdef WIN32			case '%':			{				/* Environment variable substitution in Windows */				const char *end;     // end of env var name in src				const char *envVar;				char *envName;				size_t envNameLen, envVarLen;								src++;				end = strchr (src, '%');				if (end == NULL)				{					errno = EINVAL;					return -1;				}								envNameLen = end - src;				envName = HMalloc (envNameLen + 1);				memcpy (envName, src, envNameLen + 1);				envName[envNameLen] = '\0';				envVar = getenv (envName);				HFree (envName);				if (envVar == NULL)				{#ifdef APPDATA_FALLBACK					if (strncmp (src, "APPDATA", envNameLen) != 0)					{						// Substitute an empty string						src = end + 1;						break;					}					// fallback for when the APPDATA env var is not set					// Using SHGetFolderPath or SHGetSpecialFolderPath					// is problematic (not everywhere available).					fprintf(stderr, "Warning: %%APPDATA%% is not set. "							"Falling back to \"%%USERPROFILE%%\\Application "							"Data\"\n");					envVar = getenv ("USERPROFILE");					if (envVar != NULL)					{#define APPDATA_STRING "\\Application Data"						envVarLen = strlen (envVar);						CHECKLEN (envVarLen + sizeof (APPDATA_STRING) - 1);						strcpy (destptr, envVar);						destptr += envVarLen;						strcpy (destptr, APPDATA_STRING);						destptr += sizeof (APPDATA_STRING) - 1;						src = end + 1;						break;					}										// fallback to "../userdata"					fprintf(stderr, "Warning: %%USERPROFILE%% is not set. "							"Falling back to \"..\\userdata\" for %%APPDATA%%"							"\n");#define APPDATA_FALLBACK_STRING "..\\userdata"					CHECKLEN (sizeof (APPDATA_FALLBACK_STRING) - 1);					strcpy (destptr, APPDATA_FALLBACK_STRING);					destptr += sizeof (APPDATA_FALLBACK_STRING) - 1;					src = end + 1;					break;#else  /* !defined (APPDATA_FALLBACK) */					// Substitute an empty string					src = end + 1;					break;#endif  /* APPDATA_FALLBACK */				}				envVarLen = strlen (envVar);				CHECKLEN (envVarLen);				strcpy (destptr, envVar);				destptr += envVarLen;				src = end + 1;				break;			}#endif#if 0			case '$':				/* Environment variable substitution for Unix */				// not implemented				// Should accept both $BLA_123 and ${BLA}				break;#endif			default:				CHECKLEN(1);				*(destptr++) = *(src++);				break;		}	}	*destptr = '\0';	#ifdef WIN32	/* Replacing backslashes in path by slashes in Windows. */	destptr = dest;	while (*destptr != '\0')	{		if (*destptr == '\\')			*destptr = '/';		destptr++;	}#endif	return 0;}