Date: Sat, 11 Apr 2009 14:33:10 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r190929 - head/sbin/newfs_msdos Message-ID: <200904111433.n3BEXAbr089073@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <christoph mallon gmx de> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904111433.n3BEXAbr089073>