1944fcc15SGarrett Wollman /* @(#)printmsg.c 2.1 88/08/11 4.0 RPCSRC */ 2944fcc15SGarrett Wollman /* 3944fcc15SGarrett Wollman * printmsg.c: print a message on the console 4944fcc15SGarrett Wollman */ 5944fcc15SGarrett Wollman #include <stdio.h> 6944fcc15SGarrett Wollman 7944fcc15SGarrett Wollman main(argc, argv) 8944fcc15SGarrett Wollman int argc; 9944fcc15SGarrett Wollman char *argv[]; 10944fcc15SGarrett Wollman { 11944fcc15SGarrett Wollman char *message; 12944fcc15SGarrett Wollman 13944fcc15SGarrett Wollman if (argc < 2) { 14944fcc15SGarrett Wollman fprintf(stderr, "usage: %s <message>\n", argv[0]); 15944fcc15SGarrett Wollman exit(1); 16944fcc15SGarrett Wollman } 17944fcc15SGarrett Wollman message = argv[1]; 18944fcc15SGarrett Wollman 19944fcc15SGarrett Wollman if (!printmessage(message)) { 20944fcc15SGarrett Wollman fprintf(stderr, "%s: sorry, couldn't print your message\n", 21944fcc15SGarrett Wollman argv[0]); 22944fcc15SGarrett Wollman exit(1); 23944fcc15SGarrett Wollman } 24944fcc15SGarrett Wollman printf("Message delivered!\n"); 25944fcc15SGarrett Wollman } 26944fcc15SGarrett Wollman 27944fcc15SGarrett Wollman /* 28944fcc15SGarrett Wollman * Print a message to the console. 29944fcc15SGarrett Wollman * Return a boolean indicating whether the message was actually printed. 30944fcc15SGarrett Wollman */ 31944fcc15SGarrett Wollman printmessage(msg) 32944fcc15SGarrett Wollman char *msg; 33944fcc15SGarrett Wollman { 34944fcc15SGarrett Wollman FILE *f; 35944fcc15SGarrett Wollman 36944fcc15SGarrett Wollman f = fopen("/dev/console", "w"); 37944fcc15SGarrett Wollman if (f == NULL) { 38944fcc15SGarrett Wollman return (0); 39944fcc15SGarrett Wollman } 40944fcc15SGarrett Wollman fprintf(f, "%s\n", msg); 41944fcc15SGarrett Wollman fclose(f); 42944fcc15SGarrett Wollman return(1); 43944fcc15SGarrett Wollman } 44