=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/Attic/aux.c,v retrieving revision 1.19 retrieving revision 1.20 diff -c -r1.19 -r1.20 *** src/usr.bin/mail/Attic/aux.c 2001/11/20 20:50:00 1.19 --- src/usr.bin/mail/Attic/aux.c 2001/11/21 15:26:39 1.20 *************** *** 1,4 **** ! /* $OpenBSD: aux.c,v 1.19 2001/11/20 20:50:00 millert Exp $ */ /* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: aux.c,v 1.20 2001/11/21 15:26:39 millert Exp $ */ /* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* *************** *** 36,44 **** #ifndef lint #if 0 ! static char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: aux.c,v 1.19 2001/11/20 20:50:00 millert Exp $"; #endif #endif /* not lint */ --- 36,44 ---- #ifndef lint #if 0 ! static const char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; #else ! static const char rcsid[] = "$OpenBSD: aux.c,v 1.20 2001/11/21 15:26:39 millert Exp $"; #endif #endif /* not lint */ *************** *** 50,63 **** * * Auxiliary functions. */ ! static char *save2str __P((char *, char *)); /* * Return a pointer to a dynamic copy of the argument. */ char * ! savestr(str) ! char *str; { char *new; int size = strlen(str) + 1; --- 50,62 ---- * * Auxiliary functions. */ ! static char *save2str(char *, char *); /* * Return a pointer to a dynamic copy of the argument. */ char * ! savestr(char *str) { char *new; int size = strlen(str) + 1; *************** *** 71,78 **** * Make a copy of new argument incorporating old one. */ static char * ! save2str(str, old) ! char *str, *old; { char *new; int newsize = strlen(str) + 1; --- 70,76 ---- * Make a copy of new argument incorporating old one. */ static char * ! save2str(char *str, char *old) { char *new; int newsize = strlen(str) + 1; *************** *** 94,101 **** * back to the system mailbox on exit. */ void ! touch(mp) ! struct message *mp; { mp->m_flag |= MTOUCH; --- 92,98 ---- * back to the system mailbox on exit. */ void ! touch(struct message *mp) { mp->m_flag |= MTOUCH; *************** *** 108,115 **** * Return true if it is. */ int ! isdir(name) ! char name[]; { struct stat sbuf; --- 105,111 ---- * Return true if it is. */ int ! isdir(char *name) { struct stat sbuf; *************** *** 122,129 **** * Count the number of arguments in the given string raw list. */ int ! argcount(argv) ! char **argv; { char **ap; --- 118,124 ---- * Count the number of arguments in the given string raw list. */ int ! argcount(char **argv) { char **ap; *************** *** 137,145 **** * pointer (or NULL if the desired header field is not available). */ char * ! hfield(field, mp) ! char field[]; ! struct message *mp; { FILE *ibuf; char linebuf[LINESIZE]; --- 132,138 ---- * pointer (or NULL if the desired header field is not available). */ char * ! hfield(char *field, struct message *mp) { FILE *ibuf; char linebuf[LINESIZE]; *************** *** 168,178 **** * Must deal with \ continuations & other such fraud. */ int ! gethfield(f, linebuf, rem, colon) ! FILE *f; ! char linebuf[]; ! int rem; ! char **colon; { char line2[LINESIZE]; char *cp, *cp2; --- 161,167 ---- * Must deal with \ continuations & other such fraud. */ int ! gethfield(FILE *f, char *linebuf, int rem, char **colon) { char line2[LINESIZE]; char *cp, *cp2; *************** *** 227,235 **** */ char* ! ishfield(linebuf, colon, field) ! char linebuf[], field[]; ! char *colon; { char *cp = colon; --- 216,222 ---- */ char* ! ishfield(char *linebuf, char *colon, char *field) { char *cp = colon; *************** *** 246,268 **** /* * Copy a string, lowercasing it as we go. ``dsize'' should be ! * the real size (not len) of the dest string (guarantee NULL term). */ ! void ! istrncpy(dest, src, dsize) ! char *dest, *src; ! size_t dsize; { ! if (dsize != 0) { ! while (--dsize != 0 && *src != '\0') { ! if (isupper(*src)) ! *dest++ = tolower(*src++); ! else ! *dest++ = *src++; ! } ! *dest = '\0'; } } /* --- 233,266 ---- /* * Copy a string, lowercasing it as we go. ``dsize'' should be ! * the real size (not len) of the dest string (guarantee NUL term). */ ! size_t ! istrlcpy(char *dst, const char *src, size_t dsize) { + char *d = dst; + const char *s = src; + size_t n = dsize; ! /* Copy as many bytes as will fit */ ! if (n != 0 && --n != 0) { ! do { ! if (isupper(*s)) ! *d++ = tolower(*s++); ! else if ((*d++ = *s++) == 0) ! break; ! } while (--n != 0); } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (dsize != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ } /* *************** *** 270,276 **** * commands. All but the current file pointer are saved on * the stack. */ - static int ssp; /* Top of file stack */ struct sstack { FILE *s_file; /* File we were in. */ --- 268,273 ---- *************** *** 284,291 **** * that they are no longer reading from a tty (in all probability). */ int ! source(v) ! void *v; { char **arglist = v; FILE *fi; --- 281,287 ---- * that they are no longer reading from a tty (in all probability). */ int ! source(void *v) { char **arglist = v; FILE *fi; *************** *** 318,325 **** * Update the "sourcing" flag as appropriate. */ int ! unstack() { if (ssp <= 0) { puts("\"Source\" stack over-pop."); sourcing = 0; --- 314,322 ---- * Update the "sourcing" flag as appropriate. */ int ! unstack(void) { + if (ssp <= 0) { puts("\"Source\" stack over-pop."); sourcing = 0; *************** *** 342,349 **** * This is nifty for the shell. */ void ! alter(name) ! char *name; { struct stat sb; struct timeval tv[2]; --- 339,345 ---- * This is nifty for the shell. */ void ! alter(char *name) { struct stat sb; struct timeval tv[2]; *************** *** 365,372 **** * return true if it is all blanks and tabs. */ int ! blankline(linebuf) ! char linebuf[]; { char *cp; --- 361,367 ---- * return true if it is all blanks and tabs. */ int ! blankline(char *linebuf) { char *cp; *************** *** 382,390 **** * before returning it. */ char * ! nameof(mp, reptype) ! struct message *mp; ! int reptype; { char *cp, *cp2; --- 377,383 ---- * before returning it. */ char * ! nameof(struct message *mp, int reptype) { char *cp, *cp2; *************** *** 405,412 **** * Ignore it. */ char * ! skip_comment(cp) ! char *cp; { int nesting = 1; --- 398,404 ---- * Ignore it. */ char * ! skip_comment(char *cp) { int nesting = 1; *************** *** 432,439 **** * of "host-phrase." */ char * ! skin(name) ! char *name; { char *nbuf, *bufend, *cp, *cp2; int c, gotlt, lastsp; --- 424,430 ---- * of "host-phrase." */ char * ! skin(char *name) { char *nbuf, *bufend, *cp, *cp2; int c, gotlt, lastsp; *************** *** 543,551 **** * 2 -- get sender's name for Reply */ char * ! name1(mp, reptype) ! struct message *mp; ! int reptype; { char namebuf[LINESIZE]; char linebuf[LINESIZE]; --- 534,540 ---- * 2 -- get sender's name for Reply */ char * ! name1(struct message *mp, int reptype) { char namebuf[LINESIZE]; char linebuf[LINESIZE]; *************** *** 590,598 **** first = 0; } else cp2 = strrchr(namebuf, '!') + 1; ! strncpy(cp2, cp, sizeof(namebuf) - (cp2 - namebuf) - 2); ! namebuf[sizeof(namebuf) - 2] = '\0'; ! strcat(namebuf, "!"); goto newname; } cp++; --- 579,586 ---- first = 0; } else cp2 = strrchr(namebuf, '!') + 1; ! strlcpy(cp2, cp, sizeof(namebuf) - (cp2 - namebuf) - 1); ! strlcat(namebuf, "!", sizeof(namebuf)); goto newname; } cp++; *************** *** 604,612 **** * Count the occurances of c in str */ int ! charcount(str, c) ! char *str; ! int c; { char *cp; int i; --- 592,598 ---- * Count the occurances of c in str */ int ! charcount(char *str, int c) { char *cp; int i; *************** *** 618,642 **** } /* - * Are any of the characters in the two strings the same? - */ - int - anyof(s1, s2) - char *s1, *s2; - { - - while (*s1) - if (strchr(s2, *s1++)) - return(1); - return(0); - } - - /* * Convert c to upper case */ int ! raise(c) ! int c; { if (islower(c)) --- 604,613 ---- } /* * Convert c to upper case */ int ! raise(int c) { if (islower(c)) *************** *** 648,655 **** * Copy s1 to s2, return pointer to null in s2. */ char * ! copy(s1, s2) ! char *s1, *s2; { while ((*s2++ = *s1++) != '\0') --- 619,625 ---- * Copy s1 to s2, return pointer to null in s2. */ char * ! copy(char *s1, char *s2) { while ((*s2++ = *s1++) != '\0') *************** *** 661,669 **** * See if the given header field is supposed to be ignored. */ int ! isign(field, ignore) ! char *field; ! struct ignoretab ignore[2]; { char realfld[LINESIZE]; --- 631,637 ---- * See if the given header field is supposed to be ignored. */ int ! isign(char *field, struct ignoretab ignore[2]) { char realfld[LINESIZE]; *************** *** 673,679 **** * Lower-case the string, so that "Status" and "status" * will hash to the same place. */ ! istrncpy(realfld, field, sizeof(realfld)); if (ignore[1].i_count > 0) return(!member(realfld, ignore + 1)); else --- 641,647 ---- * Lower-case the string, so that "Status" and "status" * will hash to the same place. */ ! istrlcpy(realfld, field, sizeof(realfld)); if (ignore[1].i_count > 0) return(!member(realfld, ignore + 1)); else *************** *** 681,689 **** } int ! member(realfield, table) ! char *realfield; ! struct ignoretab *table; { struct ignore *igp; --- 649,655 ---- } int ! member(char *realfield, struct ignoretab *table) { struct ignore *igp; *************** *** 695,701 **** } void ! clearnew() { struct message *mp; --- 661,667 ---- } void ! clearnew(void) { struct message *mp;