Linux上的一个简单的多人聊天室(二)

2014-11-24 08:39:37 来源: 作者: 浏览: 5
e_now));
}
int i_lseek(int fd, off_t size, int position)
{
if (-1 == lseek(fd, size, position))
{
perror("seek error");
exit(1);
}
return(0);
}
int i_saveto_chat(struct msg *pmsg)
{
struct chat_history hstr;



bzero(&hstr, HSTR_LEN);
count = count + 1;
hstr.count =count;
hstr.from = pmsg->id_from;
hstr.to = pmsg->id_to;
strncpy(hstr.content, pmsg->content, CNTNT_LEN);
strncpy(hstr.time, i_get_time(), 25);


i_lseek(mainfd, 0, SEEK_END);


i_write(mainfd, &hstr, HSTR_LEN);


return(0);
}


int i_print_history(int len, int i)
{
struct chat_history chat_reader;
int j;
int position;

bzero(&chat_reader, HSTR_LEN);
if (i != 0)
{
position = len*i*HSTR_LEN;
i_lseek(mainfd, position, SEEK_END);
}
else
{
position = len*i*HSTR_LEN;


i_lseek(mainfd, HSTR_LEN, SEEK_SET);
}

for (j = 1; j <= len; j++)
{

i_read(mainfd, &chat_reader, HSTR_LEN);
printf("\n#item%d:id%dto id%d \n", j,
chat_reader.from, chat_reader.to);
i_print(chat_reader.content, CNTNT_LEN);
printf("\n Time:%s\n", chat_reader.time);
}


return(0);
}


#endif


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: