- ret = snprintf(session_name, NAME_MAX, "session=%s\n", name);
+ (void) _config_read_session_name(path, &name);
+ return name;
+}
+
+/*
+ * Write session name option to the config file.
+ * On success, returns 0;
+ * on error, returns -1.
+ */
+int config_add_session_name(const char *path, const char *name)
+{
+ int ret;
+ const char *attr = "session=";
+ /* Max name len accepted plus attribute's len and the NULL byte. */
+ char session_name[NAME_MAX + strlen(attr) + 1];
+
+ /*
+ * With GNU C < 2.1, snprintf returns -1 if the target buffer is too small;
+ * With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
+ */
+ ret = snprintf(session_name, sizeof(session_name), "%s%s\n", attr, name);