[PATCH] osutil: implementation for Win32
Benoit Boissinot
bboissin at gmail.com
Tue Sep 9 19:58:22 UTC 2008
On Tue, Sep 9, 2008 at 8:51 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:
> # HG changeset patch
> # User Petr Kodl <petrkodl at gmail.com>
> # Date 1220959680 14400
> # Node ID 020fe75b47f569a29c25f8a5fef7451100d72772
> # Parent 9141bebefe3ed0498ff07271214bfca8b4eb0d27
> osutil: implementation for Win32
>
> diff --git a/mercurial/osutil.c b/mercurial/osutil.c
> --- a/mercurial/osutil.c
> +++ b/mercurial/osutil.c
> +static int to_python_time(FILETIME* ms_time)
> +{
> + /* this is number of 100-nanoseconds between epoch and January 1 1601 */
> + static __int64 a0 = (__int64)134774L * (__int64)24L
> + * (__int64)3600L * (__int64)1000L
> + * (__int64)1000L * (__int64)10L;
> + /* conversion factor back to 1s resolution required by Python ctime */
> + static __int64 a1 = 1000 * 1000 * 10;
should it be const instead ?
> + __int64 tmp;
> + memcpy(&tmp, ms_time, sizeof(__int64));
why not directly return (int)(*ms_time - a0)/a1 ?
> + return (int)((tmp - a0) / a1);
> +}
> +
> +static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
> +{
> + PyObject *statobj = NULL;
> + PyObject *list = NULL;
> + PyObject *items = NULL;
> + PyObject *ctor_args = NULL;
> + PyObject *item0 = NULL;
> + PyObject *item1 = NULL;
> + PyObject *py_st = NULL;
> +
> + HANDLE fh = INVALID_HANDLE_VALUE;
> + WIN32_FIND_DATAA fd;
> +
> + char path[_MAX_PATH + 1];
> + char *buffer = path;
> + int plen = _MAX_PATH - 2;
> +
> + int keepstat = 0;
> +
> + static char *kwlist[] = {"path", "stat", NULL};
> +
> + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "et#|O:listdir",
> + kwlist, Py_FileSystemDefaultEncoding, &buffer, &plen, &statobj))
> + goto error;
What if plen is then > _MAX_PATH ?
> +
> + keepstat = statobj && PyObject_IsTrue(statobj);
> +
> + if (plen > 0) {
> + char c = path[plen-1];
> + if (c != ':' && c != '/' && c != '\\')
> + path[plen++] = '\\';
> + }
> +
> + strcpy(path + plen, "*");
> +
regards,
Benoit
More information about the Mercurial-devel
mailing list