-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgsnd_report_record.c
84 lines (67 loc) · 2.1 KB
/
msgsnd_report_record.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "report_record_formats.h"
#include "queue_ids.h"
#ifndef darwin
size_t /* O - Length of string */
strlcpy(char *dst, /* O - Destination string */
const char *src, /* I - Source string */
size_t size) /* I - Size of destination string buffer */
{
size_t srclen; /* Length of source string */
/*
* Figure out how much room is needed...
*/
size --;
srclen = strlen(src);
/*
* Copy the appropriate amount...
*/
if (srclen > size)
srclen = size;
memcpy(dst, src, srclen);
dst[srclen] = '\0';
return (srclen);
}
#endif
int main(int argc, char**argv)
{
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
report_record_buf sbuf;
size_t buf_length;
key = ftok(FILE_IN_HOME_DIR,1);
if (key == 0xffffffff) {
fprintf(stderr,"Key cannot be 0xffffffff..fix queue_ids.h to link to existing file\n");
return 1;
}
if ((msqid = msgget(key, msgflg)) < 0) {
int errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("(msgget)");
fprintf(stderr, "Error msgget: %s\n", strerror( errnum ));
}
else
fprintf(stderr, "msgget: msgget succeeded: msgqid = %d\n", msqid);
// We'll send message type 2
sbuf.mtype = 2;
strcpy(sbuf.record,"09/22/21 Wipers Purchas H Peck NA $36 0 $0 $36 ");
buf_length = strlen(sbuf.record) + sizeof(int)+1;//struct size without mtype
// Send a message.
if((msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT)) < 0) {
int errnum = errno;
fprintf(stderr,"%d, %ld, %s, %d\n", msqid, sbuf.mtype, sbuf.record, (int)buf_length);
perror("(msgsnd)");
fprintf(stderr, "Error sending msg: %s\n", strerror( errnum ));
exit(1);
}
else
fprintf(stderr,"msgsnd-report_record: record\"%s\" Sent (%d bytes)\n", sbuf.record,(int)buf_length);
exit(0);
}