+/*
+ * In the non-POSIX case, we transform each character into a string of
+ * characters representing the character's priority. Since char is usually
+ * signed, we are limited by 7 bits per byte. To avoid zero, we need to add
+ * XFRM_OFFSET, so we can't use a full 7 bits. For simplicity, we choose 6
+ * bits per byte. We choose 4 bytes per character as a good compromise
+ * between maximum coverage and minimum size. This gives 24 bits, or 16M
+ * priorities. So we choose COLLATE_MAX_PRIORITY to be (2^24 - 1). This
+ * this can be increased if more is needed.
+ */
+
+#define XFRM_BYTES 4
+#define XFRM_OFFSET ('0') /* make all printable characters */
+#define XFRM_SHIFT 6
+#define XFRM_MASK ((1 << XFRM_SHIFT) - 1)
+
+static void
+xfrm(unsigned char *p, int pri)
+{
+
+ p[3] = (pri & XFRM_MASK) + XFRM_OFFSET;
+ pri >>= XFRM_SHIFT;
+ p[2] = (pri & XFRM_MASK) + XFRM_OFFSET;
+ pri >>= XFRM_SHIFT;
+ p[1] = (pri & XFRM_MASK) + XFRM_OFFSET;
+ pri >>= XFRM_SHIFT;
+ p[0] = (pri & XFRM_MASK) + XFRM_OFFSET;
+}
+