+ return n_segments;
+}
+\f
+/* Given the name of an encoding, returns the codepage number to use in the
+ 'character_code' member of the machine integer info record for writing a
+ system file. */
+int
+sys_get_codepage_from_encoding (const char *name)
+{
+ const struct sys_encoding *e;
+
+ for (e = sys_codepage_name_to_number; e->name != NULL; e++)
+ if (!c_strcasecmp (name, e->name))
+ return e->number;
+
+ return 0;
+}
+
+/* Given a codepage number from the 'character_code' member of the machine
+ integer info record in a system file, returns a corresponding encoding name.
+ Most encodings have multiple aliases; the one returned is the one that would
+ be used in the character encoding record. */
+const char *
+sys_get_encoding_from_codepage (int codepage)
+{
+ const struct sys_encoding *e;
+
+ for (e = sys_codepage_number_to_name; e->name != NULL; e++)
+ if (codepage == e->number)
+ return e->name;
+
+ return NULL;