fsync.c revision 78717
163499Sps/*-
263499Sps * Copyright (c) 2000 Paul Saab <ps@FreeBSD.org>
363499Sps * All rights reserved.
463499Sps *
563499Sps * Redistribution and use in source and binary forms, with or without
663499Sps * modification, are permitted provided that the following conditions
763499Sps * are met:
863499Sps * 1. Redistributions of source code must retain the above copyright
963499Sps *    notice, this list of conditions and the following disclaimer.
1063499Sps * 2. Redistributions in binary form must reproduce the above copyright
1163499Sps *    notice, this list of conditions and the following disclaimer in the
1263499Sps *    documentation and/or other materials provided with the distribution.
1363499Sps *
1463499Sps * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1563499Sps * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1663499Sps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1763499Sps * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1863499Sps * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1963499Sps * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2063499Sps * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2163499Sps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2263499Sps * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2363499Sps * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2463499Sps * SUCH DAMAGE.
2563499Sps */
2663499Sps
2763812Sps#ifndef lint
2863812Spsstatic const char rcsid[] =
2963812Sps  "$FreeBSD: head/usr.bin/fsync/fsync.c 78717 2001-06-24 19:41:18Z dd $";
3063812Sps#endif /* not lint */
3163812Sps
3263499Sps#include <err.h>
3363499Sps#include <fcntl.h>
3463499Sps#include <stdio.h>
3578717Sdd#include <stdlib.h>
3663499Sps#include <sysexits.h>
3763499Sps#include <unistd.h>
3863499Sps
3963499Spsvoid	usage(void);
4063499Sps
4163499Spsint
4263499Spsmain(int argc, char *argv[])
4363499Sps{
4463499Sps	int fd;
4563499Sps	int i;
4663499Sps
4763499Sps	if (argc < 2)
4863499Sps		usage();
4963499Sps
5063499Sps	for (i = 1; i < argc; ++i) {
5163499Sps		if ((fd = open(argv[i], O_RDONLY)) < 0)
5263499Sps			err(1, "open %s", argv[i]);
5363499Sps
5463499Sps		if (fsync(fd) != 0)
5563499Sps			err(1, "fsync %s", argv[1]);
5663499Sps		close(fd);
5763499Sps	}
5863499Sps	return(0);
5963499Sps}
6063499Sps
6163499Spsvoid
6263499Spsusage()
6363499Sps{
6463812Sps	fprintf(stderr, "usage: fsync file ...\n");
6563499Sps	exit(EX_USAGE);
6663499Sps}
67