0
0
mirror of https://github.com/python/cpython.git synced 2024-11-30 01:16:51 +01:00
cpython/Python/getmtime.c

27 lines
388 B
C
Raw Normal View History

1993-12-24 11:32:00 +01:00
/* Subroutine to get the last modification time of a file */
/* (A separate file because this may be OS dependent) */
#include "Python.h"
#include "pyconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
time_t
PyOS_GetLastModificationTime(char *path, FILE *fp)
1993-12-24 11:32:00 +01:00
{
struct stat st;
First part of package support. This doesn't yet support "import a.b.c" or "from a.b.c import x", but it does recognize directories. When importing a directory, it initializes __path__ to a list containing the directory name, and loads the __init__ module if found. The (internal) find_module() and load_module() functions are restructured so that they both also handle built-in and frozen modules and Mac resources (and directories of course). The imp module's find_module() and (new) load_module() also have this functionality. Moreover, imp unconditionally defines constants for all module types, and has two more new functions: find_module_in_package() and find_module_in_directory(). There's also a new API function, PyImport_ImportModuleEx(), which takes all four __import__ arguments (name, globals, locals, fromlist). The last three may be NULL. This is currently the same as PyImport_ImportModule() but in the future it will be able to do relative dotted-path imports. Other changes: - bltinmodule.c: in __import__, call PyImport_ImportModuleEx(). - ceval.c: always pass the fromlist to __import__, even if it is a C function, so PyImport_ImportModuleEx() is useful. - getmtime.c: the function has a second argument, the FILE*, on which it applies fstat(). According to Sjoerd this is much faster. The first (pathname) argument is ignored, but remains for backward compatibility (so the Mac version still works without changes). By cleverly combining the new imp functionality, the full support for dotted names in Python (mini.py, not checked in) is now about 7K, lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly commented). Good night!
1997-09-05 09:33:22 +02:00
if (fstat(fileno(fp), &st) != 0)
1993-12-24 11:32:00 +01:00
return -1;
else
return st.st_mtime;
}
#ifdef __cplusplus
}
#endif