+
+static int
+compare_string_pointers(const void *a_, const void *b_)
+{
+ const char *const *a = a_;
+ const char *const *b = b_;
+
+ return strcmp(*a, *b);
+}
+
+/* Returns a null-terminated array of pointers to the strings in 'set', sorted
+ * alphabetically. The caller must free the returned array when it is no
+ * longer needed, but the strings in the array belong to 'set' and thus must
+ * not be modified or freed. */
+const char **
+sset_sort(const struct sset *set)
+{
+ size_t n = sset_count(set);
+ const char **array;
+ const char *s;
+ size_t i;
+
+ array = xmalloc(sizeof *array * (n + 1));
+ i = 0;
+ SSET_FOR_EACH (s, set) {
+ array[i++] = s;
+ }
+ ovs_assert(i == n);
+ array[n] = NULL;
+
+ qsort(array, n, sizeof *array, compare_string_pointers);
+
+ return array;
+}