Win32OperatingSystem.st
changeset 11289 11c2bb7debc4
parent 11258 5117e5bd0dc3
child 11291 1e7c06d9d939
equal deleted inserted replaced
11288:c71a04b0e26c 11289:11c2bb7debc4
  4517 
  4517 
  4518     ^ $\
  4518     ^ $\
  4519 !
  4519 !
  4520 
  4520 
  4521 getCurrentDirectory
  4521 getCurrentDirectory
  4522 
       
  4523     |s size|
  4522     |s size|
  4524 
  4523 
  4525     s := String new:200.
  4524     s := Unicode16String new:1024.
  4526     size := self primGetCurrentDirectory:200 string: s.
  4525     size := self primGetCurrentDirectoryW:1024 string: s.
  4527     (size isNil or:[size == 0]) ifTrue:[^ ''].
  4526     (size isNil or:[size == 0]) ifTrue:[^ ''].
  4528     ^ s copyFrom:1 to: size
  4527     ^ (s copyFrom:1 to: size) asSingleByteStringIfPossible
  4529 
  4528 
  4530     "
  4529     "
  4531 	self getCurrentDirectory
  4530      self getCurrentDirectory 
  4532     "
  4531     "
  4533 !
  4532 !
  4534 
  4533 
  4535 getDiskInfoOf:volumeNameArg
  4534 getDiskInfoOf:volumeNameArg
  4536     "returns a dictionary filled with any of:
  4535     "returns a dictionary filled with any of:
  4666 %}.
  4665 %}.
  4667     ^ list
  4666     ^ list
  4668 !
  4667 !
  4669 
  4668 
  4670 getDriveType:aPathName
  4669 getDriveType:aPathName
  4671     "return true, if the given file is writable.
  4670     "returns:
  4672      For symbolic links, the pointed-to-file is checked."
  4671         0 -> Unknown
       
  4672         1 -> Invalid
       
  4673         2 -> removable
       
  4674         3 -> fixed
       
  4675         4 -> remote
       
  4676         5 -> cdrom
       
  4677         6 -> ramdisk.
       
  4678     This is a stupid interface - do not use."
  4673 
  4679 
  4674 %{
  4680 %{
  4675     int ret;
  4681     int ret;
  4676 
  4682 
  4677     if (__isString(aPathName)) {
  4683     if (__isString(aPathName)) {
  4678 #ifdef DO_WRAP_CALLS
  4684 #ifdef DO_WRAP_CALLS
  4679 	char _aPathName[MAXPATHLEN];
  4685         char _aPathName[MAXPATHLEN];
  4680 
  4686 
  4681 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4687         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4682 	do {
  4688         do {
  4683 	    __threadErrno = 0;
  4689             __threadErrno = 0;
  4684 	    ret = STX_API_CALL1( "GetDriveType", GetDriveType, _aPathName);
  4690             ret = STX_API_CALL1( "GetDriveType", GetDriveType, _aPathName);
  4685 	} while ((ret < 0) && (__threadErrno == EINTR));
  4691         } while ((ret < 0) && (__threadErrno == EINTR));
  4686 #else
  4692 #else
  4687 	ret = GetFileAttributes((char *) __stringVal(aPathName));
  4693         ret = GetFileAttributes((char *) __stringVal(aPathName));
  4688 	if (ret < 0) {
  4694         if (ret < 0) {
  4689 	    __threadErrno = __WIN32_ERR(GetLastError());
  4695             __threadErrno = __WIN32_ERR(GetLastError());
  4690 	}
  4696         }
  4691 #endif
  4697 #endif
  4692 	RETURN (ret);
  4698         RETURN (__MKSMALLINT(ret));
  4693     }
  4699     }
  4694 %}.
  4700 %}.
  4695     ^ self primitiveFailed
  4701     ^ self primitiveFailed
       
  4702 
       
  4703     "
       
  4704      self getDriveType:'x:\'  
       
  4705      self getDriveType:'C:\'  
       
  4706      self getDriveType:'D:\'
       
  4707     "
  4696 !
  4708 !
  4697 
  4709 
  4698 getFileVersionInfoOf:aPathName
  4710 getFileVersionInfoOf:aPathName
  4699     "retrieves the versionData from an executable or dll.
  4711     "retrieves the versionData from an executable or dll.
  4700      The returned value is either a byteArray, which should be
  4712      The returned value is either a byteArray, which should be
  4801      (i.e. exists and is a directory).
  4813      (i.e. exists and is a directory).
  4802      This also returns true for symbolic links pointing to a directory;
  4814      This also returns true for symbolic links pointing to a directory;
  4803      if you need to check for this, use #linkInfo:."
  4815      if you need to check for this, use #linkInfo:."
  4804 
  4816 
  4805 %{
  4817 %{
       
  4818     int ret;
       
  4819 
  4806     if (__isString(aPathName)) {
  4820     if (__isString(aPathName)) {
  4807 	int ret;
       
  4808 
       
  4809 #ifdef DO_WRAP_CALLS
  4821 #ifdef DO_WRAP_CALLS
  4810 	char _aPathName[MAXPATHLEN];
  4822         char _aPathName[MAXPATHLEN];
  4811 
  4823 
  4812 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4824         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4813 	do {
  4825         do {
  4814 	    __threadErrno = 0;
  4826             __threadErrno = 0;
  4815 	    ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  4827             ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  4816 	} while ((ret < 0) && (__threadErrno == EINTR));
  4828         } while ((ret < 0) && (__threadErrno == EINTR));
  4817 #else
  4829 #else
  4818 	ret = GetFileAttributesA((char *) __stringVal(aPathName));
  4830         ret = GetFileAttributesA((char *) __stringVal(aPathName));
  4819 	if (ret < 0) {
  4831         if (ret < 0) {
  4820 	    __threadErrno = __WIN32_ERR(GetLastError());
  4832             __threadErrno = __WIN32_ERR(GetLastError());
  4821 	}
  4833         }
  4822 #endif
  4834 #endif
  4823 	if (ret < 0) {
  4835         if (ret < 0) {
  4824 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4836             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4825 	    RETURN ( false );
  4837             RETURN ( false );
  4826 	}
  4838         }
  4827 	RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
  4839         RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
  4828     }
  4840     }
  4829 
  4841 
  4830 #ifdef SUPPORT_WIDE_CHAR_FILENAMES
       
  4831     if (__isUnicode16String(aPathName)) {
  4842     if (__isUnicode16String(aPathName)) {
  4832 	int ret;
  4843         wchar_t _wPathName[MAXPATHLEN+1];
  4833 
  4844         int i, l;
       
  4845 
       
  4846         l = __unicode16StringSize(aPathName);
       
  4847         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  4848         for (i=0; i<l; i++) {
       
  4849             _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  4850         }
       
  4851         _wPathName[i] = 0;
  4834 #ifdef DO_WRAP_CALLS
  4852 #ifdef DO_WRAP_CALLS
  4835 	unsigned char _wPathName[MAXPATHLEN];
  4853         do {
  4836 	int i;
  4854             __threadErrno = 0;
  4837 
  4855             ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
  4838 # if 1
  4856         } while ((ret < 0) && (__threadErrno == EINTR));
  4839 	for (i=0; i<MAXPATHLEN; i++) {
       
  4840 	    _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  4841 	    if (_wPathName[i] == 0) break;
       
  4842 	}
       
  4843 # else
       
  4844 	wstrncpy(_wPathName, __unicode16StringVal(aPathName), MAXPATHLEN-1); _wPathName[MAXPATHLEN-1] = '\0';
       
  4845 # endif
       
  4846 	do {
       
  4847 	    __threadErrno = 0;
       
  4848 	    ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
       
  4849 	} while ((ret < 0) && (__threadErrno == EINTR));
       
  4850 #else
  4857 #else
  4851 	ret = GetFileAttributesW(__unicode16StringVal(wPathName));
  4858         ret = GetFileAttributesW(_wPathName);
  4852 	if (ret < 0) {
  4859         if (ret < 0) {
  4853 	    __threadErrno = __WIN32_ERR(GetLastError());
  4860             __threadErrno = __WIN32_ERR(GetLastError());
  4854 	}
  4861         }
  4855 #endif
  4862 #endif
  4856 	if (ret < 0) {
  4863         if (ret < 0) {
  4857 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4864             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4858 	    RETURN ( false );
  4865             RETURN ( false );
  4859 	}
  4866         }
  4860 	RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
  4867         RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
  4861     }
  4868     }
  4862 #endif /* SUPPORT_WIDE_CHAR_FILENAMES */
       
  4863 %}.
  4869 %}.
  4864     ^ self primitiveFailed
  4870     ^ self primitiveFailed
  4865 
  4871 
  4866     "an alternative implementation would be:
  4872     "an alternative implementation would be:
  4867 	^ (self infoOf:aPathName) type == #directory
  4873         ^ (self infoOf:aPathName) type == #directory
       
  4874     "
       
  4875     "
       
  4876      self isDirectory:'.'  
       
  4877      self isDirectory:'.' asUnicode16String
  4868     "
  4878     "
  4869 
  4879 
  4870     "Modified: / 05-07-2006 / 17:23:42 / cg"
  4880     "Modified: / 05-07-2006 / 17:23:42 / cg"
  4871 !
  4881 !
  4872 
  4882 
  4889 %{
  4899 %{
  4890     int ret;
  4900     int ret;
  4891 
  4901 
  4892     if (__isString(aPathName)) {
  4902     if (__isString(aPathName)) {
  4893 #ifdef DO_WRAP_CALLS
  4903 #ifdef DO_WRAP_CALLS
  4894 	char _aPathName[MAXPATHLEN];
  4904         char _aPathName[MAXPATHLEN];
  4895 
  4905 
  4896 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4906         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4897 	do {
  4907         do {
  4898 	    __threadErrno = 0;
  4908             __threadErrno = 0;
  4899 	    ret = STX_API_CALL1( "GetFileAttributes", GetFileAttributes, _aPathName);
  4909             ret = STX_API_CALL1( "GetFileAttributes", GetFileAttributes, _aPathName);
  4900 	} while ((ret < 0) && (__threadErrno == EINTR));
  4910         } while ((ret < 0) && (__threadErrno == EINTR));
  4901 #else
  4911 #else
  4902 	ret = GetFileAttributes((char *) __stringVal(aPathName));
  4912         ret = GetFileAttributes((char *) __stringVal(aPathName));
  4903 	if (ret < 0) {
  4913         if (ret < 0) {
  4904 	    __threadErrno = __WIN32_ERR(GetLastError());
  4914             __threadErrno = __WIN32_ERR(GetLastError());
  4905 	}
  4915         }
  4906 #endif
  4916 #endif
  4907 	if (ret < 0) {
  4917         if (ret < 0) {
  4908 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4918             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4909 	    RETURN ( false );
  4919             RETURN ( false );
  4910 	}
  4920         }
  4911 	RETURN ( (ret & FILE_ATTRIBUTE_HIDDEN) ? true : false);
  4921         RETURN ( (ret & FILE_ATTRIBUTE_HIDDEN) ? true : false);
       
  4922     }
       
  4923 
       
  4924     if (__isUnicode16String(aPathName)) {
       
  4925         wchar_t _wPathName[MAXPATHLEN+1];
       
  4926         int i, l;
       
  4927 
       
  4928         l = __unicode16StringSize(aPathName);
       
  4929         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  4930         for (i=0; i<l; i++) {
       
  4931             _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  4932         }
       
  4933         _wPathName[i] = 0;
       
  4934 #ifdef DO_WRAP_CALLS
       
  4935         do {
       
  4936             __threadErrno = 0;
       
  4937             ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
       
  4938         } while ((ret < 0) && (__threadErrno == EINTR));
       
  4939 #else
       
  4940         ret = GetFileAttributesW(_wPathName);
       
  4941         if (ret < 0) {
       
  4942             __threadErrno = __WIN32_ERR(GetLastError());
       
  4943         }
       
  4944 #endif
       
  4945         if (ret < 0) {
       
  4946             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
       
  4947             RETURN ( false );
       
  4948         }
       
  4949         RETURN ( (ret & FILE_ATTRIBUTE_HIDDEN) ? true : false);
  4912     }
  4950     }
  4913 %}.
  4951 %}.
  4914     ^ self primitiveFailed
  4952     ^ self primitiveFailed
       
  4953 
       
  4954     "
       
  4955      self isHidden:'.'      
       
  4956      self isHidden:'.' asUnicode16String  
       
  4957     "
  4915 !
  4958 !
  4916 
  4959 
  4917 isReadable:aPathName
  4960 isReadable:aPathName
  4918     "return true, if the file/dir 'aPathName' is readable.
  4961     "return true, if the file/dir 'aPathName' is readable.
  4919      For symbolic links, the pointed-to-file is checked."
  4962      For symbolic links, the pointed-to-file is checked."
  4920 
  4963 
  4921 %{
  4964 %{
  4922     if (__isString(aPathName)) {
  4965     if (__isString(aPathName)) {
  4923 	int ret;
  4966         int ret;
  4924 
  4967 
  4925 	/*
  4968         /*
  4926 	 * under windows, all files are readable ...
  4969          * under windows, all files are readable ...
  4927 	 * so, only check for the files existence here.
  4970          * so, only check for the files existence here.
  4928 	 */
  4971          */
  4929 #ifdef DO_WRAP_CALLS
  4972 #ifdef DO_WRAP_CALLS
  4930 	char _aPathName[MAXPATHLEN];
  4973         char _aPathName[MAXPATHLEN];
  4931 
  4974 
  4932 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4975         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  4933 	do {
  4976         do {
  4934 	    __threadErrno = 0;
  4977             __threadErrno = 0;
  4935 	    ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  4978             ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  4936 	} while ((ret < 0) && (__threadErrno == EINTR));
  4979         } while ((ret < 0) && (__threadErrno == EINTR));
  4937 #else
  4980 #else
  4938 	ret = GetFileAttributesA((char *) __stringVal(aPathName));
  4981         ret = GetFileAttributesA((char *) __stringVal(aPathName));
  4939 	if (ret < 0) {
  4982         if (ret < 0) {
  4940 	    __threadErrno = __WIN32_ERR(GetLastError());
  4983             __threadErrno = __WIN32_ERR(GetLastError());
  4941 	}
  4984         }
  4942 #endif
  4985 #endif
  4943 	if (ret < 0) {
  4986         if (ret < 0) {
  4944 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4987             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4945 	    RETURN (false);
  4988             RETURN (false);
  4946 	}
  4989         }
  4947 	RETURN (true);
  4990         RETURN (true);
  4948     }
  4991     }
  4949 
  4992 
  4950 #ifdef SUPPORT_WIDE_CHAR_FILENAMES
       
  4951     if (__isUnicode16String(aPathName)) {
  4993     if (__isUnicode16String(aPathName)) {
  4952 	int ret;
  4994         int ret;
  4953 
  4995 
  4954 	/*
  4996         /*
  4955 	 * under windows, all files are readable ...
  4997          * under windows, all files are readable ...
  4956 	 * so, only check for the files existence here.
  4998          * so, only check for the files existence here.
  4957 	 */
  4999          */
       
  5000         wchar_t _wPathName[MAXPATHLEN+1];
       
  5001         int i, l;
       
  5002 
       
  5003         l = __unicode16StringSize(aPathName);
       
  5004         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  5005         for (i=0; i<l; i++) {
       
  5006             _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5007         }
       
  5008         _wPathName[i] = 0;
  4958 #ifdef DO_WRAP_CALLS
  5009 #ifdef DO_WRAP_CALLS
  4959 	unsigned short _wPathName[MAXPATHLEN];
  5010         do {
  4960 
  5011             __threadErrno = 0;
  4961 # if 1
  5012             ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
  4962 	int i;
  5013         } while ((ret < 0) && (__threadErrno == EINTR));
  4963 	for (i=0; i<MAXPATHLEN; i++) {
       
  4964 	    _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  4965 	    if (_wPathName[i] == 0) break;
       
  4966 	}
       
  4967 # else
       
  4968 	wstrncpy(_wPathName, __unicode16StringVal(aPathName), MAXPATHLEN-1); _wPathName[MAXPATHLEN-1] = '\0';
       
  4969 # endif
       
  4970 	do {
       
  4971 	    __threadErrno = 0;
       
  4972 	    ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
       
  4973 	} while ((ret < 0) && (__threadErrno == EINTR));
       
  4974 #else
  5014 #else
  4975 	ret = GetFileAttributesW(__unicode16StringVal(aPathName));
  5015         ret = GetFileAttributesW(_wPathName);
  4976 	if (ret < 0) {
  5016         if (ret < 0) {
  4977 	    __threadErrno = __WIN32_ERR(GetLastError());
  5017             __threadErrno = __WIN32_ERR(GetLastError());
  4978 	}
  5018         }
  4979 #endif
  5019 #endif
  4980 	if (ret < 0) {
  5020         if (ret < 0) {
  4981 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5021             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  4982 	    RETURN (false);
  5022             RETURN (false);
  4983 	}
  5023         }
  4984 	RETURN (true);
  5024         RETURN (true);
  4985     }
  5025     }
  4986 #endif /* SUPPORT_WIDE_CHAR_FILENAMES */
       
  4987 %}.
  5026 %}.
  4988     ^ self primitiveFailed
  5027     ^ self primitiveFailed
  4989 
  5028 
  4990     "Modified: / 05-07-2006 / 17:23:39 / cg"
  5029     "
       
  5030      self isReadable:'.'  
       
  5031      self isReadable:'.' asUnicode16String 
       
  5032     "
  4991 !
  5033 !
  4992 
  5034 
  4993 isValidPath:aPathName
  5035 isValidPath:aPathName
  4994     "return true, if 'aPathName' is a valid path name
  5036     "return true, if 'aPathName' is a valid path name
  4995      (i.e. the file or directory exists)"
  5037      (i.e. the file or directory exists)"
  4997 %{
  5039 %{
  4998     int ret;
  5040     int ret;
  4999 
  5041 
  5000     if (__isString(aPathName) || __isSymbol(aPathName)) {
  5042     if (__isString(aPathName) || __isSymbol(aPathName)) {
  5001 #ifdef DO_WRAP_CALLS
  5043 #ifdef DO_WRAP_CALLS
  5002 	char _aPathName[MAXPATHLEN];
  5044         char _aPathName[MAXPATHLEN];
  5003 
  5045 
  5004 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5046         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5005 	do {
  5047         do {
  5006 	    __threadErrno = 0;
  5048             __threadErrno = 0;
  5007 	    ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  5049             ret = STX_API_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName);
  5008 	} while ((ret < 0) && (__threadErrno == EINTR));
  5050         } while ((ret < 0) && (__threadErrno == EINTR));
  5009 #else
  5051 #else
  5010 	ret = GetFileAttributesA((char *) __stringVal(aPathName));
  5052         ret = GetFileAttributesA((char *) __stringVal(aPathName));
  5011 	if (ret < 0) {
  5053         if (ret < 0) {
  5012 	    __threadErrno = __WIN32_ERR(GetLastError());
  5054             __threadErrno = __WIN32_ERR(GetLastError());
  5013 	}
  5055         }
  5014 #endif
  5056 #endif
  5015 	if (ret < 0) {
  5057         if (ret < 0) {
  5016 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5058             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5017 	    RETURN ( false );
  5059             RETURN ( false );
  5018 	}
  5060         }
  5019 	RETURN (true);
  5061         RETURN (true);
  5020     }
  5062     }
  5021 
  5063 
  5022 #ifdef SUPPORT_WIDE_CHAR_FILENAMES
       
  5023     if (__isUnicode16String(aPathName)) {
  5064     if (__isUnicode16String(aPathName)) {
       
  5065         wchar_t _wPathName[MAXPATHLEN+1];
       
  5066         int i, l;
       
  5067 
       
  5068         l = __unicode16StringSize(aPathName);
       
  5069         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  5070         for (i=0; i<l; i++) {
       
  5071             _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5072         }
       
  5073         _wPathName[i] = 0;
  5024 #ifdef DO_WRAP_CALLS
  5074 #ifdef DO_WRAP_CALLS
  5025 	unsigned short _wPathName[MAXPATHLEN];
  5075         do {
  5026 # if 1
  5076             __threadErrno = 0;
  5027 	int i;
  5077             ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
  5028 	for (i=0; i<MAXPATHLEN; i++) {
  5078         } while ((ret < 0) && (__threadErrno == EINTR));
  5029 	    _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5030 	    if (_wPathName[i] == 0) break;
       
  5031 	}
       
  5032 # else
       
  5033 	wstrncpy(_wPathName, __unicode16StringVal(aPathName), MAXPATHLEN-1); _wPathName[MAXPATHLEN-1] = '\0';
       
  5034 # endif
       
  5035 	do {
       
  5036 	    __threadErrno = 0;
       
  5037 	    ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
       
  5038 	} while ((ret < 0) && (__threadErrno == EINTR));
       
  5039 #else
  5079 #else
  5040 	ret = GetFileAttributesW(__unicode16StringVal(wPathName));
  5080         ret = GetFileAttributesW(_wPathName);
  5041 	if (ret < 0) {
  5081         if (ret < 0) {
  5042 	    __threadErrno = __WIN32_ERR(GetLastError());
  5082             __threadErrno = __WIN32_ERR(GetLastError());
  5043 	}
  5083         }
  5044 #endif
  5084 #endif
  5045 	if (ret < 0) {
  5085         if (ret < 0) {
  5046 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5086             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5047 	    RETURN ( false );
  5087             RETURN ( false );
  5048 	}
  5088         }
  5049 	RETURN (true);
  5089         RETURN (true);
  5050     }
  5090     }
  5051 #endif /* SUPPORT_WIDE_CHAR_FILENAMES */
       
  5052 %}.
  5091 %}.
  5053     ^ self primitiveFailed
  5092     ^ self primitiveFailed
  5054 
  5093 
  5055     "Modified: / 05-07-2006 / 17:23:51 / cg"
  5094     "Modified: / 05-07-2006 / 17:23:51 / cg"
  5056 !
  5095 !
  5062 %{
  5101 %{
  5063     int ret;
  5102     int ret;
  5064 
  5103 
  5065     if (__isString(aPathName)) {
  5104     if (__isString(aPathName)) {
  5066 #ifdef DO_WRAP_CALLS
  5105 #ifdef DO_WRAP_CALLS
  5067 	char _aPathName[MAXPATHLEN];
  5106         char _aPathName[MAXPATHLEN];
  5068 
  5107 
  5069 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5108         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5070 	do {
  5109         do {
  5071 	    __threadErrno = 0;
  5110             __threadErrno = 0;
  5072 	    ret = STX_API_CALL1( "GetFileAttributes", GetFileAttributes, _aPathName);
  5111             ret = STX_API_CALL1( "GetFileAttributes", GetFileAttributes, _aPathName);
  5073 	} while ((ret < 0) && (__threadErrno == EINTR));
  5112         } while ((ret < 0) && (__threadErrno == EINTR));
  5074 #else
  5113 #else
  5075 	ret = GetFileAttributes((char *) __stringVal(aPathName));
  5114         ret = GetFileAttributes((char *) __stringVal(aPathName));
  5076 	if (ret < 0) {
  5115         if (ret < 0) {
  5077 	    __threadErrno = __WIN32_ERR(GetLastError());
  5116             __threadErrno = __WIN32_ERR(GetLastError());
  5078 	}
  5117         }
  5079 #endif
  5118 #endif
  5080 	if (ret < 0) {
  5119         if (ret < 0) {
  5081 	    @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5120             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5082 	    RETURN ( false );
  5121             RETURN ( false );
  5083 	}
  5122         }
  5084 	RETURN ( (ret & FILE_ATTRIBUTE_READONLY) ? false : true);
  5123         RETURN ( (ret & FILE_ATTRIBUTE_READONLY) ? false : true);
       
  5124     }
       
  5125     if (__isUnicode16String(aPathName)) {
       
  5126         int ret;
       
  5127 
       
  5128         /*
       
  5129          * under windows, all files are readable ...
       
  5130          * so, only check for the files existence here.
       
  5131          */
       
  5132         wchar_t _wPathName[MAXPATHLEN+1];
       
  5133         int i, l;
       
  5134 
       
  5135         l = __unicode16StringSize(aPathName);
       
  5136         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  5137         for (i=0; i<l; i++) {
       
  5138             _wPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5139         }
       
  5140         _wPathName[i] = 0;
       
  5141 #ifdef DO_WRAP_CALLS
       
  5142         do {
       
  5143             __threadErrno = 0;
       
  5144             ret = STX_API_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName);
       
  5145         } while ((ret < 0) && (__threadErrno == EINTR));
       
  5146 #else
       
  5147         ret = GetFileAttributesW(_wPathName);
       
  5148         if (ret < 0) {
       
  5149             __threadErrno = __WIN32_ERR(GetLastError());
       
  5150         }
       
  5151 #endif
       
  5152         if (ret < 0) {
       
  5153             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
       
  5154             RETURN (false);
       
  5155         }
       
  5156         RETURN ( (ret & FILE_ATTRIBUTE_READONLY) ? false : true);
  5085     }
  5157     }
  5086 %}.
  5158 %}.
  5087     ^ self primitiveFailed
  5159     ^ self primitiveFailed
       
  5160 
       
  5161     "
       
  5162      self isWritable:'.'  
       
  5163      self isWritable:'.' asUnicode16String   
       
  5164     "
  5088 !
  5165 !
  5089 
  5166 
  5090 linkInfoOf:aPathName
  5167 linkInfoOf:aPathName
  5091     "return some object filled with info for the file 'aPathName';
  5168     "return some object filled with info for the file 'aPathName';
  5092      the info (for which corresponding access methods are understood by
  5169      the info (for which corresponding access methods are understood by
  5116      mYr mMon mDay mHr mMin mSec mMS
  5193      mYr mMon mDay mHr mMin mSec mMS
  5117      cYr cMon cDay cHr cMin cSec cMS
  5194      cYr cMon cDay cHr cMin cSec cMS
  5118      fileName alternativeName|
  5195      fileName alternativeName|
  5119 
  5196 
  5120 %{
  5197 %{
       
  5198     HANDLE hFile = (HANDLE)0;
  5121     int ret;
  5199     int ret;
  5122     char alternativeFileNameBuffer[15];
  5200     wchar_t alternativeFileNameBuffer[15];
  5123     char fileNameBuffer[MAX_PATH+1];
  5201     wchar_t fileNameBuffer[MAX_PATH+1];
  5124 
  5202     FILETIME tempFileTime;
       
  5203     SYSTEMTIME creationTime;
       
  5204     SYSTEMTIME accessTime;
       
  5205     SYSTEMTIME modificationTime;
       
  5206     int modeBits = 0;
       
  5207     WIN32_FIND_DATAW findStructW;
  5125     unsigned INT ino;
  5208     unsigned INT ino;
       
  5209     wchar_t _aPathName[MAX_PATH+1];
  5126 
  5210 
  5127     if (__isString(aPathName)) {
  5211     if (__isString(aPathName)) {
  5128         HANDLE hFile;
  5212         int i;
  5129         FILETIME tempFileTime;
  5213         int l = __stringSize(aPathName);
  5130         SYSTEMTIME creationTime;
  5214         if (l > MAX_PATH) l = MAX_PATH;
  5131         SYSTEMTIME accessTime;
  5215 
  5132         SYSTEMTIME modificationTime;
  5216         for (i=0; i<l; i++) {
  5133         int modeBits = 0;
  5217             _aPathName[i] = __stringVal(aPathName)[i];
  5134         WIN32_FIND_DATA findStruct;
  5218         }
  5135 
  5219         _aPathName[i] = 0;
       
  5220     } else if (__isUnicode16String(aPathName)) {
       
  5221         int i;
       
  5222         int l = __unicode16StringSize(aPathName);
       
  5223         if (l > MAX_PATH) l = MAX_PATH;
       
  5224 
       
  5225         for (i=0; i<l; i++) {
       
  5226             _aPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5227         }
       
  5228         _aPathName[i] = 0;
       
  5229     } else
       
  5230         goto badArgument;
       
  5231         
  5136 #ifdef DO_WRAP_CALLS
  5232 #ifdef DO_WRAP_CALLS
  5137         {
  5233     {
  5138             char _aPathName[MAXPATHLEN];
  5234         do {
  5139 
  5235             __threadErrno = 0;
  5140             strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5236             hFile = STX_API_CALL2( "FindFirstFileW", FindFirstFileW, _aPathName, &findStructW);
  5141             do {
  5237         } while ((hFile < 0) && (__threadErrno == EINTR));
  5142                 __threadErrno = 0;
  5238     }
  5143                 hFile = STX_API_CALL2( "FindFirstFile", FindFirstFile, _aPathName, &findStruct);
  5239 #else
  5144             } while ((hFile < 0) && (__threadErrno == EINTR));
  5240     hFile = FindFirstFileW(_aPathName, &findStructW);
       
  5241     if (hFile < 0) {
       
  5242         __threadErrno = __WIN32_ERR(GetLastError());
       
  5243     }
       
  5244 #endif
       
  5245 
       
  5246     if (! hFile || (hFile == (HANDLE)(-1)) || (hFile == INVALID_HANDLE_VALUE)) {
       
  5247         @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
       
  5248     } else {
       
  5249         FindClose(hFile);
       
  5250 
       
  5251         id = __mkSmallInteger(0);   /* could get it by opening ... */
       
  5252         size = __MKLARGEINT64(1, findStructW.nFileSizeLow, findStructW.nFileSizeHigh);
       
  5253 
       
  5254         if (findStructW.cFileName[0] != '\0') {
       
  5255             bcopy(findStructW.cFileName, fileNameBuffer, MAX_PATH*sizeof(wchar_t));
       
  5256             fileNameBuffer[MAX_PATH] = '\0';
       
  5257             fileName = __MKU16STRING(fileNameBuffer);             /* FULL name */
  5145         }
  5258         }
  5146 #else
  5259 
  5147         hFile = FindFirstFile(__stringVal(aPathName), &findStruct);
  5260         if (findStructW.cAlternateFileName[0] != '\0') {
  5148         if (hFile < 0) {
  5261             bcopy(findStructW.cAlternateFileName, alternativeFileNameBuffer, 14*sizeof(wchar_t));
  5149             __threadErrno = __WIN32_ERR(GetLastError());
  5262             alternativeFileNameBuffer[14] = '\0';
       
  5263             alternativeName = __MKU16STRING(alternativeFileNameBuffer); /* DOS name */
  5150         }
  5264         }
  5151 #endif
  5265 
  5152         if (! hFile || (hFile == (HANDLE)(-1)) || (hFile == INVALID_HANDLE_VALUE)) {
  5266         /*
  5153             @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
  5267          * simulate access bits
       
  5268          */
       
  5269         if (findStructW.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
       
  5270             modeBits = 0444;
  5154         } else {
  5271         } else {
  5155             FindClose(hFile);
  5272             modeBits = 0666;
  5156 
       
  5157             id = __mkSmallInteger(0);   /* could get it by opening ... */
       
  5158             size = __MKLARGEINT64(1, findStruct.nFileSizeLow, findStruct.nFileSizeHigh);
       
  5159 
       
  5160             if (findStruct.cFileName[0] != '\0') {
       
  5161                 bcopy(findStruct.cFileName, fileNameBuffer, MAX_PATH);
       
  5162                 fileNameBuffer[MAX_PATH] = '\0';
       
  5163                 fileName = __MKSTRING(fileNameBuffer);             /* FULL name */
       
  5164             }
       
  5165 
       
  5166             if (findStruct.cAlternateFileName[0] != '\0') {
       
  5167                 bcopy(findStruct.cAlternateFileName, alternativeFileNameBuffer, 14);
       
  5168                 alternativeFileNameBuffer[14] = '\0';
       
  5169                 alternativeName = __MKSTRING(alternativeFileNameBuffer); /* DOS name */
       
  5170             }
       
  5171 
       
  5172             /*
       
  5173              * simulate access bits
       
  5174              */
       
  5175             if (findStruct.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
       
  5176                 modeBits = 0444;
       
  5177             } else {
       
  5178                 modeBits = 0666;
       
  5179             }
       
  5180 
       
  5181             if (findStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
       
  5182                 type = @symbol(directory);
       
  5183                 modeBits |= 0111;   /* executable */
       
  5184             } else {
       
  5185                 type = @symbol(regular);
       
  5186             }
       
  5187 
       
  5188             mode = __mkSmallInteger(modeBits);
       
  5189 
       
  5190             /*
       
  5191              * sigh - convert from stupid time to useful time
       
  5192              */
       
  5193             FileTimeToLocalFileTime(&findStruct.ftCreationTime, &tempFileTime);
       
  5194             FileTimeToSystemTime(&tempFileTime, &creationTime);
       
  5195             FileTimeToLocalFileTime(&findStruct.ftLastAccessTime, &tempFileTime);
       
  5196             FileTimeToSystemTime(&tempFileTime, &accessTime);
       
  5197             FileTimeToLocalFileTime(&findStruct.ftLastWriteTime, &tempFileTime);
       
  5198             FileTimeToSystemTime(&tempFileTime, &modificationTime);
       
  5199             aYr  = __mkSmallInteger(accessTime.wYear);
       
  5200             aMon = __mkSmallInteger(accessTime.wMonth);
       
  5201             aDay = __mkSmallInteger(accessTime.wDay);
       
  5202             aHr  = __mkSmallInteger(accessTime.wHour);
       
  5203             aMin = __mkSmallInteger(accessTime.wMinute);
       
  5204             aSec = __mkSmallInteger(accessTime.wSecond);
       
  5205             aMS  = __mkSmallInteger(accessTime.wMilliseconds);
       
  5206 
       
  5207             mYr  = __mkSmallInteger(modificationTime.wYear);
       
  5208             mMon = __mkSmallInteger(modificationTime.wMonth);
       
  5209             mDay = __mkSmallInteger(modificationTime.wDay);
       
  5210             mHr  = __mkSmallInteger(modificationTime.wHour);
       
  5211             mMin = __mkSmallInteger(modificationTime.wMinute);
       
  5212             mSec = __mkSmallInteger(modificationTime.wSecond);
       
  5213             mMS  = __mkSmallInteger(modificationTime.wMilliseconds);
       
  5214 
       
  5215             cYr  = __mkSmallInteger(creationTime.wYear);
       
  5216             cMon = __mkSmallInteger(creationTime.wMonth);
       
  5217             cDay = __mkSmallInteger(creationTime.wDay);
       
  5218             cHr  = __mkSmallInteger(creationTime.wHour);
       
  5219             cMin = __mkSmallInteger(creationTime.wMinute);
       
  5220             cSec = __mkSmallInteger(creationTime.wSecond);
       
  5221             cMS  = __mkSmallInteger(creationTime.wMilliseconds);
       
  5222         }
  5273         }
  5223     }
  5274 
       
  5275         if (findStructW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
       
  5276             type = @symbol(directory);
       
  5277             modeBits |= 0111;   /* executable */
       
  5278         } else {
       
  5279             type = @symbol(regular);
       
  5280         }
       
  5281 
       
  5282         mode = __mkSmallInteger(modeBits);
       
  5283 
       
  5284         /*
       
  5285          * sigh - convert from stupid time to useful time
       
  5286          */
       
  5287         FileTimeToLocalFileTime(&findStructW.ftCreationTime, &tempFileTime);
       
  5288         FileTimeToSystemTime(&tempFileTime, &creationTime);
       
  5289 
       
  5290         FileTimeToLocalFileTime(&findStructW.ftLastAccessTime, &tempFileTime);
       
  5291         FileTimeToSystemTime(&tempFileTime, &accessTime);
       
  5292 
       
  5293         FileTimeToLocalFileTime(&findStructW.ftLastWriteTime, &tempFileTime);
       
  5294         FileTimeToSystemTime(&tempFileTime, &modificationTime);
       
  5295 
       
  5296         aYr  = __mkSmallInteger(accessTime.wYear);
       
  5297         aMon = __mkSmallInteger(accessTime.wMonth);
       
  5298         aDay = __mkSmallInteger(accessTime.wDay);
       
  5299         aHr  = __mkSmallInteger(accessTime.wHour);
       
  5300         aMin = __mkSmallInteger(accessTime.wMinute);
       
  5301         aSec = __mkSmallInteger(accessTime.wSecond);
       
  5302         aMS  = __mkSmallInteger(accessTime.wMilliseconds);
       
  5303 
       
  5304         mYr  = __mkSmallInteger(modificationTime.wYear);
       
  5305         mMon = __mkSmallInteger(modificationTime.wMonth);
       
  5306         mDay = __mkSmallInteger(modificationTime.wDay);
       
  5307         mHr  = __mkSmallInteger(modificationTime.wHour);
       
  5308         mMin = __mkSmallInteger(modificationTime.wMinute);
       
  5309         mSec = __mkSmallInteger(modificationTime.wSecond);
       
  5310         mMS  = __mkSmallInteger(modificationTime.wMilliseconds);
       
  5311 
       
  5312         cYr  = __mkSmallInteger(creationTime.wYear);
       
  5313         cMon = __mkSmallInteger(creationTime.wMonth);
       
  5314         cDay = __mkSmallInteger(creationTime.wDay);
       
  5315         cHr  = __mkSmallInteger(creationTime.wHour);
       
  5316         cMin = __mkSmallInteger(creationTime.wMinute);
       
  5317         cSec = __mkSmallInteger(creationTime.wSecond);
       
  5318         cMS  = __mkSmallInteger(creationTime.wMilliseconds);
       
  5319     }
       
  5320 
       
  5321   badArgument: ;
  5224 %}.
  5322 %}.
  5225     (aPathName endsWith:'.lnk') ifTrue:[
  5323     (aPathName endsWith:'.lnk') ifTrue:[
  5226         type := #symbolicLink.
  5324         type := #symbolicLink.
  5227         "/ now done lazyly in FileStatusInfo, when the path is accessed
  5325         "/ now done lazyly in FileStatusInfo, when the path is accessed
  5228         "/ path := self getLinkTarget:aPathName.
  5326         "/ path := self getLinkTarget:aPathName.
  5229     ].
  5327     ].
  5230 
  5328 
  5231     mode isNil ifTrue:[
  5329     mode isNil ifTrue:[
  5232         (self isDirectory:aPathName) ifTrue:[
  5330         (self isDirectory:aPathName) ifTrue:[
  5233             "/ the code above fails for root directories (these do not exist).
  5331             "/ the code above fails for root directories (these do not exist).
  5234             "/ simulate
  5332             "/ simulate here
  5235             mode := 8r777.
  5333             mode := 8r777.
  5236             type := #directory.
  5334             type := #directory.
  5237             uid := gid := 0.
  5335             uid := gid := 0.
  5238             size := 0.
  5336             size := 0.
  5239             id := 0.
  5337             id := 0.
  5248             mtime := Timestamp day:mDay month:mMon year:mYr hour:mHr minutes:mMin seconds:mSec milliseconds:mMS.
  5346             mtime := Timestamp day:mDay month:mMon year:mYr hour:mHr minutes:mMin seconds:mSec milliseconds:mMS.
  5249         ].
  5347         ].
  5250         ctime isNil ifTrue:[
  5348         ctime isNil ifTrue:[
  5251             ctime := Timestamp day:cDay month:cMon year:cYr hour:cHr minutes:cMin seconds:cSec milliseconds:cMS.
  5349             ctime := Timestamp day:cDay month:cMon year:cYr hour:cHr minutes:cMin seconds:cSec milliseconds:cMS.
  5252         ].
  5350         ].
  5253 
  5351         fileName notNil ifTrue:[
       
  5352             fileName := fileName asSingleByteStringIfPossible
       
  5353         ].
       
  5354         alternativeName notNil ifTrue:[
       
  5355             alternativeName := alternativeName asSingleByteStringIfPossible
       
  5356         ].
  5254         info := FileStatusInfo
  5357         info := FileStatusInfo
  5255                     type:type
  5358                     type:type
  5256                     mode:mode
  5359                     mode:mode
  5257                     uid:uid
  5360                     uid:uid
  5258                     gid:gid
  5361                     gid:gid
  5275     (OperatingSystem linkInfoOf:'/') accessed
  5378     (OperatingSystem linkInfoOf:'/') accessed
  5276      OperatingSystem linkInfoOf:'C:\Dokumente und Einstellungen\cg\Favoriten\Incoming.lnk'
  5379      OperatingSystem linkInfoOf:'C:\Dokumente und Einstellungen\cg\Favoriten\Incoming.lnk'
  5277    "
  5380    "
  5278 
  5381 
  5279     "Modified: / 07-02-2007 / 10:30:14 / cg"
  5382     "Modified: / 07-02-2007 / 10:30:14 / cg"
       
  5383 
       
  5384 
       
  5385 
       
  5386 
       
  5387 
       
  5388 
       
  5389 
       
  5390 
       
  5391 
       
  5392 
       
  5393 
       
  5394 
       
  5395 
       
  5396 
       
  5397 
       
  5398 
       
  5399 
       
  5400 
       
  5401 
       
  5402 
       
  5403 
  5280 !
  5404 !
  5281 
  5405 
  5282 mimeTypeForSuffix:aFileSuffix
  5406 mimeTypeForSuffix:aFileSuffix
  5283     "given a file suffix, return a corresponding mimeType.
  5407     "given a file suffix, return a corresponding mimeType.
  5284      Here, the Registry is consulted.
  5408      Here, the Registry is consulted.
  5354 primGetCurrentDirectory: size string: string
  5478 primGetCurrentDirectory: size string: string
  5355     <apicall: ulong "GetCurrentDirectoryA" ( ulong pointer ) module: "kernel32.dll" >
  5479     <apicall: ulong "GetCurrentDirectoryA" ( ulong pointer ) module: "kernel32.dll" >
  5356     self primitiveFailed.
  5480     self primitiveFailed.
  5357 
  5481 
  5358     "
  5482     "
  5359     |s size|
  5483      |s size|
  5360     s := String new:200.
  5484      s := String new:200.
  5361     size := self primGetCurrentDirectory:200 string: s.
  5485      size := self primGetCurrentDirectory:200 string: s.
  5362     s copyFrom:1 to: size
  5486      s copyFrom:1 to: size
       
  5487     "
       
  5488 !
       
  5489 
       
  5490 primGetCurrentDirectoryW: size string: string
       
  5491     <apicall: ulong "GetCurrentDirectoryW" ( ulong pointer ) module: "kernel32.dll" >
       
  5492     self primitiveFailed.
       
  5493 
       
  5494     "
       
  5495      |s size|
       
  5496      s := Unicode16String new:200.
       
  5497      size := self primGetCurrentDirectoryW:200 string: s.
       
  5498      s copyFrom:1 to: size
  5363     "
  5499     "
  5364 !
  5500 !
  5365 
  5501 
  5366 primIdOf:aPathName
  5502 primIdOf:aPathName
  5367     "the actual code to return the fileNumber (i.e. inode number) of a file."
  5503     "the actual code to return the fileNumber (i.e. inode number) of a file."
  5376      realPath library function.
  5512      realPath library function.
  5377      Notice: if symbolic links are involved, the result may look different
  5513      Notice: if symbolic links are involved, the result may look different
  5378      from what you expect."
  5514      from what you expect."
  5379 
  5515 
  5380 %{  /* xxSTACK: 16000 */
  5516 %{  /* xxSTACK: 16000 */
  5381 
  5517 #define NO_NT4_0_COMPATIBILITY
  5382     if (__isStringLike(aPathName)) {
  5518     if (__isStringLike(aPathName)) {
  5383 	char nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1];
  5519         char nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1];
  5384 	char *pFinal;
  5520         char *pFinal;
  5385 	int rslt;
  5521         int rslt;
  5386 
  5522 
  5387 #ifdef DO_WRAP_CALLS
  5523 #ifdef DO_WRAP_CALLS
  5388 	char _aPathName[MAXPATHLEN];
  5524         char _aPathName[MAXPATHLEN];
  5389 
  5525 
  5390 	strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5526         strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
  5391 	do {
  5527         do {
  5392 	    __threadErrno = 0;
  5528             __threadErrno = 0;
  5393 	    rslt = STX_API_CALL4( "GetFullPathName", GetFullPathName, _aPathName, sizeof(nameBuffer), nameBuffer, &pFinal);
  5529             rslt = STX_API_CALL4( "GetFullPathName", GetFullPathName, _aPathName, sizeof(nameBuffer), nameBuffer, &pFinal);
  5394 	} while ((rslt < 0) && (__threadErrno == EINTR));
  5530         } while ((rslt < 0) && (__threadErrno == EINTR));
  5395 #else
  5531 #else
  5396 	rslt = GetFullPathName(__stringVal(aPathName), sizeof(nameBuffer), nameBuffer, &pFinal);
  5532         rslt = GetFullPathName(__stringVal(aPathName), sizeof(nameBuffer), nameBuffer, &pFinal);
  5397 #endif
  5533 #endif
  5398 
  5534 
  5399 	if (rslt > 0) {
  5535         if (rslt > 0) {
  5400 	    /*
  5536             /*
  5401 	     * Attention: GetLongPathName is not available on old NT4.0/W95/W98
  5537              * Attention: GetLongPathName is not available on old NT4.0/W95/W98
  5402 	     */
  5538              */
  5403 	    static FARPROC GetLongPathName_entry = NULL;
  5539             static FARPROC GetLongPathName_entry = NULL;
  5404 #ifdef NO_NT4_0_COMPATIBILITY
  5540 #ifdef NO_NT4_0_COMPATIBILITY
  5405 	    GetLongPathName_entry = (FARPROC) GetLongPathName;
  5541             GetLongPathName_entry = (FARPROC) GetLongPathName;
  5406 #else
  5542 #else
  5407 	    if (GetLongPathName_entry == NULL) {
  5543             if (GetLongPathName_entry == NULL) {
  5408 		GetLongPathName_entry = __get_kernel32_functionAddress("GetLongPathNameA");
  5544                 GetLongPathName_entry = __get_kernel32_functionAddress("GetLongPathNameA");
  5409 	    }
  5545             }
  5410 #endif /* NO_NT4_0_COMPATIBILITY */
  5546 #endif /* NO_NT4_0_COMPATIBILITY */
  5411 
  5547 
  5412 	    if (GetLongPathName_entry) {
  5548             if (GetLongPathName_entry) {
  5413 #ifdef DO_WRAP_CALLS
  5549 #ifdef DO_WRAP_CALLS
  5414 		do {
  5550                 do {
  5415 		    __threadErrno = 0;
  5551                     __threadErrno = 0;
  5416 		    rslt = STX_API_CALL3( "GetLongPathName", GetLongPathName_entry, nameBuffer, nameBuffer, sizeof(nameBuffer));
  5552                     rslt = STX_API_CALL3( "GetLongPathName", GetLongPathName_entry, nameBuffer, nameBuffer, sizeof(nameBuffer));
  5417 		} while ((rslt < 0) && (__threadErrno == EINTR));
  5553                 } while ((rslt < 0) && (__threadErrno == EINTR));
  5418 #else
  5554 #else
  5419 		rslt = (*GetLongPathName_entry)(nameBuffer, nameBuffer, sizeof(nameBuffer));
  5555                 rslt = (*GetLongPathName_entry)(nameBuffer, nameBuffer, sizeof(nameBuffer));
  5420 #endif
  5556 #endif
  5421 	    }
  5557             }
  5422 	}
  5558         }
  5423 	if (rslt > 0) {
  5559         if (rslt > 0) {
  5424 	    RETURN ( __MKSTRING(nameBuffer) );
  5560             RETURN ( __MKSTRING(nameBuffer) );
  5425 	}
  5561         }
  5426 	__threadErrno = __WIN32_ERR(GetLastError());
  5562         __threadErrno = __WIN32_ERR(GetLastError());
       
  5563         RETURN (nil);
       
  5564     }
       
  5565     if (__isUnicode16String(aPathName)) {
       
  5566         wchar_t nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1];
       
  5567         char *pFinal;
       
  5568         int rslt;
       
  5569         wchar_t _aPathName[MAXPATHLEN+1];
       
  5570         int i, l;
       
  5571 
       
  5572         l = __unicode16StringSize(aPathName);
       
  5573         if (l > MAXPATHLEN) l = MAXPATHLEN;
       
  5574         for (i=0; i<l; i++) {
       
  5575             _aPathName[i] = __unicode16StringVal(aPathName)[i];
       
  5576         }
       
  5577         _aPathName[i] = 0;
       
  5578 
       
  5579 #ifdef DO_WRAP_CALLS
       
  5580         do {
       
  5581             __threadErrno = 0;
       
  5582             rslt = STX_API_CALL4( "GetFullPathNameW", GetFullPathNameW, _aPathName, MAXPATHLEN, nameBuffer, &pFinal);
       
  5583         } while ((rslt < 0) && (__threadErrno == EINTR));
       
  5584 #else
       
  5585         rslt = GetFullPathName(_aPathName, MAXPATHLEN, nameBuffer, &pFinal);
       
  5586 #endif
       
  5587         if (rslt > 0) {
       
  5588             /*
       
  5589              * Attention: GetLongPathName is not available on old NT4.0/W95/W98
       
  5590              */
       
  5591             static FARPROC GetLongPathNameW_entry = NULL;
       
  5592 #ifdef NO_NT4_0_COMPATIBILITY
       
  5593             GetLongPathNameW_entry = (FARPROC) GetLongPathNameW;
       
  5594 #else
       
  5595             if (GetLongPathNameW_entry == NULL) {
       
  5596                 GetLongPathNameW_entry = __get_kernel32_functionAddress("GetLongPathNameW");
       
  5597             }
       
  5598 #endif /* NO_NT4_0_COMPATIBILITY */
       
  5599 
       
  5600             if (GetLongPathNameW_entry) {
       
  5601 #ifdef DO_WRAP_CALLS
       
  5602                 do {
       
  5603                     __threadErrno = 0;
       
  5604                     rslt = STX_API_CALL3( "GetLongPathNameW", GetLongPathNameW_entry, nameBuffer, nameBuffer, MAXPATHLEN);
       
  5605                 } while ((rslt < 0) && (__threadErrno == EINTR));
       
  5606 #else
       
  5607                 rslt = (*GetLongPathNameW_entry)(nameBuffer, nameBuffer, MAXPATHLEN);
       
  5608 #endif
       
  5609             }
       
  5610         }
       
  5611         if (rslt > 0) {
       
  5612             RETURN ( __MKU16STRING(nameBuffer) );
       
  5613         }
       
  5614         __threadErrno = __WIN32_ERR(GetLastError());
  5427     }
  5615     }
  5428 %}.
  5616 %}.
  5429     ^ nil
  5617     ^ nil
  5430 "
  5618 
  5431 self primPathNameOf:'.'
  5619     "
  5432 "
  5620      self primPathNameOf:'.' 
       
  5621      self primPathNameOf:'.' asUnicode16String
       
  5622     "
  5433 !
  5623 !
  5434 
  5624 
  5435 primSetCurrentDirectory:pathName
  5625 primSetCurrentDirectory:pathName
  5436     <apicall: bool "SetCurrentDirectoryA" ( pointer ) module: "kernel32.dll" >
  5626     <apicall: bool "SetCurrentDirectoryA" ( pointer ) module: "kernel32.dll" >
  5437     self primitiveFailed.
  5627     self primitiveFailed.
 15644 ! !
 15834 ! !
 15645 
 15835 
 15646 !Win32OperatingSystem class methodsFor:'documentation'!
 15836 !Win32OperatingSystem class methodsFor:'documentation'!
 15647 
 15837 
 15648 version
 15838 version
 15649     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.351 2008-10-21 14:08:10 ca Exp $'
 15839     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.352 2008-10-30 15:30:33 cg Exp $'
 15650 ! !
 15840 ! !
 15651 
 15841 
 15652 Win32OperatingSystem initialize!
 15842 Win32OperatingSystem initialize!
 15653 Win32OperatingSystem::PerformanceData initialize!
 15843 Win32OperatingSystem::PerformanceData initialize!
 15654 Win32OperatingSystem::RegistryEntry initialize!
 15844 Win32OperatingSystem::RegistryEntry initialize!