diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c
index 3c8f1e18d327a9468fcb4514c8841f99b44a279b..bac0e4e8ffec5998bb276968b4c0615e4c0ba9c6 100644
--- a/src/xpdev/ini_file.c
+++ b/src/xpdev/ini_file.c
@@ -1728,6 +1728,7 @@ int iniGetInteger(str_list_t list, const char* section, const char* key, int def
 	return(parseInteger(vp));
 }
 
+/* Returns the default value if key value is out of range */
 int iniGetIntInRange(str_list_t list, const char* section, const char* key, int min, int deflt, int max)
 {
 	char*	vp=NULL;
@@ -1744,6 +1745,24 @@ int iniGetIntInRange(str_list_t list, const char* section, const char* key, int
 	return result;
 }
 
+/* Returns the min or max value if key value is out of range */
+int iniGetClampedInt(str_list_t list, const char* section, const char* key, int min, int deflt, int max)
+{
+	char*	vp=NULL;
+	int		result;
+
+	get_value(list, section, key, NULL, &vp, /* literals_supported: */FALSE);
+
+	if(vp==NULL || *vp==0)	/* blank value or missing key */
+		return deflt;
+
+	result = parseInteger(vp);
+	if(result < min)
+		return min;
+	if(result > max)
+		return max;
+	return result;
+}
 
 uint iniGetUInteger(str_list_t list, const char* section, const char* key, uint deflt)
 {
diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h
index ebf3ba6f59eb1269cb1f08549d5edd1abcdc2669..7377d40f1e3d16df3c989190f892d8aaab71e9b7 100644
--- a/src/xpdev/ini_file.h
+++ b/src/xpdev/ini_file.h
@@ -158,6 +158,8 @@ DLLEXPORT int 			iniGetInteger(str_list_t, const char* section, const char* key
 							,int deflt);
 DLLEXPORT int 			iniGetIntInRange(str_list_t, const char* section, const char* key
 							,int min, int deflt, int max);
+DLLEXPORT int 			iniGetClampedInt(str_list_t, const char* section, const char* key
+							,int min, int deflt, int max);
 DLLEXPORT uint 			iniGetUInteger(str_list_t, const char* section, const char* key
 							,uint deflt);
 DLLEXPORT short 		iniGetShortInt(str_list_t, const char* section, const char* key