/**
* Function: Write to the /proc/myprocfile
* Author: Asanga Udugama (adu@comnets.uni-bremen.de)
* License: GPL
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#define MSG_SIZE	1024

int main(int argc, char *argv[])
{
  int fd;
  char buf[MSG_SIZE];
 
  if(argc != 2) {
    printf("usage : %s \"msg\" \n", argv[0]);
    exit(1);
  }
  if(strlen(argv[1]) > MSG_SIZE-1) {
    printf("Msg too large\n");
    exit(1);
  }

  fd = open("/proc/myprocfile", O_WRONLY);
  if(fd < 0) {
    printf("Cannot open\n");
    exit(1);
  }

  strcpy(buf, argv[1]);
  write(fd, buf, MSG_SIZE);
    
  close(fd);
}
 
