xref: /dragonfly/share/examples/sunrpc/msg/printmsg.c (revision d4ef6694)
1 /* @(#)printmsg.c	2.1 88/08/11 4.0 RPCSRC */
2 /* $FreeBSD: src/share/examples/sunrpc/msg/printmsg.c,v 1.2.12.1 2000/12/11 01:03:27 obrien Exp $ */
3 /* $DragonFly: src/share/examples/sunrpc/msg/printmsg.c,v 1.2 2003/06/17 04:36:58 dillon Exp $ */
4 /*
5  * printmsg.c: print a message on the console
6  */
7 #include <paths.h>
8 #include <stdio.h>
9 
10 main(argc, argv)
11 	int argc;
12 	char *argv[];
13 {
14 	char *message;
15 
16 	if (argc < 2) {
17 		fprintf(stderr, "usage: %s <message>\n", argv[0]);
18 		exit(1);
19 	}
20 	message = argv[1];
21 
22 	if (!printmessage(message)) {
23 		fprintf(stderr, "%s: sorry, couldn't print your message\n",
24 			argv[0]);
25 		exit(1);
26 	}
27 	printf("Message delivered!\n");
28 }
29 
30 /*
31  * Print a message to the console.
32  * Return a boolean indicating whether the message was actually printed.
33  */
34 printmessage(msg)
35 	char *msg;
36 {
37 	FILE *f;
38 
39 	f = fopen(_PATH_CONSOLE, "w");
40 	if (f == NULL) {
41 		return (0);
42 	}
43 	fprintf(f, "%s\n", msg);
44 	fclose(f);
45 	return(1);
46 }
47