E char *FDECL(mungspaces, (char *));
E char *FDECL(eos, (char *));
E char *FDECL(strkitten, (char *,CHAR_P));
+E void FDECL(copynchars, (char *,const char *,int));
E char *FDECL(s_suffix, (const char *));
E char *FDECL(xcrypt, (const char *,char *));
E boolean FDECL(onlyspace, (const char *));
-/* SCCS Id: @(#)hacklib.c 3.5 2004/04/11 */
+/* SCCS Id: @(#)hacklib.c 3.5 2007/03/05 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* Copyright (c) Robert Patrick Rankin, 1991 */
/* NetHack may be freely redistributed. See license for details. */
char * mungspaces (char *)
char * eos (char *)
char * strkitten (char *,char)
+ void copynchars (char *,const char *,int)
char * s_suffix (const char *)
char * xcrypt (const char *, char *)
boolean onlyspace (const char *)
return s;
}
+void
+copynchars(dst, src, n) /* truncating string copy */
+ char *dst;
+ const char *src;
+ int n;
+{
+ /* copies at most n characters, stopping sooner if terminator reached;
+ treats newline as input terminator; unlike strncpy, always supplies
+ '\0' terminator so dst must be able to hold at least n+1 characters */
+ while (n > 0 && *src != '\0' && *src != '\n') {
+ *dst++ = *src++;
+ --n;
+ }
+ *dst = '\0';
+}
+
char *
s_suffix(s) /* return a name converted to possessive */
const char *s;
/* lev_message can span multiple lines using embedded newline chars;
any segments too long to fit within in_line[] will be truncated */
for (str = lev_message; *str; str = nl + 1) {
- (void)strncpy(in_line, str, sizeof in_line - 1);
- in_line[sizeof in_line - 1] = '\0';
- if ((nl = index(in_line, '\n')) != 0) *nl = '\0';
+ /* copying will stop at newline if one is present */
+ copynchars(in_line, str, (int)(sizeof in_line) - 1);
/* convert_line() expects encrypted input;
it reads from in_line[] and writes to out_line[] */