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