aboutsummaryrefslogtreecommitdiff
path: root/src/common/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/string.c')
-rw-r--r--src/common/string.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/string.c b/src/common/string.c
index b01a56ceaa5..c9b8482cb06 100644
--- a/src/common/string.c
+++ b/src/common/string.c
@@ -90,3 +90,25 @@ pg_clean_ascii(char *str)
*p = '?';
}
}
+
+
+/*
+ * pg_strip_crlf -- Remove any trailing newline and carriage return
+ *
+ * Removes any trailing newline and carriage return characters (\r on
+ * Windows) in the input string, zero-terminating it.
+ *
+ * The passed in string must be zero-terminated. This function returns
+ * the new length of the string.
+ */
+int
+pg_strip_crlf(char *str)
+{
+ int len = strlen(str);
+
+ while (len > 0 && (str[len - 1] == '\n' ||
+ str[len - 1] == '\r'))
+ str[--len] = '\0';
+
+ return len;
+}