-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog1.c
81 lines (72 loc) · 1.35 KB
/
log1.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define BuffNum 1024
char g_cMsgbuf[BuffNum] = {0};
int g_itime = 0;
char g_cbuf[512] = {0};
FILE *fp;
int g_iCnt = 0;
int iWriteRemindTime()
{
fseek(fp, 0, SEEK_SET);
snprintf(g_cbuf, sizeof(g_cbuf), "remined time:%d\n", g_itime);
fputs(g_cbuf, fp);
printf("Write TIME: %s\n",g_cbuf);
fflush(fp);
return 0;
}
int iWriteNtpMsg()
{
iWriteRemindTime();
snprintf(g_cMsgbuf+strlen(g_cMsgbuf),sizeof(g_cMsgbuf), "ntp messge time :%d\n", g_itime);
fputs(g_cMsgbuf, fp);
fflush(fp);
if(g_iCnt < 5)
g_iCnt++;
return 0;
}
int iReadNtpMsg()//char * _Msgbuf)
{
int i;
char buf[BuffNum] = {0};
fseek(fp, 0, SEEK_SET);
fgets(buf, BuffNum, fp);
if(g_iCnt >= 5)
{
fgets(g_cMsgbuf, BuffNum, fp);
}
memset(g_cMsgbuf,0,sizeof(g_cMsgbuf));
for(i=0; i<5; i++)
{
if(fgets(g_cMsgbuf+strlen(g_cMsgbuf), BuffNum, fp) == NULL)
{
printf("Read NONE%d:%s\n",i,g_cMsgbuf);
break;
}
else
{
printf("Read%d :%s\n",i,g_cMsgbuf);
}
}
return 0;
}
int main()
{
fp = fopen("logMsg","w+");
if(fp == NULL)
{
printf("file open err\n");
return -1;
}
while (1)
{
sleep(5);
//printf("sizeof g_cBuf:%d", g_cbuf);
g_itime++;
iReadNtpMsg();
iWriteNtpMsg();
}
fclose(fp);
}