(main,mobility_check,upda,turn,rea,mobupdate,ef_open,logerror,
emp_config,gamedown,show_motd,match_user,typed_wu, delete_old_announcements) [_WIN32]: switch the default file mode to binary to match POSIX. Remove the now unneccessary ifdef for the open/fopen. Add text mode for user files (econfig/auth).
This commit is contained in:
parent
f6e78f4589
commit
1a8488bc45
13 changed files with 14 additions and 65 deletions
|
@ -61,11 +61,7 @@ mobupdate(void)
|
|||
else
|
||||
minites = atol(player->argp[1]) * 60;
|
||||
time(&now);
|
||||
#if !defined(_WIN32)
|
||||
if ((fp = fopen(timestampfil, "r+")) == NULL) {
|
||||
#else
|
||||
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
|
||||
#endif
|
||||
logerror("Unable to edit timestamp file.");
|
||||
} else {
|
||||
rewind(fp);
|
||||
|
|
|
@ -100,11 +100,7 @@ rea(void)
|
|||
clear_telegram_is_new(player->cnum);
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
if ((telfp = fopen(mbox, "r+")) == 0) {
|
||||
#else
|
||||
if ((telfp = fopen(mbox, "r+b")) == 0) {
|
||||
#endif
|
||||
logerror("telegram file %s", mbox);
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
@ -208,11 +204,7 @@ rea(void)
|
|||
/* Here, we just re-open the file for "w" only,
|
||||
and that will wipe the file clean automatically */
|
||||
(void)fclose(telfp);
|
||||
#if !defined(_WIN32)
|
||||
telfp = fopen((char *)mbox, "w");
|
||||
#else
|
||||
telfp = fopen((char *)mbox, "wb");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,11 +95,7 @@ turn(void)
|
|||
pr("Writing empty no-login message.\n");
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC, 0660);
|
||||
#else
|
||||
fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
|
||||
#endif
|
||||
if (fd == -1) {
|
||||
pr("Something went wrong opening the message file.\n");
|
||||
logerror("Could not open message file (%s).\n", msgfilepath);
|
||||
|
|
|
@ -51,13 +51,9 @@ upda(void)
|
|||
struct mob_acc_globals timestamps;
|
||||
|
||||
if (opt_MOB_ACCESS) {
|
||||
#if !defined(_WIN32)
|
||||
if ((fp = fopen(timestampfil, "r")) == NULL) {
|
||||
#else
|
||||
if ((fp = fopen(timestampfil, "rb")) == NULL) {
|
||||
#endif
|
||||
if ((fp = fopen(timestampfil, "r")) == NULL)
|
||||
logerror("Unable to open timestamp file.");
|
||||
} else {
|
||||
else {
|
||||
rewind(fp);
|
||||
fread(×tamps, sizeof(timestamps), 1, fp);
|
||||
fclose(fp);
|
||||
|
|
|
@ -60,9 +60,6 @@ ef_open(int type, int mode, int how)
|
|||
static int block;
|
||||
int size;
|
||||
|
||||
#if defined(_WIN32)
|
||||
mode |= _O_BINARY;
|
||||
#endif
|
||||
if (ef_check(type) < 0)
|
||||
return 0;
|
||||
ep = &empfile[type];
|
||||
|
|
|
@ -56,11 +56,7 @@ loginit(s_char *program)
|
|||
{
|
||||
s_char buf[1024];
|
||||
|
||||
#if !defined(_WIN32)
|
||||
sprintf(buf, "%s/%s.log", datadir, program);
|
||||
#else
|
||||
sprintf(buf, "%s\\%s.log", datadir, program);
|
||||
#endif
|
||||
logfile = malloc(strlen(buf) + 1);
|
||||
strcpy(logfile, buf);
|
||||
}
|
||||
|
@ -86,7 +82,11 @@ logerror(s_char *format, ...)
|
|||
if ((p = strchr(cbuf, '\n')) != 0)
|
||||
*p = 0;
|
||||
(void)sprintf(buf1, "%s %s\n", cbuf, buf);
|
||||
#if defined(_WIN32)
|
||||
if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_TEXT, 0666)) < 0)
|
||||
#else
|
||||
if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0)
|
||||
#endif
|
||||
return;
|
||||
(void)write(logf, buf1, strlen(buf1));
|
||||
(void)close(logf);
|
||||
|
|
|
@ -92,7 +92,7 @@ emp_config(char *file)
|
|||
fixup_files();
|
||||
return 0;
|
||||
}
|
||||
if ((fp = fopen(file, "r")) == NULL) {
|
||||
if ((fp = fopen(file, "rt")) == NULL) {
|
||||
fprintf(stderr, "Can't open %s for reading (%s)\n",
|
||||
file, strerror(errno));
|
||||
return -1;
|
||||
|
@ -181,11 +181,7 @@ static struct otherfiles ofiles[] = {
|
|||
{&annfil, "ann"},
|
||||
{×tampfil, "timestamp"},
|
||||
{&teldir, "tel"},
|
||||
#if !defined(_WIN32)
|
||||
{&telfil, "tel/tel"},
|
||||
#else
|
||||
{&telfil, "tel\\tel"},
|
||||
#endif
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -198,20 +194,12 @@ fixup_files(void)
|
|||
s_char buf[1024];
|
||||
|
||||
for (ep = empfile; ep < &empfile[EF_MAX]; ep++) {
|
||||
#if !defined(_WIN32)
|
||||
sprintf(buf, "%s/%s", datadir, ep->name);
|
||||
#else
|
||||
sprintf(buf, "%s\\%s", datadir, ep->name);
|
||||
#endif
|
||||
ep->file = strdup(buf);
|
||||
}
|
||||
|
||||
for (op = ofiles; op->files; op++) {
|
||||
#if !defined(_WIN32)
|
||||
sprintf(buf, "%s/%s", datadir, op->name);
|
||||
#else
|
||||
sprintf(buf, "%s\\%s", datadir, op->name);
|
||||
#endif
|
||||
*op->files = strdup(buf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,11 +158,7 @@ gamedown(void)
|
|||
|
||||
if (player->god)
|
||||
return 0;
|
||||
#if !defined(_WIN32)
|
||||
if ((downf = open(downfil, O_RDONLY, 0)) < 0)
|
||||
#else
|
||||
if ((downf = open(downfil, O_RDONLY | O_BINARY, 0)) < 0)
|
||||
#endif
|
||||
return 0;
|
||||
if (read(downf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) {
|
||||
logerror("bad header on login message (downfil)");
|
||||
|
|
|
@ -347,11 +347,7 @@ show_motd(void)
|
|||
struct telstr tgm;
|
||||
char buf[MAXTELSIZE];
|
||||
|
||||
#if !defined(_WIN32)
|
||||
if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
|
||||
#else
|
||||
if ((motdf = open(motdfil, O_RDONLY | O_BINARY, 0)) < 0)
|
||||
#endif
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
return RET_OK;
|
||||
|
@ -388,7 +384,7 @@ match_user(char *file, struct player *p)
|
|||
char host[256];
|
||||
char user[256];
|
||||
|
||||
if ((fp = fopen(file, "r")) == NULL) {
|
||||
if ((fp = fopen(file, "rt")) == NULL) {
|
||||
/*logerror("Cannot find file %s", file); */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -125,11 +125,7 @@ typed_wu(natid from, natid to, s_char *message, int type)
|
|||
(np->nat_stat & STAT_SANCT) == 0)) {
|
||||
return -1;
|
||||
}
|
||||
#if !defined(_WIN32)
|
||||
if ((fd = open(box, O_WRONLY | O_APPEND, 0)) < 0) {
|
||||
#else
|
||||
if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) {
|
||||
#endif
|
||||
logerror("telegram 'open' of %s (#%d) failed", box, to);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -65,12 +65,12 @@ delete_old_announcements(void)
|
|||
old = now - days(anno_keep_days);
|
||||
logerror("Deleting annos older than %s", ctime(&old));
|
||||
|
||||
if ((annfp = fopen(annfil, "rb")) == NULL) {
|
||||
if ((annfp = fopen(annfil, "r")) == NULL) {
|
||||
logerror("can't open telegram file %s for reading", annfil);
|
||||
return;
|
||||
}
|
||||
sprintf(tmp_filename, "%s.tmp", annfil);
|
||||
if ((tmpfp = fopen(tmp_filename, "wb")) == NULL) {
|
||||
if ((tmpfp = fopen(tmp_filename, "w")) == NULL) {
|
||||
logerror("can't open telegram file %s for writing",
|
||||
tmp_filename);
|
||||
if (fclose(annfp) != 0)
|
||||
|
|
|
@ -112,6 +112,10 @@ main(int argc, char **argv)
|
|||
char *config_file = NULL;
|
||||
s_char tbuf[256];
|
||||
|
||||
#if defined(_WIN32)
|
||||
_fmode = _O_BINARY;
|
||||
#endif
|
||||
|
||||
loginit("server");
|
||||
|
||||
mainpid = getpid();
|
||||
|
|
|
@ -52,11 +52,7 @@ mobility_check(void *unused)
|
|||
while (1) {
|
||||
time(&now);
|
||||
/* logerror("Updating timestamp file at %s", ctime(&now));*/
|
||||
#if !defined(_WIN32)
|
||||
if ((fp = fopen(timestampfil, "r+")) == NULL) {
|
||||
#else
|
||||
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
|
||||
#endif
|
||||
logerror("Unable to edit timestamp file.");
|
||||
continue;
|
||||
}
|
||||
|
@ -101,11 +97,7 @@ mobility_init(void)
|
|||
mobility */
|
||||
|
||||
time(&now);
|
||||
#if !defined(_WIN32)
|
||||
if ((fp = fopen(timestampfil, "r+")) == NULL) {
|
||||
#else
|
||||
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
|
||||
#endif
|
||||
logerror("Unable to edit timestamp file.");
|
||||
/* FIXME safe to continue? */
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue