Path: blob/main/share/examples/sunrpc/msg/printmsg.c
39530 views
/*1* printmsg.c: print a message on the console2*/3#include <paths.h>4#include <stdio.h>56main(argc, argv)7int argc;8char *argv[];9{10char *message;1112if (argc < 2) {13fprintf(stderr, "usage: %s <message>\n", argv[0]);14exit(1);15}16message = argv[1];1718if (!printmessage(message)) {19fprintf(stderr, "%s: sorry, couldn't print your message\n",20argv[0]);21exit(1);22}23printf("Message delivered!\n");24}2526/*27* Print a message to the console.28* Return a boolean indicating whether the message was actually printed.29*/30printmessage(msg)31char *msg;32{33FILE *f;3435f = fopen(_PATH_CONSOLE, "w");36if (f == NULL) {37return (0);38}39fprintf(f, "%s\n", msg);40fclose(f);41return(1);42}434445