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