Ignore:
Timestamp:
Feb 21, 2025, 3:31:23 PM (6 weeks ago)
Author:
bird
Message:

kmk: More debugging code for the mysterious 'kmk: write error: stdout' problem...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/kmk/output.c

    r3664 r3666  
    6060#endif
    6161
    62 #if defined(KMK) && defined(KBUILD_OS_WINDOWS) && 1
    63 # define DEBUG_STDOUT_CLOSE_ISSUE
     62#ifdef DEBUG_STDOUT_CLOSE_ISSUE
    6463/* fflush wrapper w/ error checking + reporting for stdout.
    6564   This is to debug the mysterious 'kmk: write error: stdout' errors. */
     
    6867static void my_stdout_error (const char *pszOperation, const char *pszMessage)
    6968{
     69# ifdef KBUILD_OS_WINDOWS
    7070  DWORD const     dwErr   = GetLastError ();
     71# endif
    7172  int const       iErrNo  = errno;
    72   int const       fdFile  = fileno(stdout);
     73  int const       fdFile  = fileno (stdout);
     74# ifdef KBUILD_OS_WINDOWS
    7375  HANDLE    const hNative = (HANDLE)_get_osfhandle (_fileno (stdout));
    7476  DWORD const     dwType  = GetFileType (hNative);
    75   fprintf (stderr, "kmk: %s: %s! (lasterr=%u errno=%d fileno=%d native=%p type=%#x)\n",
    76            pszOperation, pszMessage, dwErr, iErrNo, fdFile, hNative, dwType);
     77  fprintf (stderr, "kmk[%u]: %s: %s! (lasterr=%u errno=%d fileno=%d native=%p type=%#x)\n",
     78           makelevel, pszOperation, pszMessage, dwErr, iErrNo, fdFile, hNative, dwType);
     79# else
     80  fprintf (stderr, "kmk[%u]: %s: %s! (lasterr=%u errno=%d fileno=%d)\n",
     81           makelevel, pszOperation, pszMessage, dwErr, iErrNo, fdFile);
     82# endif
    7783}
    7884
     
    107113# define fflush(a_pFile) my_fflush(a_pFile)
    108114
    109 #endif
     115/* Preserves errno and win32 last error. */
     116void my_check_stdout (const char *pszWhere)
     117{
     118  if (!g_fStdOutError)
     119    {
     120# ifdef KBUILD_OS_WINDOWS
     121      DWORD const dwErrSaved  = GetLastError();
     122# endif
     123      int const   iErrNoSaved = errno;
     124
     125      if (ferror (stdout))
     126        {
     127          my_stdout_error (pszWhere, "error pending!");
     128          g_fStdOutError = 1;
     129        }
     130
     131      errno = iErrNoSaved;
     132# ifdef KBUILD_OS_WINDOWS
     133      SetLastError(dwErrSaved);
     134# endif
     135    }
     136}
     137
     138#endif /* DEBUG_STDOUT_CLOSE_ISSUE */
    110139
    111140
Note: See TracChangeset for help on using the changeset viewer.