freebsd-dev/share/examples/sunrpc/msg/printmsg.c

46 lines
753 B
C
Raw Normal View History

1994-08-07 18:50:51 +00:00
/* @(#)printmsg.c 2.1 88/08/11 4.0 RPCSRC */
/* $FreeBSD$ */
1994-08-07 18:50:51 +00:00
/*
* printmsg.c: print a message on the console
*/
#include <paths.h>
1994-08-07 18:50:51 +00:00
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
char *message;
if (argc < 2) {
fprintf(stderr, "usage: %s <message>\n", argv[0]);
exit(1);
}
message = argv[1];
if (!printmessage(message)) {
fprintf(stderr, "%s: sorry, couldn't print your message\n",
argv[0]);
exit(1);
1995-05-30 06:58:14 +00:00
}
1994-08-07 18:50:51 +00:00
printf("Message delivered!\n");
}
/*
* Print a message to the console.
* Return a boolean indicating whether the message was actually printed.
*/
printmessage(msg)
char *msg;
{
FILE *f;
f = fopen(_PATH_CONSOLE, "w");
1994-08-07 18:50:51 +00:00
if (f == NULL) {
return (0);
}
fprintf(f, "%s\n", msg);
fclose(f);
return(1);
}