#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#define MAX_CNT 10
#define MAXTIX (24*60)
int l_xupdate(int xfds, char *a1, char *a2);
struct xxxidx
{
int recs; // record size
int recn[MAXTIX]; // Starting Record of HHMM
};
struct biglotTrade
{
char symbol[20];
char orderbookid[12];
long biglotOrderQty; //VOLUME
int biglotSequence;
long biglotTotalVolumeTraded; //TOTAL VOLUME
double biglotTurnover; //AMT
int typeOfTrade; //CASE 1 NEW, CASE 2 CANCEL(MUST)
double doubleprice;
double totalTurnoverTradeReport; //TOTAL AMT
char tradeId[30];
char dealId[30];
};
char DNS_PACKET[55][2][100] = {
{"TN-1-1508147706984-2","DN-1-1508147706984-1"},
{"TN-1-1508147696497-2","DN-1-1508147696497-1"},
{"TN-1-1508147685915-2","DN-1-1508147685915-1"},
{"TN-1-1508147668355-2","DN-1-1508147668355-1"},
{"TN-1-1508147651212-2","DN-1-1508147651212-1"},
{"TN-1-1508147637492-2","DN-1-1508147637492-1"},
{"TN-1-1508147635403-2","DN-1-1508147635403-1"},
{"TN-1-1508147624602-3","DN-1-1508147624602-2"},
{"TN-1-1508147579369-3","DN-1-1508147579369-2"},
{"TN-1-1508147553972-2","DN-1-1508147553972-1"}};
int main(int argc, char *argv[])
{
struct biglotTrade biglottrade[500];
int xxfd;
char xfile[32];
int ii, jj, cnt, rc;
sprintf(xfile, "%.20s", "BIGLOT");
xxfd = l_xopen(SAMFILE_PATH, xfile, O_RDWR); //FOR UPDATE, RDWR NEEDED!!
if (xxfd < 0)
{
printf("Can't open BIGLOT file [%s][%s]. errno(%d)\n", DAT_JC_PATH, xfile, errno);
return(-1)
}
for (jj = 0; jj < MAX_CNT; jj++)
{
rc = l_xupdate(xxfd, DNS_PACKET[jj][0], DNS_PACKET[jj][1]);
if(rc)
{
printf("l_xupdate fail!!\n");
return(-1);
}
}
close(xxfd);
return 0;
}
int l_xupdate(int xfds, char *a1, char *a2)
{
struct xxxidx xxxidx;
struct biglotTrade *tmpdjd;
int rlen, wlen;
int xsiz;
int maxr;
int ii, cnt;
long xoff;
char buff[1024 * 100];
lseek(xfds, 0L, SEEK_SET);
rlen = read(xfds, &xxxidx, sizeof(struct xxxidx));
if (rlen != sizeof(struct xxxidx))
{
printf("rlen failed\n");
return -1;
}
xsiz = xxxidx.recs;
xoff = lseek(xfds, 0L, SEEK_END);
maxr = (xoff - sizeof(struct xxxidx)) / xsiz;
if (maxr <= 0) {
printf("maxr failed\n");
return -1;
}
xoff = sizeof(struct xxxidx);
cnt = lseek(xfds, xoff, SEEK_SET);
for (ii = 0; ii < maxr ; ii++)
{
rlen = read(xfds, buff, xsiz);
tmpdjd = (struct biglotTrade *)buff;
if (strcmp(tmpdjd->tradeId,a1)==0 &&
strcmp(tmpdjd->dealId,a2)==0)
{
xoff = sizeof(struct xxxidx) + (ii * xsiz);
cnt = lseek(xfds, xoff, SEEK_SET);
tmpdjd->typeOfTrade = 1; //UPDATE DATA
wlen = write(xfds, tmpdjd, sizeof(struct biglotTrade));
printf("wlen = %d\n", wlen);
break;
}
}
return 0;
}
'c 언어 > 고급과정' 카테고리의 다른 글
Firebase : Send notification with REST API(common.c) (0) | 2019.10.30 |
---|---|
Firebase : Send notification with REST API(sample.c) (0) | 2019.10.30 |
WINDOWS,LINUX,Firebase Cloud Messaging (0) | 2019.10.30 |
LINUX, Curl + Encrypt(AES 128) + Decrypt(AES 128) + Json Parse (0) | 2019.10.30 |
마우스위치 저장및 재생(WIN32-API) (0) | 2019.10.29 |