Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

_stat returns impossible errno code 132

I have the following program to read a file that exists:

const char *path = "C:\\Users\\myname\\AppData\\Roaming\\Technology\\plus\\fs\\D\\TECH\\CUSTOM\\LOG.XML";
struct _stat    lInfo;
int             err = _stat(path, &lInfo);

if (err == 0) {
    return (lInfo.st_mode & _S_IFDIR) != 0;
} else {
    _get_errno(&err);
    printf("Error: %d\n", err);
}

On this particular file I am getting err == 132 where _stat, according to the documentation, can only return ENOENT (2) and EINVAL (22). Error code 132 is EOVERFLOW. If I copy the file exactly and rename it LOG2.xml and replace this line accordingly:

const char *path = "C:\\Users\\myname\\AppData\\Roaming\\Technology\\plus\\fs\\D\\TECH\\CUSTOM\\LOG2.XML";

Then everything works just fine. (ie. errno is 0 and i get the file information). If I just rename the original file (From LOG.XML to LOG2.XML) then i get the same error which leads me to believe its a permissions or ownership problem.

What could be the cause of this error?

Upvotes: 1

Views: 1490

Answers (2)

Raven
Raven

Reputation: 1331

I encountered this exact problem while upgrading from Visual Studio 2010 SP1Rel to Visual Studio 2015 Update 2. My file has a modified date of Sunday, ‎May ‎13, ‎1601, ‏‎5:53:31 PM, and it appears stat no longer works with dates before 1970.

Debugging through the vc14 ucrt, I believe the following lines of code are relevant:

corecrt_internal_time.h

#define _BASE_YEAR     70                // The epoch year (1970)

loctotime.cpp:common_loctotime_t()

yr -= 1900;

_VALIDATE_RETURN_NOEXC(yr >= _BASE_YEAR && yr <= time_traits::max_year, EINVAL, invalid_time)

Running touch on the file fixed the issue.

On the one hand, it does seem pretty unreasonable to have file timestamps that predate 1970, but on the other hand it is possible to do (artificially) and somehow it occasionally happens by accident. Feels like a regression in Visual Studio.

Upvotes: 3

Luis
Luis

Reputation: 1235

The link where you looked for the error actually contains the Windows API error codes, which are not the same as the C standard library's.

  • The header you need is <errno.h> which shows that 132 corresponds to EOVERFLOW.
  • VS includes the source code of the C runtime library (in a path like C:\Program Files (x86)\Microsoft Visual Studio VERSIONID\VC\crt\src), so you should step into it with the debugger to find out what's going on in your case.

A quick look on the CRT source code in my VS version suggests that can happen when a file size is too big to be represented in a 32 bit integer. From what you describe, I'm not sure that might your problem (unless the original path is something special, symbolic link, ...?) but you should try your debugger.

Upvotes: -1

Related Questions