File: fdflush.c

package info (click to toggle)
fdflush 1.0.1-5
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 40 kB
  • ctags: 12
  • sloc: makefile: 47; ansic: 31; sh: 16
file content (44 lines) | stat: -rw-r--r-- 796 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Floppy-disk buffer flush program.
 * Copyright (C) 1995 Bruce Perens
 * This program is free software under the GNU General Public License
 */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fd.h>

static const char	fd0[] = "/dev/fd0";

int
main(int argc, char * * argv)
{
	const char *	floppy = fd0;
	int		fd;

	if ( argc == 2 )
		floppy = argv[1];
	else if ( argc > 2 ) {
	    fprintf(stderr, "usage: fdflush [device]\n");
	    return 1;
	}

	fd = open(floppy, O_RDONLY);

	if ( fd < 0 ) {
		fprintf(stderr, "%s: %s.\n", floppy, strerror(errno));
		return -1;
	}

	if ( ioctl(fd, FDFLUSH, 0) != 0 ) {
		fprintf(stderr, "%s: fdflush: %s.\n", floppy, strerror(errno));
		close(fd);
		return -1;
	}

	close(fd);

	return 0;
}