aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2009-04-11 14:33:10 +0000
committerEd Schouten <ed@FreeBSD.org>2009-04-11 14:33:10 +0000
commit18a064438f020ec9358c33efdfc172cd04bdff38 (patch)
tree38ddd17e8d35b3694d4b5319f1d80d3de4c2b952 /sbin
parente532d3fafa72831d35def8970d5d0f48152236eb (diff)
downloadsrc-18a064438f020ec9358c33efdfc172cd04bdff38.tar.gz
src-18a064438f020ec9358c33efdfc172cd04bdff38.zip
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>
Notes
Notes: svn path=/head/; revision=190929
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs_msdos/newfs_msdos.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c
index cccc9e9402c6..0b787717037e 100644
--- a/sbin/newfs_msdos/newfs_msdos.c
+++ b/sbin/newfs_msdos/newfs_msdos.c
@@ -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);