diff options
Diffstat (limited to 'sys/lib')
-rw-r--r-- | sys/lib/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/lib/libsa/getfile.c | 4 | ||||
-rw-r--r-- | sys/lib/libsa/getln.c (renamed from sys/lib/libsa/gets.c) | 26 | ||||
-rw-r--r-- | sys/lib/libsa/stand.h | 4 |
4 files changed, 22 insertions, 16 deletions
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile index 0324e76765f..5e722d49328 100644 --- a/sys/lib/libsa/Makefile +++ b/sys/lib/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.27 2015/09/18 13:42:31 miod Exp $ +# $OpenBSD: Makefile,v 1.28 2015/11/16 19:33:52 miod Exp $ # $NetBSD: Makefile,v 1.13 1996/10/02 16:19:51 ws Exp $ LIB= sa @@ -24,7 +24,7 @@ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD .endif # stand routines -SRCS+= alloc.c memcpy.c exit.c getfile.c getchar.c gets.c globals.c \ +SRCS+= alloc.c memcpy.c exit.c getfile.c getchar.c getln.c globals.c \ printf.c putchar.c snprintf.c strerror.c strcmp.c memset.c memcmp.c \ strncpy.c strncmp.c strchr.c diff --git a/sys/lib/libsa/getfile.c b/sys/lib/libsa/getfile.c index f6131d1e4f1..be134430d4c 100644 --- a/sys/lib/libsa/getfile.c +++ b/sys/lib/libsa/getfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getfile.c,v 1.6 2014/11/19 20:28:56 miod Exp $ */ +/* $OpenBSD: getfile.c,v 1.7 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: getfile.c,v 1.6 1996/10/14 04:49:21 cgd Exp $ */ /*- @@ -45,7 +45,7 @@ getfile(const char *prompt, int mode) do { printf("%s: ", prompt); - gets(buf); + getln(buf, sizeof buf); if (buf[0] == CTRL('d') && buf[1] == 0) return (-1); } while ((fd = open(buf, mode)) < 0); diff --git a/sys/lib/libsa/gets.c b/sys/lib/libsa/getln.c index a724a3c14ca..7dae1e3aeda 100644 --- a/sys/lib/libsa/gets.c +++ b/sys/lib/libsa/getln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gets.c,v 1.4 2003/08/11 06:23:09 deraadt Exp $ */ +/* $OpenBSD: getln.c,v 1.1 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: gets.c,v 1.5.2.1 1995/10/13 19:54:26 pk Exp $ */ /*- @@ -35,12 +35,16 @@ #include "stand.h" void -gets(char *buf) +getln(char *buf, size_t bufsiz) { int c; - char *lp; + char *lp, *ep; - for (lp = buf;;) + if (bufsiz == 0) + return; + ep = buf + bufsiz - 1; + + for (lp = buf; ;) switch (c = getchar() & 0177) { case '\n': case '\r': @@ -62,24 +66,26 @@ gets(char *buf) --lp; break; #endif - case 'r'&037: { - char *p; + case 'r' & 037: + { + char *p; putchar('\n'); for (p = buf; p < lp; ++p) putchar(*p); break; - } + } #if AT_ERASE case '@': #endif - case 'u'&037: - case 'w'&037: + case 'u' & 037: + case 'w' & 037: lp = buf; putchar('\n'); break; default: - *lp++ = c; + if (lp != ep) + *lp++ = c; putchar(c); } /*NOTREACHED*/ diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h index a56a2e96b45..abc95875614 100644 --- a/sys/lib/libsa/stand.h +++ b/sys/lib/libsa/stand.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stand.h,v 1.61 2015/09/02 01:52:26 yasuoka Exp $ */ +/* $OpenBSD: stand.h,v 1.62 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */ /*- @@ -138,7 +138,7 @@ void printf(const char *, ...); int snprintf(char *, size_t, const char *, ...); void vprintf(const char *, __va_list); void twiddle(void); -void gets(char *); +void getln(char *, size_t); __dead void panic(const char *, ...) __attribute__((noreturn)); __dead void _rtt(void) __attribute__((noreturn)); #define bzero(s,n) ((void)memset((s),0,(n))) |