diff --git a/src/doconfig/doconfig.c b/src/doconfig/doconfig.c index 1ed98914..1779e697 100644 --- a/src/doconfig/doconfig.c +++ b/src/doconfig/doconfig.c @@ -88,10 +88,6 @@ main(void) char *cp; char *pathname; -#if defined(_WIN32) - _fmode = _O_BINARY; -#endif - if ((pathname = safe_getcwd()) == NULL) { printf("Can't get current path!\n"); exit(-1); @@ -141,7 +137,7 @@ wrmakesrc(char *pathname) char buf[256]; sprintf(buf, "%s/src/make.src", pathname); - if ((fp = fopen(buf, "w")) == NULL) { + if ((fp = fopen(buf, "wb")) == NULL) { printf("Cannot open %s for writing, exiting.\n", buf); exit(-1); } @@ -158,7 +154,7 @@ wripglob(char *filename) FILE *fp; printf("Writing %s\n", filename); - if ((fp = fopen(filename, "w")) == NULL) { + if ((fp = fopen(filename, "wb")) == NULL) { printf("Cannot open %s for writing, exiting.\n", filename); exit(-1); } @@ -175,7 +171,7 @@ wrauth(char *filename) FILE *fp; printf("Writing %s\n", filename); - if ((fp = fopen(filename, "wt")) == NULL) { + if ((fp = fopen(filename, "w")) == NULL) { printf("Cannot open %s for writing, exiting.\n", filename); exit(-1); } @@ -232,7 +228,7 @@ wrgamesdef(char *filename) } printf("Writing %s\n", filename); - if ((fp = fopen(filename, "w")) == NULL) { + if ((fp = fopen(filename, "wb")) == NULL) { printf("Cannot open %s for writing, exiting.\n", filename); exit(-1); } diff --git a/src/lib/commands/info.c b/src/lib/commands/info.c index cfc0866e..7038add9 100644 --- a/src/lib/commands/info.c +++ b/src/lib/commands/info.c @@ -305,7 +305,7 @@ info(void) name = "TOP"; _snprintf(filename, sizeof(filename) - 1, "%s\\%s", infodir, name); - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); if (fp == NULL) { /* may be a "partial" request. */ HANDLE hDir; @@ -365,7 +365,7 @@ info(void) } _snprintf(filename, sizeof(filename), "%s/%s", infodir, last); - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); if (fp == NULL) { pr("Error reading info file for %s\n", name); logerror("Cannot open for \"%s\" info file (%s)", @@ -455,7 +455,7 @@ apro(void) (fData.dwFileAttributes == FILE_ATTRIBUTE_READONLY))) { _snprintf(filename, sizeof(filename), "%s\\%s", infodir, fData.cFileName); - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); alreadyhit = 0; nll = nlhl = 0; if (fp != NULL) { diff --git a/src/lib/commands/mobu.c b/src/lib/commands/mobu.c index a368c196..636f907c 100644 --- a/src/lib/commands/mobu.c +++ b/src/lib/commands/mobu.c @@ -61,7 +61,7 @@ mobupdate(void) else minites = atol(player->argp[1]) * 60; time(&now); - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "rb+")) == NULL) { logerror("Unable to edit timestamp file."); } else { rewind(fp); diff --git a/src/lib/commands/rea.c b/src/lib/commands/rea.c index b70f6fd5..fe0dc6fa 100644 --- a/src/lib/commands/rea.c +++ b/src/lib/commands/rea.c @@ -100,7 +100,7 @@ rea(void) clear_telegram_is_new(player->cnum); } - if ((telfp = fopen(mbox, "r+")) == 0) { + if ((telfp = fopen(mbox, "rb+")) == 0) { logerror("telegram file %s", mbox); return RET_FAIL; } @@ -201,7 +201,7 @@ rea(void) /* Here, we just re-open the file for "w" only, and that will wipe the file clean automatically */ (void)fclose(telfp); - telfp = fopen((char *)mbox, "w"); + telfp = fopen((char *)mbox, "wb"); } } } diff --git a/src/lib/commands/turn.c b/src/lib/commands/turn.c index 84deb678..d0567cbd 100644 --- a/src/lib/commands/turn.c +++ b/src/lib/commands/turn.c @@ -95,7 +95,7 @@ turn(void) pr("Writing empty no-login message.\n"); } - fptr = fopen(msgfilepath, "w"); + fptr = fopen(msgfilepath, "wb"); if (fptr == NULL) { 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 94adc79a..34cedc3e 100644 --- a/src/lib/commands/upda.c +++ b/src/lib/commands/upda.c @@ -51,7 +51,7 @@ upda(void) struct mob_acc_globals timestamps; if (opt_MOB_ACCESS) { - if ((fp = fopen(timestampfil, "r")) == NULL) + if ((fp = fopen(timestampfil, "rb")) == NULL) logerror("Unable to open timestamp file."); else { rewind(fp); diff --git a/src/lib/common/file.c b/src/lib/common/file.c index e94b52c5..e35c775c 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -60,6 +60,9 @@ 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 8419df7a..36e2b0d5 100644 --- a/src/lib/common/log.c +++ b/src/lib/common/log.c @@ -82,11 +82,7 @@ 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 e13736f7..4def08f3 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, "rt")) == NULL) { + if ((fp = fopen(file, "r")) == NULL) { fprintf(stderr, "Can't open %s for reading (%s)\n", file, strerror(errno)); return -1; diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index 57654067..19e4f991 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -158,7 +158,7 @@ gamedown(void) if (player->god) return 0; - if ((down_fp = fopen(downfil, "r")) == NULL) + if ((down_fp = fopen(downfil, "rb")) == NULL) return 0; if (fread((void *)&tgm, sizeof(tgm), 1, down_fp) != 1) { logerror("bad header on login message (downfil)"); diff --git a/src/lib/player/player.c b/src/lib/player/player.c index a08b2e6e..92272fa2 100644 --- a/src/lib/player/player.c +++ b/src/lib/player/player.c @@ -347,7 +347,7 @@ show_motd(void) struct telstr tgm; char buf[MAXTELSIZE]; - if ((motd_fp = fopen(motdfil, "r")) == NULL) + if ((motd_fp = fopen(motdfil, "rb")) == NULL) { if (errno == ENOENT) return RET_OK; @@ -387,7 +387,7 @@ match_user(char *file, struct player *p) char host[256]; char user[256]; - if ((fp = fopen(file, "rt")) == NULL) { + if ((fp = fopen(file, "r")) == NULL) { /*logerror("Cannot find file %s", file); */ return 0; } diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c index 036d94e4..292717ad 100644 --- a/src/lib/subs/wu.c +++ b/src/lib/subs/wu.c @@ -125,7 +125,11 @@ 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 b5b11823..f7268364 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, "r")) == NULL) { + if ((annfp = fopen(annfil, "rb")) == NULL) { logerror("can't open telegram file %s for reading", annfil); return; } sprintf(tmp_filename, "%s.tmp", annfil); - if ((tmpfp = fopen(tmp_filename, "w")) == NULL) { + if ((tmpfp = fopen(tmp_filename, "wb")) == 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 f6b0b2c1..51b1c577 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -113,10 +113,6 @@ main(int argc, char **argv) int op; s_char tbuf[256]; -#if defined(_WIN32) - _fmode = _O_BINARY; -#endif - mainpid = getpid(); #if defined(_WIN32) diff --git a/src/server/timestamp.c b/src/server/timestamp.c index c85c80f8..c8d0f5fb 100644 --- a/src/server/timestamp.c +++ b/src/server/timestamp.c @@ -52,7 +52,7 @@ mobility_check(void *unused) while (1) { time(&now); /* logerror("Updating timestamp file at %s", ctime(&now));*/ - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "rb+")) == NULL) { logerror("Unable to edit timestamp file."); continue; } @@ -97,7 +97,7 @@ mobility_init(void) mobility */ time(&now); - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "rb+")) == NULL) { logerror("Unable to edit timestamp file."); /* FIXME safe to continue? */ } else { diff --git a/src/util/fairland.c b/src/util/fairland.c index 9d97ac2b..72faccba 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -194,10 +194,6 @@ main(int argc, char *argv[]) char tbuf[512]; int i = 0; -#if defined(_WIN32) - _fmode = _O_BINARY; -#endif - rnd_seed = time(NULL); while ((opt = getopt(argc, argv, "ae:ioqs:R:")) != EOF) { @@ -411,7 +407,7 @@ allocate_memory(void) { int i; - sect_fptr = fopen(empfile[EF_SECTOR].file, "w"); + sect_fptr = fopen(empfile[EF_SECTOR].file, "wb"); if (sect_fptr == NULL) { perror(empfile[EF_SECTOR].file); return -1; diff --git a/src/util/files.c b/src/util/files.c index f0ad84fe..6acee2fb 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -88,10 +88,6 @@ main(int argc, char *argv[]) char *config_file = NULL; int force = 0; -#if defined(_WIN32) - _fmode = _O_BINARY; -#endif - while ((opt = getopt(argc, argv, "e:f")) != EOF) { switch (opt) { case 'e':