[pywin32-checkins] pywin32/win32/src win32file.i,1.78,1.79
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-05-14 17:10:12
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31992/win32/src Modified Files: win32file.i Log Message: Combine CreateHardLink, CreateSymbolicLink, GetFullPathName, and GetLongPathName with corresponding Transacted functions Fix a couple more 64-bit issues Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** win32file.i 23 Apr 2007 00:13:55 -0000 1.78 --- win32file.i 14 May 2007 17:10:11 -0000 1.79 *************** *** 200,204 **** // @flag FILE_SHARE_WRITE|Subsequent open operations on the object will succeed only if write access is requested. SECURITY_ATTRIBUTES *lpSecurityAttributes, // @pyparm <o PySECURITY_ATTRIBUTES>|attributes||The security attributes, or None ! DWORD dwCreationDistribution, // @pyparm int|creationDisposition||Specifies which action to take on files that exist, and which action to take when files do not exist. For more information about this parameter, see the Remarks section. This parameter must be one of the following values: // @flagh Value|Meaning // @flag CREATE_NEW|Creates a new file. The function fails if the specified file already exists. --- 200,204 ---- // @flag FILE_SHARE_WRITE|Subsequent open operations on the object will succeed only if write access is requested. SECURITY_ATTRIBUTES *lpSecurityAttributes, // @pyparm <o PySECURITY_ATTRIBUTES>|attributes||The security attributes, or None ! DWORD dwCreationDisposition, // @pyparm int|CreationDisposition||Specifies which action to take on files that exist, and which action to take when files do not exist. For more information about this parameter, see the Remarks section. This parameter must be one of the following values: // @flagh Value|Meaning // @flag CREATE_NEW|Creates a new file. The function fails if the specified file already exists. *************** *** 233,245 **** PyObject *MyCreateIoCompletionPort(PyObject *self, PyObject *args) { ! PyObject *obFileHandle, *obExistingHandle; ! int key, nt; PyObject *obRet = NULL; ! if (!PyArg_ParseTuple(args, "OOii:CreateIoCompletionPort", &obFileHandle, // @pyparm <o PyHANDLE>|handle||file handle to associate with the I/O completion port &obExistingHandle, // @pyparm <o PyHANDLE>|existing||handle to the I/O completion port ! &key, // @pyparm int|completionKey||per-file completion key for I/O completion packets &nt)) // @pyparm int|numThreads||number of threads allowed to execute concurrently return NULL; HANDLE hFile, hExisting; if (!PyWinObject_AsHANDLE(obFileHandle, &hFile, FALSE)) --- 233,248 ---- PyObject *MyCreateIoCompletionPort(PyObject *self, PyObject *args) { ! PyObject *obFileHandle, *obExistingHandle, *obkey; ! DWORD nt; ! ULONG_PTR key; PyObject *obRet = NULL; ! if (!PyArg_ParseTuple(args, "OOOi:CreateIoCompletionPort", &obFileHandle, // @pyparm <o PyHANDLE>|handle||file handle to associate with the I/O completion port &obExistingHandle, // @pyparm <o PyHANDLE>|existing||handle to the I/O completion port ! &obkey, // @pyparm int|completionKey||per-file completion key for I/O completion packets &nt)) // @pyparm int|numThreads||number of threads allowed to execute concurrently return NULL; + if (!PyWinLong_AsVoidPtr(obkey, (void **)&key)) + return NULL; HANDLE hFile, hExisting; if (!PyWinObject_AsHANDLE(obFileHandle, &hFile, FALSE)) *************** *** 1173,1177 **** if (!PyWinObject_AsHANDLE(obHandle, &handle, FALSE)) return NULL; ! DWORD bytes = 0, key = 0; OVERLAPPED *pOverlapped = NULL; UINT errCode; --- 1176,1181 ---- if (!PyWinObject_AsHANDLE(obHandle, &handle, FALSE)) return NULL; ! DWORD bytes = 0; ! ULONG_PTR key = 0; OVERLAPPED *pOverlapped = NULL; UINT errCode; *************** *** 1180,1186 **** errCode = ok ? 0 : GetLastError(); Py_END_ALLOW_THREADS ! PyObject *obOverlapped = PyWinObject_FromQueuedOVERLAPPED(pOverlapped); ! PyObject *rc = Py_BuildValue("illO", errCode, bytes, key, obOverlapped); ! Py_XDECREF(obOverlapped); return rc; } --- 1184,1190 ---- errCode = ok ? 0 : GetLastError(); Py_END_ALLOW_THREADS ! PyObject *rc = Py_BuildValue("ilNN", errCode, bytes, ! PyWinLong_FromVoidPtr((void *)key), ! PyWinObject_FromQueuedOVERLAPPED(pOverlapped)); return rc; } *************** *** 1189,1200 **** PyObject *myPostQueuedCompletionStatus(PyObject *self, PyObject *args) { ! PyObject *obHandle, *obOverlapped = NULL; ! DWORD bytesTransfered = 0, key = 0; // @pyparm <o PyHANDLE>|handle||handle to an I/O completion port // @pyparm int|numberOfbytes|0|value to return via GetQueuedCompletionStatus' first result // @pyparm int|completionKey|0|value to return via GetQueuedCompletionStatus' second result // @pyparm <o PyOVERLAPPED>|overlapped|None|value to return via GetQueuedCompletionStatus' third result ! if (!PyArg_ParseTuple(args, "O|iiO", &obHandle, &bytesTransfered, &key, &obOverlapped)) return NULL; HANDLE handle; if (!PyWinObject_AsHANDLE(obHandle, &handle, FALSE)) --- 1193,1208 ---- PyObject *myPostQueuedCompletionStatus(PyObject *self, PyObject *args) { ! PyObject *obHandle, *obOverlapped = NULL, *obkey=Py_None; ! DWORD bytesTransfered = 0; ! ULONG_PTR key = 0; // @pyparm <o PyHANDLE>|handle||handle to an I/O completion port // @pyparm int|numberOfbytes|0|value to return via GetQueuedCompletionStatus' first result // @pyparm int|completionKey|0|value to return via GetQueuedCompletionStatus' second result // @pyparm <o PyOVERLAPPED>|overlapped|None|value to return via GetQueuedCompletionStatus' third result ! if (!PyArg_ParseTuple(args, "O|iOO", &obHandle, &bytesTransfered, &obkey, &obOverlapped)) return NULL; + if (obkey!=Py_None) + if (!PyWinLong_AsVoidPtr(obkey, (void **)&key)) + return NULL; HANDLE handle; if (!PyWinObject_AsHANDLE(obHandle, &handle, FALSE)) *************** *** 1236,1329 **** #define FILE_TYPE_CHAR FILE_TYPE_CHAR // The specified file is a character file, typically an LPT device or a console. #define FILE_TYPE_PIPE FILE_TYPE_PIPE // The specified file is either a named or anonymous pipe. - - #endif // MS_WINCE - - // GetFullPathName - // @pyswig str/unicode|GetFullPathName|Returns full path for path passed in - // @comm This function takes either a plain string or a unicode string, and returns the same type - // If unicode is passed in, GetFullPathNameW is called, which supports filenames longer than MAX_PATH - %native(GetFullPathName) MyGetFullPathName; - %{ - static PyObject *MyGetFullPathName(PyObject *self, PyObject *args) - { - PyObject *ret=NULL, *obpathin; - int pathlen, retlen; - - // @pyparm str/unicode|FileName||Path on which to operate - if (!PyArg_ParseTuple(args, "O", &obpathin)) - return NULL; - WCHAR *wpathin; - if (wpathin=PyUnicode_AsUnicode(obpathin)){ - WCHAR *wpathret, *wfilepart; - pathlen=wcslen(wpathin)+1; - wpathret=(WCHAR *)malloc(pathlen*sizeof(WCHAR)); - if (wpathret==NULL){ - PyErr_SetString(PyExc_MemoryError,"GetFullPathNameW: unable to allocate unicode return buffer"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - retlen=GetFullPathNameW(wpathin, pathlen, wpathret, &wfilepart); - Py_END_ALLOW_THREADS - if (retlen>pathlen){ - pathlen=retlen; - wpathret=(WCHAR *)realloc(wpathret,pathlen*sizeof(WCHAR)); - if (wpathret==NULL){ - PyErr_SetString(PyExc_MemoryError,"GetFullPathNameW: unable to allocate unicode return buffer"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - retlen=GetFullPathNameW(wpathin, retlen, wpathret, &wfilepart); - Py_END_ALLOW_THREADS - } - if (retlen>pathlen) - PyErr_SetString(PyExc_SystemError,"GetFullPathNameW: Unexpected second increase in required buffer size"); - else - if (retlen==0) - PyWin_SetAPIError("GetFullPathNameW", GetLastError()); - else - ret=PyUnicode_FromWideChar(wpathret,retlen); - free(wpathret); - return ret; - } - - PyErr_Clear(); - char *cpathin; - if (PyString_AsStringAndSize(obpathin, &cpathin, &pathlen)!=-1){ - char *cpathret, *cfilepart; - pathlen+=1; - cpathret=(char *)malloc(pathlen); - if (cpathret==NULL){ - PyErr_SetString(PyExc_MemoryError,"GetFullPathName: unable to allocate character return buffer"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - retlen=GetFullPathName(cpathin, pathlen, cpathret, &cfilepart); - Py_END_ALLOW_THREADS - if (retlen>pathlen){ - pathlen=retlen; - cpathret=(char *)realloc(cpathret,pathlen); - if (cpathret==NULL){ - PyErr_SetString(PyExc_MemoryError,"GetFullPathName: unable to allocate character return buffer"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - retlen=GetFullPathName(cpathin, retlen, cpathret, &cfilepart); - Py_END_ALLOW_THREADS - } - if (retlen>pathlen) - PyErr_SetString(PyExc_SystemError,"GetFullPathName: Unexpected second increase in required buffer size"); - else - if (retlen==0) - PyWin_SetAPIError("GetFullPathName", GetLastError()); - else - ret=PyString_FromStringAndSize(cpathret,retlen); - free(cpathret); - } - return ret; - } - %} - - #ifndef MS_WINCE // @pyswig int|GetLogicalDrives|Returns a bitmaks of the logical drives installed. unsigned long GetLogicalDrives( // DWORD --- 1244,1248 ---- *************** *** 1702,1723 **** PyObject *myget_osfhandle (int filehandle) { ! long result = _get_osfhandle (filehandle); ! if (result == -1) return PyErr_SetFromErrno(PyExc_IOError); ! return Py_BuildValue ("l",result); } PyObject *myopen_osfhandle (PyHANDLE osfhandle, int flags) { ! int result = _open_osfhandle ((long) osfhandle, flags); if (result == -1) return PyErr_SetFromErrno(PyExc_IOError); ! return Py_BuildValue ("i",result); } %} // Overlapped Socket stuff %{ --- 1621,1643 ---- PyObject *myget_osfhandle (int filehandle) { ! HANDLE result = (HANDLE)_get_osfhandle (filehandle); ! if (result == (HANDLE)-1) return PyErr_SetFromErrno(PyExc_IOError); ! return PyWinLong_FromHANDLE(result); } PyObject *myopen_osfhandle (PyHANDLE osfhandle, int flags) { ! int result = _open_osfhandle ((ULONG_PTR)osfhandle, flags); if (result == -1) return PyErr_SetFromErrno(PyExc_IOError); ! return PyInt_FromLong(result); } %} + // Overlapped Socket stuff %{ *************** *** 2755,2764 **** typedef DWORD (WINAPI *GetFinalPathNameByHandlefunc)(HANDLE,LPWSTR,DWORD,DWORD); static GetFinalPathNameByHandlefunc pfnGetFinalPathNameByHandle = NULL; ! ! // These aren't used yet ! typedef DWORD (WINAPI *GetFullPathNameTransactedfunc)(LPCTSTR,DWORD,LPTSTR,LPTSTR*,HANDLE); ! static GetFullPathNameTransactedfunc pfnGetFullPathNameTransacted = NULL; ! typedef DWORD (WINAPI *GetLongPathNameTransactedfunc)(LPCTSTR,LPTSTR,DWORD,HANDLE); static GetLongPathNameTransactedfunc pfnGetLongPathNameTransacted = NULL; /* FILE_INFO_BY_HANDLE_CLASS and various structs used by this function are in fileextd.h, can be downloaded here: http://www.microsoft.com/downloads/details.aspx?familyid=1decc547-ab00-4963-a360-e4130ec079b8&displaylang=en --- 2675,2687 ---- typedef DWORD (WINAPI *GetFinalPathNameByHandlefunc)(HANDLE,LPWSTR,DWORD,DWORD); static GetFinalPathNameByHandlefunc pfnGetFinalPathNameByHandle = NULL; ! typedef DWORD (WINAPI *GetLongPathNamefunc)(LPCWSTR,LPWSTR,DWORD); ! static GetLongPathNamefunc pfnGetLongPathName = NULL; ! typedef DWORD (WINAPI *GetLongPathNameTransactedfunc)(LPCWSTR,LPWSTR,DWORD,HANDLE); static GetLongPathNameTransactedfunc pfnGetLongPathNameTransacted = NULL; + typedef DWORD (WINAPI *GetFullPathNameTransactedWfunc)(LPCWSTR,DWORD,LPWSTR,LPWSTR*,HANDLE); + static GetFullPathNameTransactedWfunc pfnGetFullPathNameTransactedW = NULL; + typedef DWORD (WINAPI *GetFullPathNameTransactedAfunc)(LPCSTR,DWORD,LPSTR,LPSTR*,HANDLE); + static GetFullPathNameTransactedAfunc pfnGetFullPathNameTransactedA = NULL; + /* FILE_INFO_BY_HANDLE_CLASS and various structs used by this function are in fileextd.h, can be downloaded here: http://www.microsoft.com/downloads/details.aspx?familyid=1decc547-ab00-4963-a360-e4130ec079b8&displaylang=en *************** *** 2966,3031 **** // @comm This method exists on Windows 2000 and later. Otherwise NotImplementedError will be raised. // @comm Accepts keyword args. ! CHECK_PFN(CreateHardLink); PyObject *ret=NULL; PyObject *new_file_obj; PyObject *existing_file_obj; ! PyObject *sa_obj = Py_None; ! WCHAR *new_file = NULL; ! WCHAR *existing_file = NULL; ! SECURITY_ATTRIBUTES *sa; ! static char *keywords[]={"FileName","ExistingFileName","SecurityAttributes", NULL}; ! ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O:CreateHardLink", keywords, ! &new_file_obj, // @pyparm <o PyUnicode>|FileName||The name of the new directory entry to be created. ! &existing_file_obj, // @pyparm <o PyUnicode>|ExistingFileName||The name of the existing file to which the new link will point. ! &sa_obj)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Optional SECURITY_ATTRIBUTES object. MSDN describes this parameter as reserved, so use only None, ! return NULL; ! if (!PyWinObject_AsSECURITY_ATTRIBUTES(sa_obj, &sa, TRUE)) ! return NULL; ! if (PyWinObject_AsWCHAR(new_file_obj, &new_file, FALSE) ! &&PyWinObject_AsWCHAR(existing_file_obj, &existing_file, FALSE)){ ! if (!(*pfnCreateHardLink)(new_file, existing_file, sa)) ! PyWin_SetAPIError("CreateHardLink"); ! else{ ! Py_INCREF(Py_None); ! ret=Py_None; ! } ! } ! PyWinObject_FreeWCHAR(new_file); ! PyWinObject_FreeWCHAR(existing_file); ! return ret; ! } ! PyCFunction pfnpy_CreateHardLink=(PyCFunction)py_CreateHardLink; ! ! // @pyswig |CreateHardLinkTransacted|Creates an NTFS hard link as part of a transaction ! static PyObject *py_CreateHardLinkTransacted(PyObject *self, PyObject *args, PyObject *kwargs) ! { ! // @comm This method only exists on Vista and later. ! // @comm Accepts keyword args. ! CHECK_PFN(CreateHardLinkTransacted); ! PyObject *obtrans, *ret=NULL; ! PyObject *new_file_obj; ! PyObject *existing_file_obj; ! PyObject *sa_obj = Py_None; WCHAR *new_file = NULL; WCHAR *existing_file = NULL; SECURITY_ATTRIBUTES *sa; HANDLE htrans; ! static char *keywords[]={"FileName","ExistingFileName","Transaction","SecurityAttributes", NULL}; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO|O:CreateHardLinkTransacted", keywords, &new_file_obj, // @pyparm <o PyUnicode>|FileName||The name of the new directory entry to be created. &existing_file_obj, // @pyparm <o PyUnicode>|ExistingFileName||The name of the existing file to which the new link will point. ! &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction ! &sa_obj)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Optional SECURITY_ATTRIBUTES object. MSDN describes this parameter as reserved, so use only None, return NULL; ! if (!PyWinObject_AsHANDLE(obtrans, &htrans, FALSE)) return NULL; if (!PyWinObject_AsSECURITY_ATTRIBUTES(sa_obj, &sa, TRUE)) return NULL; if (PyWinObject_AsWCHAR(new_file_obj, &new_file, FALSE) &&PyWinObject_AsWCHAR(existing_file_obj, &existing_file, FALSE)){ ! if (!(*pfnCreateHardLinkTransacted)(new_file, existing_file, sa, htrans)) ! PyWin_SetAPIError("CreateHardLinkTransacted"); else{ Py_INCREF(Py_None); --- 2889,2928 ---- // @comm This method exists on Windows 2000 and later. Otherwise NotImplementedError will be raised. // @comm Accepts keyword args. ! // @comm If the Transaction parameter is specified, CreateHardLinkTransacted will be called (requires Vista or later) PyObject *ret=NULL; PyObject *new_file_obj; PyObject *existing_file_obj; ! PyObject *trans_obj=Py_None, *sa_obj = Py_None; WCHAR *new_file = NULL; WCHAR *existing_file = NULL; SECURITY_ATTRIBUTES *sa; HANDLE htrans; ! static char *keywords[]={"FileName","ExistingFileName","SecurityAttributes","Transaction", NULL}; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|OO:CreateHardLink", keywords, &new_file_obj, // @pyparm <o PyUnicode>|FileName||The name of the new directory entry to be created. &existing_file_obj, // @pyparm <o PyUnicode>|ExistingFileName||The name of the existing file to which the new link will point. ! &sa_obj, // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Optional SECURITY_ATTRIBUTES object. MSDN describes this parameter as reserved, so use only None ! &trans_obj)) // @pyparm <o PyHANDLE>|Transaction|None|Handle to a transaction, as returned by <om win32transaction.CreateTransaction> return NULL; ! if (!PyWinObject_AsHANDLE(trans_obj, &htrans, TRUE)) return NULL; if (!PyWinObject_AsSECURITY_ATTRIBUTES(sa_obj, &sa, TRUE)) return NULL; + if (htrans){ + CHECK_PFN(CreateHardLinkTransacted); + } + else{ + CHECK_PFN(CreateHardLink); + } if (PyWinObject_AsWCHAR(new_file_obj, &new_file, FALSE) &&PyWinObject_AsWCHAR(existing_file_obj, &existing_file, FALSE)){ ! BOOL bsuccess; ! if (htrans) ! bsuccess=(*pfnCreateHardLinkTransacted)(new_file, existing_file, sa, htrans); ! else ! bsuccess=(*pfnCreateHardLink)(new_file, existing_file, sa); ! if (!bsuccess) ! PyWin_SetAPIError("CreateHardLink"); else{ Py_INCREF(Py_None); *************** *** 3037,3041 **** return ret; } ! PyCFunction pfnpy_CreateHardLinkTransacted=(PyCFunction)py_CreateHardLinkTransacted; // @pyswig |CreateSymbolicLink|Creates a symbolic link (reparse point) --- 2934,2938 ---- return ret; } ! PyCFunction pfnpy_CreateHardLink=(PyCFunction)py_CreateHardLink; // @pyswig |CreateSymbolicLink|Creates a symbolic link (reparse point) *************** *** 3044,3097 **** // @comm This method only exists on Vista and later. // @comm Accepts keyword args. ! // @comm Requires SeCreateSymbolicLink priv ! CHECK_PFN(CreateSymbolicLink); ! WCHAR *linkname=NULL, *targetname=NULL; ! PyObject *oblinkname, *obtargetname, *ret=NULL; ! DWORD flags=0; ! static char *keywords[]={"SymlinkFileName","TargetFileName","Flags", NULL}; ! ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|k:CreateSymbolicLink", keywords, ! &oblinkname, // @pyparm <o PyUnicode>|SymlinkFileName||Path of the symbolic link to be created ! &obtargetname, // @pyparm <o PyUnicode>|TargetFileName||The name of file to which link will point ! &flags)) // @pyparm int|Flags|0|SYMLINK_FLAG_DIRECTORY is only defined flag ! return NULL; ! if (PyWinObject_AsWCHAR(oblinkname, &linkname, FALSE) && PyWinObject_AsWCHAR(obtargetname, &targetname, FALSE)){ ! if (!(*pfnCreateSymbolicLink)(linkname, targetname, flags)) ! PyWin_SetAPIError("CreateSymbolicLink"); ! else{ ! Py_INCREF(Py_None); ! ret=Py_None; ! } ! } ! PyWinObject_FreeWCHAR(linkname); ! PyWinObject_FreeWCHAR(targetname); ! return ret; ! } ! PyCFunction pfnpy_CreateSymbolicLink=(PyCFunction)py_CreateSymbolicLink; ! ! // @pyswig |CreateSymbolicLinkTransacted|Creates a symbolic link as part of a transaction ! static PyObject *py_CreateSymbolicLinkTransacted(PyObject *self, PyObject *args, PyObject *kwargs) ! { ! // @comm This method only exists on Vista and later. ! // @comm Accepts keyword args. ! // @comm Requires SeCreateSymbolicLink priv ! CHECK_PFN(CreateSymbolicLinkTransacted); WCHAR *linkname=NULL, *targetname=NULL; ! PyObject *oblinkname, *obtargetname, *obtrans, *ret=NULL; DWORD flags=0; HANDLE htrans; static char *keywords[]={"SymlinkFileName","TargetFileName","Flags","Transaction", NULL}; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO|k:CreateSymbolicLinkTransacted", keywords, &oblinkname, // @pyparm <o PyUnicode>|SymlinkFileName||Path of the symbolic link to be created &obtargetname, // @pyparm <o PyUnicode>|TargetFileName||The name of file to which link will point ! &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction ! &flags)) // @pyparm int|Flags|0|SYMLINK_FLAG_DIRECTORY is only defined flag ! return NULL; ! if (!PyWinObject_AsHANDLE(obtrans, &htrans, FALSE)) return NULL; if (PyWinObject_AsWCHAR(oblinkname, &linkname, FALSE) && PyWinObject_AsWCHAR(obtargetname, &targetname, FALSE)){ ! if (!(*pfnCreateSymbolicLinkTransacted)(linkname, targetname, flags, htrans)) ! PyWin_SetAPIError("CreateSymbolicLinkTransacted"); else{ Py_INCREF(Py_None); --- 2941,2975 ---- // @comm This method only exists on Vista and later. // @comm Accepts keyword args. ! // @comm Requires SeCreateSymbolicLink priv. ! // @comm If the Transaction parameter is passed in, CreateSymbolicLinkTransacted will be called WCHAR *linkname=NULL, *targetname=NULL; ! PyObject *oblinkname, *obtargetname, *obtrans=Py_None, *ret=NULL; DWORD flags=0; HANDLE htrans; static char *keywords[]={"SymlinkFileName","TargetFileName","Flags","Transaction", NULL}; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|kO:CreateSymbolicLink", keywords, &oblinkname, // @pyparm <o PyUnicode>|SymlinkFileName||Path of the symbolic link to be created &obtargetname, // @pyparm <o PyUnicode>|TargetFileName||The name of file to which link will point ! &flags, // @pyparm int|Flags|0|SYMLINK_FLAG_DIRECTORY is only defined flag ! &obtrans)) // @pyparm <o PyHANDLE>|Transaction|None|Handle to a transaction, as returned by <om win32transaction.CreateTransaction> return NULL; + if (!PyWinObject_AsHANDLE(obtrans, &htrans, TRUE)) + return NULL; + if (htrans){ + CHECK_PFN(CreateSymbolicLinkTransacted); + } + else{ + CHECK_PFN(CreateSymbolicLink); + } + if (PyWinObject_AsWCHAR(oblinkname, &linkname, FALSE) && PyWinObject_AsWCHAR(obtargetname, &targetname, FALSE)){ ! BOOL bsuccess; ! if (htrans) ! bsuccess=(*pfnCreateSymbolicLinkTransacted)(linkname, targetname, flags, htrans); ! else ! bsuccess=(*pfnCreateSymbolicLink)(linkname, targetname, flags); ! if (!bsuccess) ! PyWin_SetAPIError("CreateSymbolicLink"); else{ Py_INCREF(Py_None); *************** *** 3103,3107 **** return ret; } ! PyCFunction pfnpy_CreateSymbolicLinkTransacted=(PyCFunction)py_CreateSymbolicLinkTransacted; // @pyswig |EncryptFile|Encrypts specified file (requires Win2k or higher and NTFS) --- 2981,2985 ---- return ret; } ! PyCFunction pfnpy_CreateSymbolicLink=(PyCFunction)py_CreateSymbolicLink; // @pyswig |EncryptFile|Encrypts specified file (requires Win2k or higher and NTFS) *************** *** 4949,4952 **** --- 4827,4996 ---- return PyBool_FromLong(ret); } + + // @pyswig <o PyUnicode>|GetLongPathName|Retrieves the long path for a short path (8.3 filename) + // @comm Accepts keyword args + static PyObject *py_GetLongPathName(PyObject *self, PyObject *args, PyObject *kwargs) + { + PyObject *ret=NULL; + DWORD pathlen=MAX_PATH+1, retlen; + WCHAR *short_path=NULL, *long_path=NULL, *long_path_save=NULL; + PyObject *obfname, *obtrans=Py_None; + HANDLE htrans; + static char *keywords[]={"ShortPath","Transaction", NULL}; + #ifdef Py_DEBUG + pathlen=3; // test reallocation logic + #endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:GetLongPathName", keywords, + &obfname, // @pyparm <o PyUnicode>|ShortPath||8.3 path to be expanded + &obtrans)) // @pyparm <o PyHANDLE>|Transaction|None|Handle to a transaction. If specified, GetLongPathNameTransacted will be called. + return NULL; + if (!PyWinObject_AsHANDLE(obtrans, &htrans, TRUE)) + return NULL; + if (htrans){ + CHECK_PFN(GetLongPathNameTransacted); + } + else{ + CHECK_PFN(GetLongPathName); + } + if (!PyWinObject_AsWCHAR(obfname, &short_path, FALSE)) + return NULL; + + while (1){ + if (long_path){ + long_path_save=long_path; + long_path=(WCHAR *)realloc(long_path, pathlen*sizeof(WCHAR)); + } + else + long_path=(WCHAR *)malloc(pathlen*sizeof(WCHAR)); + if (long_path==NULL){ + if (long_path_save) + free(long_path_save); + PyErr_Format(PyExc_MemoryError,"Unable to allocate %d bytes", pathlen*sizeof(WCHAR)); + break; + } + Py_BEGIN_ALLOW_THREADS + if (htrans) + retlen=(*pfnGetLongPathNameTransacted)(short_path, long_path, pathlen, htrans); + else + retlen=(*pfnGetLongPathName)(short_path, long_path, pathlen); + Py_END_ALLOW_THREADS + if (retlen==0){ + PyWin_SetAPIError("GetLongPathName"); + break; + } + if (retlen<=pathlen){ + ret=PyUnicode_FromWideChar(long_path,retlen); + break; + } + pathlen=retlen+1; + } + + PyWinObject_FreeWCHAR(short_path); + if (long_path) + free(long_path); + return ret; + } + PyCFunction pfnpy_GetLongPathName=(PyCFunction)py_GetLongPathName; + + // @pyswig str/unicode|GetFullPathName|Returns full path for path passed in + // @comm This function takes either a plain string or a unicode string, and returns the same type + // If unicode is passed in, GetFullPathNameW is called, which supports filenames longer than MAX_PATH + // @comm If Transaction parameter is specified, GetFullPathNameTransacted is called (requires Vista or later) + static PyObject *py_GetFullPathName(PyObject *self, PyObject *args, PyObject *kwargs) + { + HANDLE htrans; + PyObject *obtrans=Py_None, *ret=NULL, *obpathin; + DWORD pathlen=MAX_PATH+1, retlen; + static char *keywords[]={"FileName","Transaction", NULL}; + #ifdef Py_DEBUG + pathlen=3; // test reallocation logic + #endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:GetFullPathName", keywords, + &obpathin, // @pyparm str/unicode|FileName||Path on which to operate + &obtrans)) // @pyparm <o PyHANDLE>|Transaction|None|Handle to a transaction as returned by <om win32transaction.CreateTransaction> + return NULL; + if (!PyWinObject_AsHANDLE(obtrans, &htrans, TRUE)) + return NULL; + + WCHAR *wpathin; + if (wpathin=PyUnicode_AsUnicode(obpathin)){ + if (htrans) + CHECK_PFN(GetFullPathNameTransactedW); + WCHAR *wpathret=NULL, *wfilepart, *wpathsave=NULL; + while (1){ + if (wpathret){ + wpathsave=wpathret; + wpathret=(WCHAR *)realloc(wpathret,pathlen*sizeof(WCHAR)); + } + else + wpathret=(WCHAR *)malloc(pathlen*sizeof(WCHAR)); + if (wpathret==NULL){ + if (wpathsave) + free(wpathsave); + PyErr_SetString(PyExc_MemoryError,"GetFullPathNameW: unable to allocate unicode return buffer"); + return NULL; + } + Py_BEGIN_ALLOW_THREADS + if (htrans) + retlen=(*pfnGetFullPathNameTransactedW)(wpathin, pathlen, wpathret, &wfilepart, htrans); + else + retlen=GetFullPathNameW(wpathin, pathlen, wpathret, &wfilepart); + Py_END_ALLOW_THREADS + if (retlen==0){ + PyWin_SetAPIError("GetFullPathNameW"); + break; + } + if (retlen<=pathlen){ + ret=PyUnicode_FromWideChar(wpathret,retlen); + break; + } + pathlen=retlen; + } + free(wpathret); + return ret; + } + + PyErr_Clear(); + char *cpathin; + if (cpathin=PyString_AsString(obpathin)){ + if (htrans) + CHECK_PFN(GetFullPathNameTransactedA); + char *cpathret=NULL, *cfilepart, *cpathsave=NULL; + while (1){ + if (cpathret){ + cpathsave=cpathret; + cpathret=(char *)realloc(cpathret,pathlen); + } + else + cpathret=(char *)malloc(pathlen); + if (cpathret==NULL){ + if (cpathsave) + free(cpathsave); + PyErr_SetString(PyExc_MemoryError,"GetFullPathNameW: unable to allocate unicode return buffer"); + return NULL; + } + Py_BEGIN_ALLOW_THREADS + if (htrans) + retlen=(*pfnGetFullPathNameTransactedA)(cpathin, pathlen, cpathret, &cfilepart, htrans); + else + retlen=GetFullPathNameA(cpathin, pathlen, cpathret, &cfilepart); + Py_END_ALLOW_THREADS + if (retlen==0){ + PyWin_SetAPIError("GetFullPathNameA"); + break; + } + if (retlen<=pathlen){ + ret=PyString_FromStringAndSize(cpathret,retlen); + break; + } + pathlen=retlen; + } + free(cpathret); + } + return ret; + } + PyCFunction pfnpy_GetFullPathName=(PyCFunction)py_GetFullPathName; %} *************** *** 4958,4964 **** %native (CreateHardLink) pfnpy_CreateHardLink; - %native (CreateHardLinkTransacted) pfnpy_CreateHardLinkTransacted; %native (CreateSymbolicLink) pfnpy_CreateSymbolicLink; - %native (CreateSymbolicLinkTransacted) pfnpy_CreateSymbolicLinkTransacted; // end of win2k volume mount functions. --- 5002,5006 ---- *************** *** 4997,5000 **** --- 5039,5044 ---- %native (FindFileNames) pfnpy_FindFileNames; %native (GetFinalPathNameByHandle) pfnpy_GetFinalPathNameByHandle; + %native (GetLongPathName) pfnpy_GetLongPathName; + %native (GetFullPathName) pfnpy_GetFullPathName; %native (SfcGetNextProtectedFile) py_SfcGetNextProtectedFile; *************** *** 5015,5021 **** ||(strcmp(pmd->ml_name, "SetFileAttributesTransacted")==0) ||(strcmp(pmd->ml_name, "CreateHardLink")==0) - ||(strcmp(pmd->ml_name, "CreateHardLinkTransacted")==0) ||(strcmp(pmd->ml_name, "CreateSymbolicLink")==0) - ||(strcmp(pmd->ml_name, "CreateSymbolicLinkTransacted")==0) ||(strcmp(pmd->ml_name, "CreateDirectoryTransacted")==0) ||(strcmp(pmd->ml_name, "RemoveDirectoryTransacted")==0) --- 5059,5063 ---- *************** *** 5031,5036 **** ||(strcmp(pmd->ml_name, "GetVolumePathNamesForVolumeName")==0) ||(strcmp(pmd->ml_name, "DuplicateEncryptionInfoFile")==0) ! ||(strcmp(pmd->ml_name, "GetFullPathNameTransacted")==0) // not impl yet ! ||(strcmp(pmd->ml_name, "GetLongPathNameTransacted")==0) // not impl yet ||(strcmp(pmd->ml_name, "GetFileInformationByHandleEx")==0) // not impl yet ) --- 5073,5078 ---- ||(strcmp(pmd->ml_name, "GetVolumePathNamesForVolumeName")==0) ||(strcmp(pmd->ml_name, "DuplicateEncryptionInfoFile")==0) ! ||(strcmp(pmd->ml_name, "GetLongPathName")==0) ! ||(strcmp(pmd->ml_name, "GetFullPathName")==0) ||(strcmp(pmd->ml_name, "GetFileInformationByHandleEx")==0) // not impl yet ) *************** *** 5096,5103 **** pfnFindNextFileName=(FindNextFileNamefunc)GetProcAddress(hmodule, "FindNextFileNameW"); pfnGetFinalPathNameByHandle=(GetFinalPathNameByHandlefunc)GetProcAddress(hmodule, "GetFinalPathNameByHandleW"); ! ! // these aren't wrapped yet ! pfnGetFullPathNameTransacted=(GetFullPathNameTransactedfunc)GetProcAddress(hmodule, "GetFullPathNameTransactedW"); pfnGetLongPathNameTransacted=(GetLongPathNameTransactedfunc)GetProcAddress(hmodule, "GetLongPathNameTransactedW"); // pfnGetFileInformationByHandleEx=(GetFileInformationByHandleExfunc)GetProcAddress(hmodule, "GetFileInformationByHandleEx"); } --- 5138,5145 ---- pfnFindNextFileName=(FindNextFileNamefunc)GetProcAddress(hmodule, "FindNextFileNameW"); pfnGetFinalPathNameByHandle=(GetFinalPathNameByHandlefunc)GetProcAddress(hmodule, "GetFinalPathNameByHandleW"); ! pfnGetLongPathName=(GetLongPathNamefunc)GetProcAddress(hmodule, "GetLongPathNameW"); pfnGetLongPathNameTransacted=(GetLongPathNameTransactedfunc)GetProcAddress(hmodule, "GetLongPathNameTransactedW"); + pfnGetFullPathNameTransactedW=(GetFullPathNameTransactedWfunc)GetProcAddress(hmodule, "GetFullPathNameTransactedW"); + pfnGetFullPathNameTransactedA=(GetFullPathNameTransactedAfunc)GetProcAddress(hmodule, "GetFullPathNameTransactedA"); // pfnGetFileInformationByHandleEx=(GetFileInformationByHandleExfunc)GetProcAddress(hmodule, "GetFileInformationByHandleEx"); } |