fsync.c revision 63812
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 63812 2000-07-24 20:35:19Z ps $"; 3063812Sps#endif /* not lint */ 3163812Sps 3263499Sps#include <err.h> 3363499Sps#include <fcntl.h> 3463499Sps#include <stdio.h> 3563499Sps#include <sysexits.h> 3663499Sps#include <unistd.h> 3763499Sps 3863499Spsvoid usage(void); 3963499Sps 4063499Spsint 4163499Spsmain(int argc, char *argv[]) 4263499Sps{ 4363499Sps int fd; 4463499Sps int i; 4563499Sps 4663499Sps if (argc < 2) 4763499Sps usage(); 4863499Sps 4963499Sps for (i = 1; i < argc; ++i) { 5063499Sps if ((fd = open(argv[i], O_RDONLY)) < 0) 5163499Sps err(1, "open %s", argv[i]); 5263499Sps 5363499Sps if (fsync(fd) != 0) 5463499Sps err(1, "fsync %s", argv[1]); 5563499Sps close(fd); 5663499Sps } 5763499Sps return(0); 5863499Sps} 5963499Sps 6063499Spsvoid 6163499Spsusage() 6263499Sps{ 6363812Sps fprintf(stderr, "usage: fsync file ...\n"); 6463499Sps exit(EX_USAGE); 6563499Sps} 66