Self-answering, with thanks to @mehrdad and @HansPassant for pointing me in the right direction. Indeed, MSVCRT exports an array of arrays of a structure called ioinfo
in which it stores information about each open file handle in the process.
The exact contents of the structure depend on the VC version and some defines, but in general its first two members are defined:
typedef struct {
intptr_t osfhnd; /* underlying OS file HANDLE */
char osfile; /* attributes of file (e.g., open in text mode?) */
....
} ioinfo;
The osfile
member is the interesting one--if the file is opened with _O_APPEND
the flag called FAPPEND
defined as 0x20
is set on this.
I wrote a little utility function in Python based on similar code in CPython's posixmodule that can perform this check: https://gist.github.com/embray/6444262