diff --git a/src/lib/commands/mobu.c b/src/lib/commands/mobu.c index 47a5d534..a368c196 100644 --- a/src/lib/commands/mobu.c +++ b/src/lib/commands/mobu.c @@ -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); diff --git a/src/lib/commands/rea.c b/src/lib/commands/rea.c index ffa97063..e1437794 100644 --- a/src/lib/commands/rea.c +++ b/src/lib/commands/rea.c @@ -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 } } } diff --git a/src/lib/commands/turn.c b/src/lib/commands/turn.c index b98edff5..0dd80caa 100644 --- a/src/lib/commands/turn.c +++ b/src/lib/commands/turn.c @@ -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); diff --git a/src/lib/commands/upda.c b/src/lib/commands/upda.c index 6f94b96f..94adc79a 100644 --- a/src/lib/commands/upda.c +++ b/src/lib/commands/upda.c @@ -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); diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 9d286d1d..e94b52c5 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -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]; diff --git a/src/lib/common/log.c b/src/lib/common/log.c index de7f8cd3..8419df7a 100644 --- a/src/lib/common/log.c +++ b/src/lib/common/log.c @@ -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); diff --git a/src/lib/gen/emp_config.c b/src/lib/gen/emp_config.c index 54b1ad96..e13736f7 100644 --- a/src/lib/gen/emp_config.c +++ b/src/lib/gen/emp_config.c @@ -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); } } diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index 2497ddb5..223eca94 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -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)"); diff --git a/src/lib/player/player.c b/src/lib/player/player.c index 0506e391..7f8514ad 100644 --- a/src/lib/player/player.c +++ b/src/lib/player/player.c @@ -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; } diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c index 292717ad..036d94e4 100644 --- a/src/lib/subs/wu.c +++ b/src/lib/subs/wu.c @@ -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; } diff --git a/src/lib/update/anno.c b/src/lib/update/anno.c index f7268364..b5b11823 100644 --- a/src/lib/update/anno.c +++ b/src/lib/update/anno.c @@ -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) diff --git a/src/server/main.c b/src/server/main.c index 95e401e7..6da52d3e 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -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(); diff --git a/src/server/timestamp.c b/src/server/timestamp.c index 6ad807ae..c85c80f8 100644 --- a/src/server/timestamp.c +++ b/src/server/timestamp.c @@ -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 {