(gamedown,show_motd): Change to stdio for reading motd and
down message. (gamedown): Change buf's size to be MAXTELSIZE instead of abitrary number. Make consistent with show_motd().
This commit is contained in:
parent
7afaedbfc1
commit
446d4ed394
2 changed files with 17 additions and 17 deletions
|
@ -152,33 +152,33 @@ explain(void)
|
|||
int
|
||||
gamedown(void)
|
||||
{
|
||||
int downf;
|
||||
FILE *down_fp;
|
||||
struct telstr tgm;
|
||||
s_char buf[1024];
|
||||
s_char buf[MAXTELSIZE];
|
||||
|
||||
if (player->god)
|
||||
return 0;
|
||||
if ((downf = open(downfil, O_RDONLY, 0)) < 0)
|
||||
if ((down_fp = fopen(downfil, "r")) == NULL)
|
||||
return 0;
|
||||
if (read(downf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) {
|
||||
if (fread((void *)&tgm, sizeof(tgm), 1, down_fp) != 1) {
|
||||
logerror("bad header on login message (downfil)");
|
||||
close(downf);
|
||||
fclose(down_fp);
|
||||
return 1;
|
||||
}
|
||||
if (tgm.tel_length >= (long)sizeof(buf)) {
|
||||
logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
|
||||
close(downf);
|
||||
fclose(down_fp);
|
||||
return 1;
|
||||
}
|
||||
if (read(downf, buf, tgm.tel_length) != tgm.tel_length) {
|
||||
if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
|
||||
logerror("bad length %ld on login message", tgm.tel_length);
|
||||
close(downf);
|
||||
fclose(down_fp);
|
||||
return 1;
|
||||
}
|
||||
buf[tgm.tel_length] = 0;
|
||||
prnf(buf);
|
||||
pr("\nThe game is down\n");
|
||||
(void)close(downf);
|
||||
fclose(down_fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -343,11 +343,11 @@ execute(void)
|
|||
int
|
||||
show_motd(void)
|
||||
{
|
||||
int motdf;
|
||||
FILE *motd_fp;
|
||||
struct telstr tgm;
|
||||
char buf[MAXTELSIZE];
|
||||
|
||||
if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
|
||||
if ((motd_fp = fopen(motdfil, "r")) == NULL)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
return RET_OK;
|
||||
|
@ -358,24 +358,24 @@ show_motd(void)
|
|||
return RET_SYS;
|
||||
}
|
||||
}
|
||||
if (read(motdf, &tgm, sizeof(tgm)) != sizeof(tgm)) {
|
||||
if (fread((void *)&tgm, sizeof(tgm), 1, motd_fp) != 1) {
|
||||
logerror("bad header on login message (motdfil)");
|
||||
close(motdf);
|
||||
fclose(motd_fp);
|
||||
return RET_FAIL;
|
||||
}
|
||||
if (tgm.tel_length >= (long)sizeof(buf)) {
|
||||
logerror("text length (%ld) is too long for login message (motdfil)", tgm.tel_length);
|
||||
close(motdf);
|
||||
fclose(motd_fp);
|
||||
return RET_FAIL;
|
||||
}
|
||||
if (read(motdf, buf, tgm.tel_length) != tgm.tel_length) {
|
||||
if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) {
|
||||
logerror("bad length %ld on login message", tgm.tel_length);
|
||||
close(motdf);
|
||||
fclose(motd_fp);
|
||||
return RET_FAIL;
|
||||
}
|
||||
buf[tgm.tel_length] = 0;
|
||||
prnf(buf);
|
||||
(void)close(motdf);
|
||||
fclose(motd_fp);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue