diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml
index e3e64c9d..16269671 100644
--- a/man/mosquitto.conf.5.xml
+++ b/man/mosquitto.conf.5.xml
@@ -351,13 +351,16 @@
contain the main configuration file.
The configuration files in
are loaded in case
- insensitive alphabetical order.
+ sensitive alphabetical order, with the upper case of
+ each letter ordered before the lower case of the same
+ letter.
Given the files
b.conf,
A.conf,
01.conf,
- a.conf, and
+ a.conf,
+ B.conf, and
00.conf inside
, the config files
would be loaded in this order:
@@ -366,6 +369,7 @@
01.conf
A.conf
a.conf
+B.conf
b.conf
If this option is used multiple times, then each
diff --git a/mosquitto.conf b/mosquitto.conf
index c974eaf3..9a1ba231 100644
--- a/mosquitto.conf
+++ b/mosquitto.conf
@@ -872,10 +872,10 @@
# in the main file. This option will only be processed from the main
# configuration file. The directory specified must not contain the
# main configuration file.
-# Files within include_dir will be loaded sorted in case-insensitive
-# alphabetical order. If this option is given multiple times, all of the files
-# from the first instance will be processed before the next instance. See the
-# man page for examples.
+# Files within include_dir will be loaded sorted in case-sensitive
+# alphabetical order, with capital letters ordered first. If this option is
+# given multiple times, all of the files from the first instance will be
+# processed before the next instance. See the man page for examples.
#include_dir
# =================================================================
diff --git a/src/conf_includedir.c b/src/conf_includedir.c
index 4d99f892..b0aecf2c 100644
--- a/src/conf_includedir.c
+++ b/src/conf_includedir.c
@@ -16,6 +16,7 @@ Contributors:
#include "config.h"
+#include
#include
#include
#include
@@ -47,12 +48,33 @@ Contributors:
#include "mqtt3_protocol.h"
-#ifdef WIN32
int scmp_p(const void *p1, const void *p2)
{
- return strcasecmp(*(const char **)p1, *(const char **)p2);
+ const char *s1 = *(const char **)p1;
+ const char *s2 = *(const char **)p2;
+ int result;
+
+ while(s1[0] && s2[0]){
+ /* Sort by case insensitive part first */
+ result = toupper(s1[0]) - toupper(s2[0]);
+ if(result == 0){
+ /* Case insensitive part matched, now distinguish between case */
+ result = s1[0] - s2[0];
+ if(result != 0){
+ return result;
+ }
+ }else{
+ /* Return case insensitive match fail */
+ return result;
+ }
+ s1++;
+ s2++;
+ }
+
+ return s1[0] - s2[0];
}
+#ifdef WIN32
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{
int len;
@@ -112,10 +134,6 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
#ifndef WIN32
-int scmp_p(const void *p1, const void *p2)
-{
- return strcmp(*(const char **)p1, *(const char **)p2);
-}
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{