Skip to content

Commit

Permalink
ed(1): Sync with FreeBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Wildner committed Jul 28, 2016
1 parent 7c31553 commit 92e10cb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/ed/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $FreeBSD: head/bin/ed/Makefile 235654 2012-05-19 17:55:49Z marcel $
# $FreeBSD: head/bin/ed/Makefile 298107 2016-04-16 07:45:30Z gjb $

PROG= ed
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
Expand Down
9 changes: 3 additions & 6 deletions bin/ed/cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* from: @(#)bdes.c 5.5 (Berkeley) 6/27/91
*
* @(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp
* $FreeBSD: head/bin/ed/cbc.c 248656 2013-03-23 19:04:57Z jmg $
* $FreeBSD: head/bin/ed/cbc.c 300340 2016-05-21 00:45:42Z pfg $
*/

#include <sys/types.h>
Expand Down Expand Up @@ -92,16 +92,13 @@ void
init_des_cipher(void)
{
#ifdef DES
int i;

des_ct = des_n = 0;

/* initialize the initialization vector */
MEMZERO(ivec, 8);

/* initialize the padding vector */
for (i = 0; i < 8; i++)
pvec[i] = (char) (arc4random() % 256);
arc4random_buf(pvec, sizeof(pvec));
#endif
}

Expand Down Expand Up @@ -166,7 +163,7 @@ get_keyword(void)
/*
* get the key
*/
if (*(p = getpass("Enter key: "))) {
if ((p = getpass("Enter key: ")) != NULL && *p != '\0') {

/*
* copy it, nul-padded, into the key area
Expand Down
4 changes: 2 additions & 2 deletions bin/ed/ed.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $FreeBSD: head/bin/ed/ed.1 250582 2013-05-12 22:22:12Z joel $
.\" $FreeBSD: head/bin/ed/ed.1 281997 2015-04-26 10:03:05Z bapt $
.Dd July 3, 2004
.Dt ED 1
.Os
Expand Down Expand Up @@ -739,7 +739,7 @@ It is an error if no substitutions are performed on any of the addressed
lines.
The current address is set the last line affected.
.Pp
.Ar Re
.Ar \&Re
and
.Ar replacement
may be delimited by any character other than space and newline
Expand Down
4 changes: 2 additions & 2 deletions bin/ed/glbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* SUCH DAMAGE.
*
* @(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp
* $FreeBSD: head/bin/ed/glbl.c 241720 2012-10-19 05:43:38Z ed $
* $FreeBSD: head/bin/ed/glbl.c 281758 2015-04-20 02:07:57Z eadler $
*/

#include <sys/types.h>
Expand Down Expand Up @@ -154,7 +154,7 @@ set_active_node(line_t *lp)
if (active_list != NULL) {
#endif
if ((ts = (line_t **) realloc(active_list,
(ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
(ti += MINBUFSZ) * sizeof(line_t *))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
errmsg = "out of memory";
SPL0();
Expand Down
29 changes: 19 additions & 10 deletions bin/ed/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* SUCH DAMAGE.
*
* @(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp
* $FreeBSD: head/bin/ed/io.c 241737 2012-10-19 14:49:42Z ed $
* $FreeBSD: head/bin/ed/io.c 300692 2016-05-25 18:38:30Z truckman $
*/

#include "ed.h"
Expand All @@ -36,20 +36,24 @@ read_file(char *fn, long n)
{
FILE *fp;
long size;

int cs;

fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
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) {
}
if ((size = read_stream(fp, n)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "error reading input file";
}
if ((cs = (*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot close input file";
return ERR;
}
if (size < 0 || cs < 0)
return ERR;
if (!scripted)
fprintf(stdout, "%lu\n", size);
return current_addr - n;
Expand Down Expand Up @@ -143,19 +147,24 @@ write_file(char *fn, const char *mode, long n, long m)
{
FILE *fp;
long size;
int cs;

fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
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) {
}
if ((size = write_stream(fp, n, m)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "error writing output file";
}
if ((cs = (*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot close output file";
return ERR;
}
if (size < 0 || cs < 0)
return ERR;
if (!scripted)
fprintf(stdout, "%lu\n", size);
return n ? m - n + 1 : 0;
Expand Down
12 changes: 7 additions & 5 deletions bin/ed/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @(#) Copyright (c) 1993 Andrew Moore, Talke Studio. All rights reserved.
* @(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp
* $FreeBSD: head/bin/ed/main.c 241720 2012-10-19 05:43:38Z ed $
* $FreeBSD: head/bin/ed/main.c 292455 2015-12-18 23:05:36Z pfg $
*/

/*
Expand Down Expand Up @@ -489,7 +489,8 @@ exec_command(void)
return ERR;
else if (open_sbuf() < 0)
return FATAL;
if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
if (*fnp && *fnp != '!')
strlcpy(old_filename, fnp, PATH_MAX);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
errmsg = "no current filename";
Expand All @@ -516,7 +517,8 @@ exec_command(void)
return ERR;
}
GET_COMMAND_SUFFIX();
if (*fnp) strcpy(old_filename, fnp);
if (*fnp)
strlcpy(old_filename, fnp, PATH_MAX);
printf("%s\n", strip_escapes(old_filename));
break;
case 'g':
Expand Down Expand Up @@ -647,7 +649,7 @@ exec_command(void)
GET_COMMAND_SUFFIX();
if (!isglobal) clear_undo_stack();
if (*old_filename == '\0' && *fnp != '!')
strcpy(old_filename, fnp);
strlcpy(old_filename, fnp, PATH_MAX);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
errmsg = "no current filename";
Expand Down Expand Up @@ -781,7 +783,7 @@ exec_command(void)
return ERR;
GET_COMMAND_SUFFIX();
if (*old_filename == '\0' && *fnp != '!')
strcpy(old_filename, fnp);
strlcpy(old_filename, fnp, PATH_MAX);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
errmsg = "no current filename";
Expand Down

0 comments on commit 92e10cb

Please sign in to comment.