All pastes #11056 Raw Edit

Mine

public c v1 · immutable
#11056 ·published 2005-05-05 19:20 UTC
rendered paste body
/*************************************************************************** *            cron_client.c * *  Wed May  4 20:03:01 2005 *  Copyright  2005  tw03d024 *  Email tw03d024@technikum-wien.at ****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <time.h>#include <string.h>#define KEY 0410257051#define PERM 0666#define MAX_DATA 255struct tm tm_now;typedef struct{long mType;char mText[MAX_DATA];} message_t;int main(int argc, char *argv[]){    message_t msg;    int msgid = -1;    char command[MAX_DATA];    int i;    char delim[] = ":";    char *token = NULL;    int new_hour;    int new_min;                if (argc < 2)    {      fprintf(stderr,"Usage: %s hh:mm program [arg1] [agr2...argn]\n",argv[0]);      return EXIT_FAILURE;      }   	for(i=2; i<argc; i++)	{		strcat(command, argv[i]);		strcat(command, " ");	}        token = strtok( argv[1], delim );    new_hour = atoi(token);        token = strtok( NULL, delim);    new_min = atoi(token);        tm_now.tm_hour = new_hour;    tm_now.tm_min = new_min;        mktime(&tm_now);        msg.mType = (long)tm_now;        /* Message Queue oeffnen */   if( (msgid = msgget(KEY,PERM))==-1 )   {      /* error handling */      fprintf(stderr,"%s: Can't access message queue\n",argv[0]);      return EXIT_FAILURE;      }	/*Kommandozeile ins struct schreiben*/	strncpy(msg.mText,command,MAX_DATA);		fprintf(stdout, "Message sent: %d %s\n", (int)msg.mType, msg.mText);	     /* Nachricht verschicken */     if (msgsnd(msgid,&msg,sizeof(msg)-sizeof(long),0) == -1)     {         /* error handling */         fprintf(stderr,"%s: Can't send message\n",argv[0]);         return EXIT_FAILURE;      }      fprintf(stdout, "Message sent: %d %s\n", (int)msg.mType, msg.mText);   return EXIT_SUCCESS;}