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