Index: store_dir_coss.c =================================================================== RCS file: /cvsroot/squid/squid/src/fs/coss/store_dir_coss.c,v retrieving revision 1.20 diff -u -p -r1.20 store_dir_coss.c --- store_dir_coss.c 8 Apr 2002 00:38:18 -0000 1.20 +++ store_dir_coss.c 19 May 2002 15:21:33 -0000 @@ -130,7 +130,7 @@ storeCossDirOpenSwapLog(SwapDir * sd) char *path; int fd; path = storeCossDirSwapLogFile(sd, NULL); - fd = file_open(path, O_WRONLY | O_CREAT); + fd = file_open(path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(81, 1) ("%s: %s\n", path, xstrerror()); fatal("storeCossDirOpenSwapLog: Failed to open swap log."); @@ -390,7 +390,7 @@ storeCossDirCloseTmpSwapLog(SwapDir * sd char *new_path = xstrdup(storeCossDirSwapLogFile(sd, ".new")); int fd; file_close(cs->swaplog_fd); -#ifdef _SQUID_OS2_ +#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) if (unlink(swaplog_path) < 0) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeCossDirCloseTmpSwapLog: unlink failed"); @@ -399,7 +399,7 @@ storeCossDirCloseTmpSwapLog(SwapDir * sd if (xrename(new_path, swaplog_path) < 0) { fatal("storeCossDirCloseTmpSwapLog: rename failed"); } - fd = file_open(swaplog_path, O_WRONLY | O_CREAT); + fd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeCossDirCloseTmpSwapLog: Failed to open swap log."); @@ -433,7 +433,7 @@ storeCossDirOpenTmpSwapLog(SwapDir * sd, if (cs->swaplog_fd >= 0) file_close(cs->swaplog_fd); /* open a write-only FD for the new log */ - fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC); + fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", new_path, xstrerror()); fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); @@ -445,6 +445,9 @@ storeCossDirOpenTmpSwapLog(SwapDir * sd, debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_BINARY); +#endif memset(&clean_sb, '\0', sizeof(struct stat)); if (stat(clean_path, &clean_sb) < 0) *clean_flag = 0; @@ -484,7 +487,7 @@ storeCossDirWriteCleanStart(SwapDir * sd struct stat sb; #endif state->new = xstrdup(storeCossDirSwapLogFile(sd, ".clean")); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (state->fd < 0) { xfree(state->new); xfree(state); @@ -567,6 +570,7 @@ storeCossDirWriteCleanEntry(SwapDir * sd static void storeCossDirWriteCleanDone(SwapDir * sd) { + int fd; struct _clean_state *state = sd->log.clean.state; if (NULL == state) return; @@ -587,24 +591,26 @@ storeCossDirWriteCleanDone(SwapDir * sd) * so we have to close before renaming. */ storeCossDirCloseSwapLog(sd); + /* save the fd value for a later test */ + fd = state->fd; /* rename */ if (state->fd >= 0) { -#ifdef _SQUID_OS2_ +#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) file_close(state->fd); state->fd = -1; - if (unlink(cur) < 0) + if (unlink(state->cur) < 0) debug(50, 0) ("storeCossDirWriteCleanLogs: unlinkd failed: %s, %s\n", - xstrerror(), cur); + xstrerror(), state->cur); #endif xrename(state->new, state->cur); } /* touch a timestamp file if we're not still validating */ if (store_dirs_rebuilding) (void) 0; - else if (state->fd < 0) + else if (fd < 0) (void) 0; else - file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC)); + file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)); /* close */ safe_free(state->cur); safe_free(state->new);