/****************************************************************************
- * Copyright (c) 2004-2009,2016 Free Software Foundation, Inc. *
+ * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2004-2009,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_insnstr.c,v 1.4 2016/02/20 21:22:46 tom Exp $")
+MODULE_ID("$Id: lib_insnstr.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
{
int code = ERR;
- NCURSES_SIZE_T oy;
- NCURSES_SIZE_T ox;
const unsigned char *str = (const unsigned char *) s;
- const unsigned char *cp;
T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
if (code == ERR)
#endif
{
+ NCURSES_SIZE_T oy = win->_cury;
+ NCURSES_SIZE_T ox = win->_curx;
+ const unsigned char *cp;
- oy = win->_cury;
- ox = win->_curx;
- for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
+ for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) {
_nc_insert_ch(sp, win, (chtype) UChar(*cp));
}
win->_curx = ox;