diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-12 19:38:44 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-12 19:38:44 +0000 |
commit | 3004d6df5e47bc94053bba1328d73a63c7540609 (patch) | |
tree | 90207a20f69ff0c810b4ad246af8c06b00e2bd72 /bin/ed | |
parent | 5df03423fe6ca2c39244d226c95864e4fe57f417 (diff) |
Back out my sprintf -> snprintf changes where they don't make sense and
use good ole strcpy() instead. Also use perror() instead of fprintf()
where it makes sense.
Diffstat (limited to 'bin/ed')
-rw-r--r-- | bin/ed/buf.c | 36 | ||||
-rw-r--r-- | bin/ed/cbc.c | 8 | ||||
-rw-r--r-- | bin/ed/ed.h | 16 | ||||
-rw-r--r-- | bin/ed/glbl.c | 20 | ||||
-rw-r--r-- | bin/ed/io.c | 34 | ||||
-rw-r--r-- | bin/ed/main.c | 121 | ||||
-rw-r--r-- | bin/ed/re.c | 18 | ||||
-rw-r--r-- | bin/ed/sub.c | 10 | ||||
-rw-r--r-- | bin/ed/undo.c | 14 |
9 files changed, 131 insertions, 146 deletions
diff --git a/bin/ed/buf.c b/bin/ed/buf.c index 8feb876169a..0188b5be984 100644 --- a/bin/ed/buf.c +++ b/bin/ed/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.5 1996/09/15 22:25:54 millert Exp $ */ +/* $OpenBSD: buf.c,v 1.6 1996/10/12 19:38:28 millert Exp $ */ /* $NetBSD: buf.c,v 1.15 1995/04/23 10:07:28 cgd Exp $ */ /* buf.c: This file contains the scratch-file buffer rountines for the @@ -33,7 +33,7 @@ #if 0 static char *rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp"; #else -static char rcsid[] = "$OpenBSD: buf.c,v 1.5 1996/09/15 22:25:54 millert Exp $"; +static char rcsid[] = "$OpenBSD: buf.c,v 1.6 1996/10/12 19:38:28 millert Exp $"; #endif #endif /* not lint */ @@ -66,16 +66,16 @@ get_sbuf_line(lp) if (sfseek != lp->seek) { sfseek = lp->seek; if (fseek(sfp, sfseek, SEEK_SET) < 0) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot seek temp file"); + perror(NULL); + strcpy(errmsg, "cannot seek temp file"); return NULL; } } len = lp->len; REALLOC(sfbuf, sfbufsz, len + 1, NULL); if ((ct = fread(sfbuf, sizeof(char), len, sfp)) < 0 || ct != len) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot read temp file"); + perror(NULL); + strcpy(errmsg, "cannot read temp file"); return NULL; } sfseek += len; /* update file position */ @@ -95,23 +95,23 @@ put_sbuf_line(cs) char *s; if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); return NULL; } /* assert: cs is '\n' terminated */ for (s = cs; *s != '\n'; s++) ; if (s - cs >= LINECHARS) { - snprintf(errmsg, sizeof(errmsg), "line too long"); + strcpy(errmsg, "line too long"); return NULL; } len = s - cs; /* out of position */ if (seek_write) { if (fseek(sfp, 0L, SEEK_END) < 0) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot seek temp file"); + perror(NULL); + strcpy(errmsg, "cannot seek temp file"); return NULL; } sfseek = ftell(sfp); @@ -120,8 +120,8 @@ put_sbuf_line(cs) /* assert: SPL1() */ if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) { sfseek = -1; - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot write temp file"); + perror(NULL); + strcpy(errmsg, "cannot write temp file"); return NULL; } lp->len = len; @@ -157,7 +157,7 @@ get_line_node_addr(lp) while (cp != lp && (cp = cp->q_forw) != &buffer_head) n++; if (n && cp == &buffer_head) { - snprintf(errmsg, sizeof(errmsg), "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } return n; @@ -214,8 +214,8 @@ open_sbuf() (sfp = fdopen(fd, "w+")) == NULL) { if (fd != -1) close(fd); - fprintf(stderr, "%s: %s\n", sfn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot open temp file"); + perror(sfn); + strcpy(errmsg, "cannot open temp file"); umask(u); return ERR; } @@ -230,8 +230,8 @@ close_sbuf() { if (sfp) { if (fclose(sfp) < 0) { - fprintf(stderr, "%s: %s\n", sfn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot close temp file"); + perror(sfn); + strcpy(errmsg, "cannot close temp file"); return ERR; } sfp = NULL; diff --git a/bin/ed/cbc.c b/bin/ed/cbc.c index 48fe9ecef5c..3eb9efbcf89 100644 --- a/bin/ed/cbc.c +++ b/bin/ed/cbc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cbc.c,v 1.3 1996/09/15 22:25:54 millert Exp $ */ +/* $OpenBSD: cbc.c,v 1.4 1996/10/12 19:38:31 millert Exp $ */ /* $NetBSD: cbc.c,v 1.9 1995/03/21 09:04:36 cgd Exp $ */ /* cbc.c: This file contains the encryption routines for the ed line editor */ @@ -44,7 +44,7 @@ #if 0 static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp"; #else -static char rcsid[] = "$OpenBSD: cbc.c,v 1.3 1996/09/15 22:25:54 millert Exp $"; +static char rcsid[] = "$OpenBSD: cbc.c,v 1.4 1996/10/12 19:38:31 millert Exp $"; #endif #endif /* not lint */ @@ -212,7 +212,7 @@ void des_error(s) char *s; /* the message */ { - (void)snprintf(errmsg, sizeof(errmsg), "%s", s ? s : strerror(errno)); + strcpy(errmsg, s ? s : strerror(errno)); } /* @@ -301,7 +301,7 @@ expand_des_key(obuf, ibuf) /* * no special leader -- ASCII */ - (void)strncpy(obuf, ibuf, 8); + strncpy(obuf, ibuf, 8); } /***************** diff --git a/bin/ed/ed.h b/bin/ed/ed.h index 1f827ff394b..05f97d0d80c 100644 --- a/bin/ed/ed.h +++ b/bin/ed/ed.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ed.h,v 1.4 1996/09/15 22:25:55 millert Exp $ */ +/* $OpenBSD: ed.h,v 1.5 1996/10/12 19:38:33 millert Exp $ */ /* $NetBSD: ed.h,v 1.23 1995/03/21 09:04:40 cgd Exp $ */ /* ed.h: type and constant definitions for the ed editor. */ @@ -116,7 +116,7 @@ if (--mutex == 0) { \ #define STRTOL(i, p) { \ if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \ errno == ERANGE) { \ - snprintf(errmsg, sizeof(errmsg), "number out of range"); \ + strcpy(errmsg, "number out of range"); \ i = 0; \ return ERR; \ } \ @@ -131,15 +131,15 @@ if ((i) > (n)) { \ SPL1(); \ if ((b) != NULL) { \ if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \ - fprintf(stderr, "%s\n", strerror(errno)); \ - snprintf(errmsg, sizeof(errmsg), "out of memory"); \ + perror(NULL); \ + strcpy(errmsg, "out of memory"); \ SPL0(); \ return err; \ } \ } else { \ if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \ - fprintf(stderr, "%s\n", strerror(errno)); \ - snprintf(errmsg, sizeof(errmsg), "out of memory"); \ + perror(NULL); \ + strcpy(errmsg, "out of memory"); \ SPL0(); \ return err; \ } \ @@ -156,8 +156,8 @@ if ((i) > (n)) { \ char *ts; \ SPL1(); \ if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \ - fprintf(stderr, "%s\n", strerror(errno)); \ - snprintf(errmsg, sizeof(errmsg), "out of memory"); \ + perror(NULL); \ + strcpy(errmsg, "out of memory"); \ SPL0(); \ return err; \ } \ diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c index 3cbebd97758..b92b2ab1a5b 100644 --- a/bin/ed/glbl.c +++ b/bin/ed/glbl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glbl.c,v 1.3 1996/09/15 22:25:55 millert Exp $ */ +/* $OpenBSD: glbl.c,v 1.4 1996/10/12 19:38:34 millert Exp $ */ /* $NetBSD: glbl.c,v 1.2 1995/03/21 09:04:41 cgd Exp $ */ /* glob.c: This file contains the global command routines for the ed line @@ -33,7 +33,7 @@ #if 0 static char *rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp"; #else -static char rcsid[] = "$OpenBSD: glbl.c,v 1.3 1996/09/15 22:25:55 millert Exp $"; +static char rcsid[] = "$OpenBSD: glbl.c,v 1.4 1996/10/12 19:38:34 millert Exp $"; #endif #endif /* not lint */ @@ -55,7 +55,7 @@ build_active_list(isgcmd) char delimiter; if ((delimiter = *ibufp) == ' ' || delimiter == '\n') { - snprintf(errmsg, sizeof(errmsg), "invalid pattern delimiter"); + strcpy(errmsg, "invalid pattern delimiter"); return ERR; } else if ((pat = get_compiled_pattern()) == NULL) return ERR; @@ -115,15 +115,13 @@ exec_global(interact, gflag) if (n < 0) return ERR; else if (n == 0) { - snprintf(errmsg, sizeof(errmsg), - "unexpected end-of-file"); + strcpy(errmsg, "unexpected end-of-file"); return ERR; } else if (n == 1 && !strcmp(ibuf, "\n")) continue; else if (n == 2 && !strcmp(ibuf, "&\n")) { if (cmd == NULL) { - snprintf(errmsg, sizeof(errmsg), - "no previous command"); + strcpy(errmsg, "no previous command"); return ERR; } else cmd = ocmd; } else if ((cmd = get_extended_line(&n, 0)) == NULL) @@ -167,8 +165,8 @@ set_active_node(lp) #endif if ((ts = (line_t **) realloc(active_list, (ti += MINBUFSZ) * sizeof(line_t **))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); SPL0(); return ERR; } @@ -176,8 +174,8 @@ set_active_node(lp) } else { if ((ts = (line_t **) malloc((ti += MINBUFSZ) * sizeof(line_t **))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); SPL0(); return ERR; } diff --git a/bin/ed/io.c b/bin/ed/io.c index fbf1b3cd9d9..d84211711dd 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.3 1996/09/15 22:25:56 millert Exp $ */ +/* $OpenBSD: io.c,v 1.4 1996/10/12 19:38:36 millert Exp $ */ /* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */ /* io.c: This file contains the i/o routines for the ed line editor */ @@ -32,7 +32,7 @@ #if 0 static char *rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp"; #else -static char rcsid[] = "$OpenBSD: io.c,v 1.3 1996/09/15 22:25:56 millert Exp $"; +static char rcsid[] = "$OpenBSD: io.c,v 1.4 1996/10/12 19:38:36 millert Exp $"; #endif #endif /* not lint */ @@ -53,14 +53,14 @@ read_file(fn, n) fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r"); if (fp == NULL) { - fprintf(stderr, "%s: %s\n", fn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot open input file"); + perror(fn); + strcpy(errmsg, "cannot open input file"); return ERR; } else if ((size = read_stream(fp, n)) < 0) return ERR; else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { - fprintf(stderr, "%s: %s\n", fn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot close input file"); + perror(fn); + strcpy(errmsg, "cannot close input file"); return ERR; } fprintf(stderr, !scripted ? "%lu\n" : "", size); @@ -143,8 +143,8 @@ get_stream_line(fp) if (c == '\n') sbuf[i++] = c; else if (ferror(fp)) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot read input file"); + perror(NULL); + strcpy(errmsg, "cannot read input file"); return ERR; } else if (i) { sbuf[i++] = '\n'; @@ -168,14 +168,14 @@ write_file(fn, mode, n, m) fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode); if (fp == NULL) { - fprintf(stderr, "%s: %s\n", fn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot open output file"); + perror(fn); + strcpy(errmsg, "cannot open output file"); return ERR; } else if ((size = write_stream(fp, n, m)) < 0) return ERR; else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { - fprintf(stderr, "%s: %s\n", fn, strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot close output file"); + perror(fn); + strcpy(errmsg, "cannot close output file"); return ERR; } fprintf(stderr, !scripted ? "%lu\n" : "", size); @@ -224,8 +224,8 @@ put_stream_line(fp, s, len) { while (len--) if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot write file"); + perror(NULL); + strcpy(errmsg, "cannot write file"); return ERR; } return 0; @@ -258,7 +258,7 @@ get_extended_line(sizep, nonl) if ((n = get_tty_line()) < 0) return NULL; else if (n == 0 || ibuf[n - 1] != '\n') { - snprintf(errmsg, sizeof(errmsg), "unexpected end-of-file"); + strcpy(errmsg, "unexpected end-of-file"); return NULL; } REALLOC(cvbuf, cvbufsz, l + n, NULL); @@ -298,8 +298,8 @@ get_tty_line() return i; case EOF: if (ferror(stdin)) { - fprintf(stderr, "stdin: %s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "cannot read stdin"); + perror(stdin); + strcpy(errmsg, "cannot read stdin"); clearerr(stdin); ibufp = NULL; return ERR; diff --git a/bin/ed/main.c b/bin/ed/main.c index 64e9447299e..0e7e6df6d3d 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.3 1996/09/15 22:25:57 millert Exp $ */ +/* $OpenBSD: main.c,v 1.4 1996/10/12 19:38:38 millert Exp $ */ /* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */ /* main.c: This file contains the main control and user-interface routines @@ -39,7 +39,7 @@ char *copyright = #if 0 static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.3 1996/09/15 22:25:57 millert Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.4 1996/10/12 19:38:38 millert Exp $"; #endif #endif /* not lint */ @@ -164,7 +164,7 @@ top: #endif { fputs("\n?\n", stderr); - snprintf(errmsg, sizeof(errmsg), "interrupt"); + strcpy(errmsg, "interrupt"); } else { init_buffers(); sigactive = 1; /* enable signal handlers */ @@ -176,7 +176,7 @@ top: } else if (argc) { fputs("?\n", stderr); if (**argv == '\0') - snprintf(errmsg, sizeof(errmsg), "invalid filename"); + strcpy(errmsg, "invalid filename"); if (!isatty(0)) quit(2); } @@ -185,7 +185,7 @@ top: if (status < 0 && garrulous) fprintf(stderr, "%s\n", errmsg); if (prompt) { - printf("%s", prompt); + fputs(prompt, stdout); fflush(stdout); } if ((n = get_tty_line()) < 0) { @@ -194,7 +194,7 @@ top: } else if (n == 0) { if (modified && !scripted) { fputs("?\n", stderr); - snprintf(errmsg, sizeof(errmsg), "warning: file modified"); + strcpy(errmsg, "warning: file modified"); if (!isatty(0)) { fprintf(stderr, garrulous ? "script, line %d: %s\n" : @@ -209,7 +209,7 @@ top: quit(0); } else if (ibuf[n - 1] != '\n') { /* discard line */ - snprintf(errmsg, sizeof(errmsg), "unexpected end-of-file"); + strcpy(errmsg, "unexpected end-of-file"); clearerr(stdin); status = ERR; continue; @@ -227,7 +227,7 @@ top: case EMOD: modified = 0; fputs("?\n", stderr); /* give warning */ - snprintf(errmsg, sizeof(errmsg), "warning: file modified"); + strcpy(errmsg, "warning: file modified"); if (!isatty(0)) { fprintf(stderr, garrulous ? "script, line %d: %s\n" : @@ -287,7 +287,7 @@ extract_addr_range() #define SKIP_BLANKS() while (isspace(*ibufp) && *ibufp != '\n') ibufp++ #define MUST_BE_FIRST() \ - if (!first) { snprintf(errmsg, sizeof(errmsg), "invalid address"); return ERR; } + if (!first) { strcpy(errmsg, "invalid address"); return ERR; } /* next_addr: return the next line address in the command buffer */ long @@ -357,8 +357,7 @@ next_addr() if (ibufp == hd) return EOF; else if (addr < 0 || addr_last < addr) { - snprintf(errmsg, sizeof(errmsg), - "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } else return addr; @@ -377,10 +376,10 @@ next_addr() if (extract_addr_range() < 0) \ return ERR; \ else if (addr_cnt == 0) { \ - snprintf(errmsg, sizeof(errmsg), "destination expected"); \ + strcpy(errmsg, "destination expected"); \ return ERR; \ } else if (second_addr < 0 || addr_last < second_addr) { \ - snprintf(errmsg, sizeof(errmsg), "invalid address"); \ + strcpy(errmsg, "invalid address"); \ return ERR; \ } \ addr = second_addr; \ @@ -396,7 +395,7 @@ next_addr() if (extract_addr_range() < 0) \ return ERR; \ if (second_addr < 0 || addr_last < second_addr) { \ - snprintf(errmsg, sizeof(errmsg), "invalid address"); \ + strcpy(errmsg, "invalid address"); \ return ERR; \ } \ addr = second_addr; \ @@ -424,7 +423,7 @@ next_addr() } \ } while (!done); \ if (*ibufp++ != '\n') { \ - snprintf(errmsg, sizeof(errmsg), "invalid command suffix"); \ + strcpy(errmsg, "invalid command suffix"); \ return ERR; \ } \ } @@ -493,11 +492,10 @@ exec_command() /* fall through */ case 'E': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } else if (!isspace(*ibufp)) { - snprintf(errmsg, sizeof(errmsg), - "unexpected command suffix"); + strcpy(errmsg, "unexpected command suffix"); return ERR; } else if ((fnp = get_filename()) == NULL) return ERR; @@ -512,7 +510,7 @@ exec_command() if (*fnp && *fnp != '!') strcpy(old_filename, fnp); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { - snprintf(errmsg, sizeof(errmsg), "no current filename"); + strcpy(errmsg, "no current filename"); return ERR; } #endif @@ -524,29 +522,27 @@ exec_command() break; case 'f': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } else if (!isspace(*ibufp)) { - snprintf(errmsg, sizeof(errmsg), - "unexpected command suffix"); + strcpy(errmsg, "unexpected command suffix"); return ERR; } else if ((fnp = get_filename()) == NULL) return ERR; else if (*fnp == '!') { - snprintf(errmsg, sizeof(errmsg), "invalid redirection"); + strcpy(errmsg, "invalid redirection"); return ERR; } GET_COMMAND_SUFFIX(); if (*fnp) strcpy(old_filename, fnp); - printf("%s\n", strip_escapes(old_filename)); + puts(strip_escapes(old_filename)); break; case 'g': case 'v': case 'G': case 'V': if (isglobal) { - snprintf(errmsg, sizeof(errmsg), - "cannot nest global commands"); + strcpy(errmsg, "cannot nest global commands"); return ERR; } else if (check_addr_range(1, addr_last) < 0) return ERR; @@ -560,7 +556,7 @@ exec_command() break; case 'h': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -568,7 +564,7 @@ exec_command() break; case 'H': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -577,7 +573,7 @@ exec_command() break; case 'i': if (second_addr == 0) { - snprintf(errmsg, sizeof(errmsg), "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -597,7 +593,7 @@ exec_command() case 'k': c = *ibufp++; if (second_addr == 0) { - snprintf(errmsg, sizeof(errmsg), "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -617,7 +613,7 @@ exec_command() return ERR; GET_THIRD_ADDR(addr); if (first_addr <= addr && addr < second_addr) { - snprintf(errmsg, sizeof(errmsg), "invalid destination"); + strcpy(errmsg, "invalid destination"); return ERR; } GET_COMMAND_SUFFIX(); @@ -643,7 +639,7 @@ exec_command() break; case 'P': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -652,7 +648,7 @@ exec_command() case 'q': case 'Q': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -660,8 +656,7 @@ exec_command() break; case 'r': if (!isspace(*ibufp)) { - snprintf(errmsg, sizeof(errmsg), - "unexpected command suffix"); + strcpy(errmsg, "unexpected command suffix"); return ERR; } else if (addr_cnt == 0) second_addr = addr_last; @@ -673,7 +668,7 @@ exec_command() strcpy(old_filename, fnp); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { - snprintf(errmsg, sizeof(errmsg), "no current filename"); + strcpy(errmsg, "no current filename"); return ERR; } #endif @@ -708,21 +703,18 @@ exec_command() break; default: if (sflags) { - snprintf(errmsg, sizeof(errmsg), - "invalid command suffix"); + strcpy(errmsg, "invalid command suffix"); return ERR; } } } while (sflags && *ibufp != '\n'); if (sflags && !pat) { - snprintf(errmsg, sizeof(errmsg), - "no previous substitution"); + strcpy(errmsg, "no previous substitution"); return ERR; } else if (sflags & SGG) sgnum = 0; /* override numeric arg */ if (*ibufp != '\n' && *(ibufp + 1) == '\n') { - snprintf(errmsg, sizeof(errmsg), - "invalid pattern delimiter"); + strcpy(errmsg, "invalid pattern delimiter"); return ERR; } tpat = pat; @@ -783,7 +775,7 @@ exec_command() break; case 'u': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); @@ -797,8 +789,7 @@ exec_command() ibufp++; } if (!isspace(*ibufp)) { - snprintf(errmsg, sizeof(errmsg), - "unexpected command suffix"); + strcpy(errmsg, "unexpected command suffix"); return ERR; } else if ((fnp = get_filename()) == NULL) return ERR; @@ -811,7 +802,7 @@ exec_command() strcpy(old_filename, fnp); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { - snprintf(errmsg, sizeof(errmsg), "no current filename"); + strcpy(errmsg, "no current filename"); return ERR; } #endif @@ -825,14 +816,14 @@ exec_command() break; case 'x': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } GET_COMMAND_SUFFIX(); #ifdef DES des = get_keyword(); #else - snprintf(errmsg, sizeof(errmsg), "crypt unavailable"); + strcpy(errmsg, "crypt unavailable"); return ERR; #endif break; @@ -857,7 +848,7 @@ exec_command() break; case '!': if (addr_cnt > 0) { - snprintf(errmsg, sizeof(errmsg), "unexpected address"); + strcpy(errmsg, "unexpected address"); return ERR; } else if ((sflags = get_shell_command()) < 0) return ERR; @@ -876,7 +867,7 @@ exec_command() return ERR; break; default: - snprintf(errmsg, sizeof(errmsg), "unknown command"); + strcpy(errmsg, "unknown command"); return ERR; } return gflag; @@ -894,7 +885,7 @@ check_addr_range(n, m) } if (first_addr > second_addr || 1 > first_addr || second_addr > addr_last) { - snprintf(errmsg, sizeof(errmsg), "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } return 0; @@ -925,7 +916,7 @@ get_matching_node_addr(pat, dir) return n; } } while (n != current_addr); - snprintf(errmsg, sizeof(errmsg), "no match"); + strcpy(errmsg, "no match"); return ERR; } @@ -942,7 +933,7 @@ get_filename() if (*ibufp != '\n') { SKIP_BLANKS(); if (*ibufp == '\n') { - snprintf(errmsg, sizeof(errmsg), "invalid filename"); + strcpy(errmsg, "invalid filename"); return NULL; } else if ((ibufp = get_extended_line(&n, 1)) == NULL) return NULL; @@ -953,13 +944,13 @@ get_filename() if (n) printf("%s\n", shcmd + 1); return shcmd; } else if (n - 1 > MAXPATHLEN) { - snprintf(errmsg, sizeof(errmsg), "filename too long"); + strcpy(errmsg, "filename too long"); return NULL; } } #ifndef BACKWARDS else if (*old_filename == '\0') { - snprintf(errmsg, sizeof(errmsg), "no current filename"); + strcpy(errmsg, "no current filename"); return NULL; } #endif @@ -984,7 +975,7 @@ get_shell_command() int j = 0; if (red) { - snprintf(errmsg, sizeof(errmsg), "shell access restricted"); + strcpy(errmsg, "shell access restricted"); return ERR; } else if ((s = ibufp = get_extended_line(&j, 1)) == NULL) return ERR; @@ -1009,8 +1000,7 @@ get_shell_command() else if (shcmd == NULL) #endif { - snprintf(errmsg, sizeof(errmsg), - "no previous command"); + strcpy(errmsg, "no previous command"); return ERR; } else { REALLOC(buf, n, i + shcmdi, ERR); @@ -1021,8 +1011,7 @@ get_shell_command() break; case '%': if (*old_filename == '\0') { - snprintf(errmsg, sizeof(errmsg), - "no current filename"); + strcpy(errmsg, "no current filename"); return ERR; } j = strlen(s = strip_escapes(old_filename)); @@ -1249,7 +1238,7 @@ display_lines(from, to, gflag) char *s; if (!from) { - snprintf(errmsg, sizeof(errmsg), "invalid address"); + strcpy(errmsg, "invalid address"); return ERR; } ep = get_addressed_line_node(INC_MOD(to, addr_last)); @@ -1276,7 +1265,7 @@ mark_line_node(lp, n) int n; { if (!islower(n)) { - snprintf(errmsg, sizeof(errmsg), "invalid mark character"); + strcpy(errmsg, "invalid mark character"); return ERR; } else if (mark[n - 'a'] == NULL) markno++; @@ -1291,7 +1280,7 @@ get_marked_node_addr(n) int n; { if (!islower(n)) { - snprintf(errmsg, sizeof(errmsg), "invalid mark character"); + strcpy(errmsg, "invalid mark character"); return ERR; } return get_line_node_addr(mark[n - 'a']); @@ -1321,8 +1310,8 @@ dup_line_node(lp) line_t *np; if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); return NULL; } np->seek = lp->seek; @@ -1442,7 +1431,7 @@ is_legal_filename(s) char *s; { if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) { - snprintf(errmsg, sizeof(errmsg), "shell access restricted"); + strcpy(errmsg, "shell access restricted"); return 0; } return 1; diff --git a/bin/ed/re.c b/bin/ed/re.c index 64d98990670..948a05980d9 100644 --- a/bin/ed/re.c +++ b/bin/ed/re.c @@ -1,4 +1,4 @@ -/* $OpenBSD: re.c,v 1.3 1996/09/15 22:25:57 millert Exp $ */ +/* $OpenBSD: re.c,v 1.4 1996/10/12 19:38:40 millert Exp $ */ /* $NetBSD: re.c,v 1.14 1995/03/21 09:04:48 cgd Exp $ */ /* re.c: This file contains the regular expression interface routines for @@ -33,7 +33,7 @@ #if 0 static char *rcsid = "@(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp"; #else -static char rcsid[] = "$OpenBSD: re.c,v 1.3 1996/09/15 22:25:57 millert Exp $"; +static char rcsid[] = "$OpenBSD: re.c,v 1.4 1996/10/12 19:38:40 millert Exp $"; #endif #endif /* not lint */ @@ -56,11 +56,11 @@ get_compiled_pattern() int n; if ((delimiter = *ibufp) == ' ') { - snprintf(errmsg, sizeof(errmsg), "invalid pattern delimiter"); + strcpy(errmsg, "invalid pattern delimiter"); return NULL; } else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) { if (!exp) - snprintf(errmsg, sizeof(errmsg), "no previous pattern"); + strcpy(errmsg, "no previous pattern"); return exp; } else if ((exps = extract_pattern(delimiter)) == NULL) return NULL; @@ -68,8 +68,8 @@ get_compiled_pattern() if (exp && !patlock) regfree(exp); else if ((exp = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); return NULL; } patlock = 0; @@ -100,15 +100,13 @@ extract_pattern(delimiter) break; case '[': if ((nd = parse_char_class(++nd)) == NULL) { - snprintf(errmsg, sizeof(errmsg), - "unbalanced brackets ([])"); + strcpy(errmsg, "unbalanced brackets ([])"); return NULL; } break; case '\\': if (*++nd == '\n') { - snprintf(errmsg, sizeof(errmsg), - "trailing backslash (\\)"); + strcpy(errmsg, "trailing backslash (\\)"); return NULL; } break; diff --git a/bin/ed/sub.c b/bin/ed/sub.c index 0234dc2ba21..e0fa18d54b9 100644 --- a/bin/ed/sub.c +++ b/bin/ed/sub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sub.c,v 1.3 1996/09/15 22:25:58 millert Exp $ */ +/* $OpenBSD: sub.c,v 1.4 1996/10/12 19:38:42 millert Exp $ */ /* $NetBSD: sub.c,v 1.4 1995/03/21 09:04:50 cgd Exp $ */ /* sub.c: This file contains the substitution routines for the ed @@ -33,7 +33,7 @@ #if 0 static char *rcsid = "@(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp"; #else -static char rcsid[] = "$OpenBSD: sub.c,v 1.3 1996/09/15 22:25:58 millert Exp $"; +static char rcsid[] = "$OpenBSD: sub.c,v 1.4 1996/10/12 19:38:42 millert Exp $"; #endif #endif /* not lint */ @@ -89,7 +89,7 @@ extract_subst_template() if (*ibufp == '%' && *(ibufp + 1) == delimiter) { ibufp++; if (!rhbuf) - snprintf(errmsg, sizeof(errmsg), "no previous substitution"); + strcpy(errmsg, "no previous substitution"); return rhbuf; } while (*ibufp != delimiter) { @@ -166,7 +166,7 @@ search_and_replace(pat, gflag, kth) } current_addr = xa; if (nsubs == 0 && !(gflag & GLB)) { - snprintf(errmsg, sizeof(errmsg), "no match"); + strcpy(errmsg, "no match"); return ERR; } else if ((gflag & (GPR | GLS | GNP)) && display_lines(current_addr, current_addr, gflag) < 0) @@ -224,7 +224,7 @@ substitute_matching_text(pat, lp, gflag, kth) i = eot - txt; REALLOC(rbuf, rbufsz, off + i + 2, ERR); if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) { - snprintf(errmsg, sizeof(errmsg), "infinite substitution loop"); + strcpy(errmsg, "infinite substitution loop"); return ERR; } if (isbinary) diff --git a/bin/ed/undo.c b/bin/ed/undo.c index 4fa60d2cf9c..dee17de9be6 100644 --- a/bin/ed/undo.c +++ b/bin/ed/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.3 1996/09/15 22:25:58 millert Exp $ */ +/* $OpenBSD: undo.c,v 1.4 1996/10/12 19:38:43 millert Exp $ */ /* $NetBSD: undo.c,v 1.2 1995/03/21 09:04:52 cgd Exp $ */ /* undo.c: This file contains the undo routines for the ed line editor */ @@ -32,7 +32,7 @@ #if 0 static char *rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp"; #else -static char rcsid[] = "$OpenBSD: undo.c,v 1.3 1996/09/15 22:25:58 millert Exp $"; +static char rcsid[] = "$OpenBSD: undo.c,v 1.4 1996/10/12 19:38:43 millert Exp $"; #endif #endif /* not lint */ @@ -56,8 +56,8 @@ push_undo_stack(type, from, to) #if defined(sun) || defined(NO_REALLOC_NULL) if (ustack == NULL && (ustack = (undo_t *) malloc((usize = USIZE) * sizeof(undo_t))) == NULL) { - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); return NULL; } #endif @@ -71,8 +71,8 @@ push_undo_stack(type, from, to) return ustack + u_p++; } /* out of memory - release undo stack */ - fprintf(stderr, "%s\n", strerror(errno)); - snprintf(errmsg, sizeof(errmsg), "out of memory"); + perror(NULL); + strcpy(errmsg, "out of memory"); clear_undo_stack(); free(ustack); ustack = NULL; @@ -100,7 +100,7 @@ pop_undo_stack() long o_addr_last = addr_last; if (u_current_addr == -1 || u_addr_last == -1) { - snprintf(errmsg, sizeof(errmsg), "nothing to undo"); + strcpy(errmsg, "nothing to undo"); return ERR; } else if (u_p) modified = 1; |