From owner-svn-src-all@FreeBSD.ORG Sat Apr 11 14:33:10 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7EA061065674; Sat, 11 Apr 2009 14:33:10 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6D6E18FC19; Sat, 11 Apr 2009 14:33:10 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n3BEXAgj089074; Sat, 11 Apr 2009 14:33:10 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n3BEXAbr089073; Sat, 11 Apr 2009 14:33:10 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200904111433.n3BEXAbr089073@svn.freebsd.org> From: Ed Schouten Date: Sat, 11 Apr 2009 14:33:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190929 - head/sbin/newfs_msdos X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Sat, 11 Apr 2009 14:33:11 -0000 Author: ed Date: Sat Apr 11 14:33:10 2009 New Revision: 190929 URL: http://svn.freebsd.org/changeset/base/190929 Log: Use ftruncate() instead of lseek()+write()+lseek() to set the created file (-C) to the requested size. Submitted by: Christoph Mallon Modified: head/sbin/newfs_msdos/newfs_msdos.c Modified: head/sbin/newfs_msdos/newfs_msdos.c ============================================================================== --- head/sbin/newfs_msdos/newfs_msdos.c Sat Apr 11 14:25:47 2009 (r190928) +++ head/sbin/newfs_msdos/newfs_msdos.c Sat Apr 11 14:33:10 2009 (r190929) @@ -356,17 +356,13 @@ main(int argc, char *argv[]) } dtype = *argv; if (opt_create) { - off_t pos; - if (opt_N) errx(1, "create (-C) is incompatible with -N"); fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd == -1) errx(1, "failed to create %s", fname); - pos = lseek(fd, opt_create - 1, SEEK_SET); - if (write(fd, "\0", 1) != 1) + if (ftruncate(fd, opt_create)) errx(1, "failed to initialize %jd bytes", (intmax_t)opt_create); - pos = lseek(fd, 0, SEEK_SET); } else if ((fd = open(fname, opt_N ? O_RDONLY : O_RDWR)) == -1 || fstat(fd, &sb)) err(1, "%s", fname);