Portability to BeOS.
[gnulib.git] / lib / readline.c
index 197262a..52f002e 100644 (file)
@@ -1,5 +1,5 @@
 /* readline.c --- Simple implementation of readline.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    Written by Simon Josefsson
 
    This program is free software; you can redistribute it and/or modify
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
 #endif
 
-/* This module is intended to be used when the application only need
+/* This module is intended to be used when the application only needs
    the readline interface.  If you need more functions from the
    readline library, it is recommended to require the readline library
    (or improve this module) rather than #if-protect part of your
@@ -33,6 +33,7 @@
 #include "readline.h"
 
 #include <stdio.h>
+#include <string.h>
 #include <getline.h>
 
 char *
@@ -47,5 +48,9 @@ readline (const char *prompt)
   if (getline (&out, &size, stdin) < 0)
     return NULL;
 
+  while (*out && (out[strlen (out) - 1] == '\r'
+                 || out[strlen (out) - 1] == '\n'))
+    out[strlen (out) - 1] = '\0';
+
   return out;
 }