From owner-svn-src-all@FreeBSD.ORG Wed May 6 23:52:17 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9F3A0B12; Wed, 6 May 2015 23:52:17 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8BE4511DD; Wed, 6 May 2015 23:52:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t46NqHKv020011; Wed, 6 May 2015 23:52:17 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t46NqGRq020002; Wed, 6 May 2015 23:52:16 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201505062352.t46NqGRq020002@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Wed, 6 May 2015 23:52:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r282572 - vendor/OpenBSD/dist/usr.bin/rcs X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 May 2015 23:52:17 -0000 Author: pfg Date: Wed May 6 23:52:15 2015 New Revision: 282572 URL: https://svnweb.freebsd.org/changeset/base/282572 Log: Bring OpenRCS 20150326 to the vendor area. A BSD-licensed alternative to GNU Revision Control System. Obtained from: OpenBSD Added: vendor/OpenBSD/dist/usr.bin/rcs/ vendor/OpenBSD/dist/usr.bin/rcs/Makefile (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/buf.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/buf.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/ci.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/ci.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/co.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/co.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/date.y vendor/OpenBSD/dist/usr.bin/rcs/diff.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/diff.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/diff3.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/ident.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/ident.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/merge.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/merge.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcs.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcs.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcs.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsclean.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsclean.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsdiff.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsdiff.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsmerge.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsmerge.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsnum.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsparse.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsparse.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsprog.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsprog.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcstime.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsutil.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rcsutil.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rlog.1 (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/rlog.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/worklist.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/worklist.h (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/xmalloc.c (contents, props changed) vendor/OpenBSD/dist/usr.bin/rcs/xmalloc.h (contents, props changed) Added: vendor/OpenBSD/dist/usr.bin/rcs/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/OpenBSD/dist/usr.bin/rcs/Makefile Wed May 6 23:52:15 2015 (r282572) @@ -0,0 +1,23 @@ +# $OpenBSD: Makefile,v 1.40 2010/10/15 08:44:12 tobias Exp $ + +PROG= rcs +MAN= ci.1 co.1 ident.1 merge.1 rcs.1 rcsclean.1 rcsdiff.1 rcsmerge.1 rlog.1 + +SRCS= ci.c co.c ident.c merge.c rcsclean.c rcsdiff.c rcsmerge.c rcsparse.c \ + rcsprog.c rlog.c rcsutil.c buf.c date.y diff.c diff3.c rcs.c rcsnum.c \ + rcstime.c worklist.c xmalloc.c + +LINKS= ${BINDIR}/rcs ${BINDIR}/ci ${BINDIR}/rcs ${BINDIR}/co \ + ${BINDIR}/rcs ${BINDIR}/ident ${BINDIR}/rcs ${BINDIR}/merge \ + ${BINDIR}/rcs ${BINDIR}/rcsclean ${BINDIR}/rcs ${BINDIR}/rcsdiff \ + ${BINDIR}/rcs ${BINDIR}/rcsmerge ${BINDIR}/rcs ${BINDIR}/rlog + +CPPFLAGS+=-I${.CURDIR} +CFLAGS+=-Wall +CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes +CFLAGS+=-Wmissing-declarations +CFLAGS+=-Wshadow -Wpointer-arith -Wcast-qual +CFLAGS+=-Wsign-compare +YFLAGS= + +.include Added: vendor/OpenBSD/dist/usr.bin/rcs/buf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/OpenBSD/dist/usr.bin/rcs/buf.c Wed May 6 23:52:15 2015 (r282572) @@ -0,0 +1,331 @@ +/* $OpenBSD: buf.c,v 1.24 2015/02/05 12:59:58 millert Exp $ */ +/* + * Copyright (c) 2003 Jean-Francois Brousseau + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "buf.h" +#include "xmalloc.h" +#include "worklist.h" + +#define BUF_INCR 128 + +struct buf { + /* buffer handle, buffer size, and data length */ + u_char *cb_buf; + size_t cb_size; + size_t cb_len; +}; + +#define SIZE_LEFT(b) (b->cb_size - b->cb_len) + +static void buf_grow(BUF *, size_t); + +/* + * Create a new buffer structure and return a pointer to it. This structure + * uses dynamically-allocated memory and must be freed with buf_free(), once + * the buffer is no longer needed. + */ +BUF * +buf_alloc(size_t len) +{ + BUF *b; + + b = xmalloc(sizeof(*b)); + /* Postpone creation of zero-sized buffers */ + if (len > 0) + b->cb_buf = xcalloc(1, len); + else + b->cb_buf = NULL; + + b->cb_size = len; + b->cb_len = 0; + + return (b); +} + +/* + * Open the file specified by and load all of its contents into a + * buffer. + * Returns the loaded buffer on success or NULL on failure. + * Sets errno on error. + */ +BUF * +buf_load(const char *path) +{ + int fd; + ssize_t ret; + size_t len; + u_char *bp; + struct stat st; + BUF *buf; + + buf = NULL; + + if ((fd = open(path, O_RDONLY, 0600)) == -1) + goto out; + + if (fstat(fd, &st) == -1) + goto out; + + if (st.st_size > SIZE_MAX) { + errno = EFBIG; + goto out; + } + buf = buf_alloc(st.st_size); + for (bp = buf->cb_buf; ; bp += (size_t)ret) { + len = SIZE_LEFT(buf); + ret = read(fd, bp, len); + if (ret == -1) { + int saved_errno; + + saved_errno = errno; + buf_free(buf); + buf = NULL; + errno = saved_errno; + goto out; + } else if (ret == 0) + break; + + buf->cb_len += (size_t)ret; + } + +out: + if (fd != -1) { + int saved_errno; + + /* We may want to preserve errno here. */ + saved_errno = errno; + (void)close(fd); + errno = saved_errno; + } + + return (buf); +} + +void +buf_free(BUF *b) +{ + if (b->cb_buf != NULL) + xfree(b->cb_buf); + xfree(b); +} + +/* + * Free the buffer 's structural information but do not free the contents + * of the buffer. Instead, they are returned and should be freed later using + * xfree(). + */ +void * +buf_release(BUF *b) +{ + void *tmp; + + tmp = b->cb_buf; + xfree(b); + return (tmp); +} + +u_char * +buf_get(BUF *b) +{ + return (b->cb_buf); +} + +/* + * Empty the contents of the buffer and reset pointers. + */ +void +buf_empty(BUF *b) +{ + memset(b->cb_buf, 0, b->cb_size); + b->cb_len = 0; +} + +/* + * Append a single character to the end of the buffer . + */ +void +buf_putc(BUF *b, int c) +{ + u_char *bp; + + if (SIZE_LEFT(b) == 0) + buf_grow(b, BUF_INCR); + bp = b->cb_buf + b->cb_len; + *bp = (u_char)c; + b->cb_len++; +} + +/* + * Append a string to the end of buffer . + */ +void +buf_puts(BUF *b, const char *str) +{ + buf_append(b, str, strlen(str)); +} + +/* + * Return u_char at buffer position . + */ +u_char +buf_getc(BUF *b, size_t pos) +{ + return (b->cb_buf[pos]); +} + +/* + * Append bytes of data pointed to by to the buffer . If the + * buffer is too small to accept all data, it will get resized to an + * appropriate size to accept all data. + * Returns the number of bytes successfully appended to the buffer. + */ +size_t +buf_append(BUF *b, const void *data, size_t len) +{ + size_t left, rlen; + u_char *bp; + + left = SIZE_LEFT(b); + rlen = len; + + if (left < len) + buf_grow(b, len - left); + bp = b->cb_buf + b->cb_len; + memcpy(bp, data, rlen); + b->cb_len += rlen; + + return (rlen); +} + +/* + * Returns the size of the buffer that is being used. + */ +size_t +buf_len(BUF *b) +{ + return (b->cb_len); +} + +/* + * Write the contents of the buffer to the specified + */ +int +buf_write_fd(BUF *b, int fd) +{ + u_char *bp; + size_t len; + ssize_t ret; + + len = b->cb_len; + bp = b->cb_buf; + + do { + ret = write(fd, bp, len); + if (ret == -1) { + if (errno == EINTR || errno == EAGAIN) + continue; + return (-1); + } + + len -= (size_t)ret; + bp += (size_t)ret; + } while (len > 0); + + return (0); +} + +/* + * Write the contents of the buffer to the file whose path is given in + * . If the file does not exist, it is created with mode . + */ +int +buf_write(BUF *b, const char *path, mode_t mode) +{ + int fd; + open: + if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)) == -1) { + if (errno == EACCES && unlink(path) != -1) + goto open; + else + err(1, "%s", path); + } + + if (buf_write_fd(b, fd) == -1) { + (void)unlink(path); + errx(1, "buf_write: buf_write_fd: `%s'", path); + } + + if (fchmod(fd, mode) < 0) + warn("permissions not set on file %s", path); + + (void)close(fd); + + return (0); +} + +/* + * Write the contents of the buffer to a temporary file whose path is + * specified using