UnixOperatingSystem.st
branchjv
changeset 18117 eb433f2c42b2
parent 18115 26ac4840e5d0
parent 15906 8bbbcd3b5765
child 18120 e3a375d5f6a8
equal deleted inserted replaced
18116:bf7f37b63ea2 18117:eb433f2c42b2
   219 #  endif
   219 #  endif
   220 # endif /* aix */
   220 # endif /* aix */
   221 
   221 
   222 # ifdef __osx__
   222 # ifdef __osx__
   223 #  include <time.h>
   223 #  include <time.h>
       
   224 #  define HAS_TIMEGM
   224 
   225 
   225 struct tm {
   226 struct tm {
   226         int     tm_sec;         /* seconds after the minute [0-60] */
   227 	int     tm_sec;         /* seconds after the minute [0-60] */
   227         int     tm_min;         /* minutes after the hour [0-59] */
   228 	int     tm_min;         /* minutes after the hour [0-59] */
   228         int     tm_hour;        /* hours since midnight [0-23] */
   229 	int     tm_hour;        /* hours since midnight [0-23] */
   229         int     tm_mday;        /* day of the month [1-31] */
   230 	int     tm_mday;        /* day of the month [1-31] */
   230         int     tm_mon;         /* months since January [0-11] */
   231 	int     tm_mon;         /* months since January [0-11] */
   231         int     tm_year;        /* years since 1900 */
   232 	int     tm_year;        /* years since 1900 */
   232         int     tm_wday;        /* days since Sunday [0-6] */
   233 	int     tm_wday;        /* days since Sunday [0-6] */
   233         int     tm_yday;        /* days since January 1 [0-365] */
   234 	int     tm_yday;        /* days since January 1 [0-365] */
   234         int     tm_isdst;       /* Daylight Savings Time flag */
   235 	int     tm_isdst;       /* Daylight Savings Time flag */
   235         long    tm_gmtoff;      /* offset from CUT in seconds */
   236 	long    tm_gmtoff;      /* offset from CUT in seconds */
   236         char    *tm_zone;       /* timezone abbreviation */
   237 	char    *tm_zone;       /* timezone abbreviation */
   237 };
   238 };
   238 
   239 
   239 #  include <crt_externs.h>
   240 #  include <crt_externs.h>
   240 
   241 
   241 # endif /* __osx__ */
   242 # endif /* __osx__ */
   671 
   672 
   672 initializeCodeset
   673 initializeCodeset
   673     "initialize the codeset, we are running under.
   674     "initialize the codeset, we are running under.
   674      The codeset is determined from the environment.
   675      The codeset is determined from the environment.
   675      The LC_CTYPE locale is set from the environment as a side effect."
   676      The LC_CTYPE locale is set from the environment as a side effect."
   676     
   677 
   677     |codeset|
   678     |codeset|
   678     
   679 
   679 %{
   680 %{
   680 #include <langinfo.h>
   681 #include <langinfo.h>
   681     char *__codeset;
   682     char *__codeset;
   682 
   683 
   683     setlocale(LC_CTYPE, "");
   684     setlocale(LC_CTYPE, "");
   684     __codeset = nl_langinfo(CODESET);
   685     __codeset = nl_langinfo(CODESET);
   685     if (strlen(__codeset) > 0) {
   686     if (strlen(__codeset) > 0) {
   686         codeset = __MKSTRING(__codeset);
   687 	codeset = __MKSTRING(__codeset);
   687     }
   688     }
   688 %}.
   689 %}.
   689     codeset notNil ifTrue:[
   690     codeset notNil ifTrue:[
   690         codeset := codeset asLowercase.
   691 	codeset := codeset asLowercase.
   691         codeset = 'utf-8' ifTrue:[
   692 	codeset = 'utf-8' ifTrue:[
   692             codeset := #utf8.
   693 	    codeset := #utf8.
   693         ] ifFalse:[
   694 	] ifFalse:[
   694             codeset := codeset asSymbol.
   695 	    codeset := codeset asSymbol.
   695         ].
   696 	].
   696     ].
   697     ].
   697     Codeset := codeset.
   698     Codeset := codeset.
   698     ^ codeset.
   699     ^ codeset.
   699 
   700 
   700     "
   701     "
   704 
   705 
   705 update:something with:aParameter from:changedObject
   706 update:something with:aParameter from:changedObject
   706     "catch image restart and flush some cached data"
   707     "catch image restart and flush some cached data"
   707 
   708 
   708     something == #earlyRestart ifTrue:[
   709     something == #earlyRestart ifTrue:[
   709         self initializeCachedData
   710 	self initializeCachedData
   710     ]
   711     ]
   711 
   712 
   712     "Created: / 15.6.1996 / 15:22:37 / cg"
   713     "Created: / 15.6.1996 / 15:22:37 / cg"
   713     "Modified: / 7.1.1997 / 19:36:11 / stefan"
   714     "Modified: / 7.1.1997 / 19:36:11 / stefan"
   714     "Modified: / 11.12.1998 / 16:22:48 / cg"
   715     "Modified: / 11.12.1998 / 16:22:48 / cg"
  3711     struct stat buf;
  3712     struct stat buf;
  3712     int ret;
  3713     int ret;
  3713 
  3714 
  3714     if (__isSmallInteger(aFileDescriptor)) {
  3715     if (__isSmallInteger(aFileDescriptor)) {
  3715 # ifdef TRACE_STAT_CALLS
  3716 # ifdef TRACE_STAT_CALLS
  3716         printf("fstat on '%d' for accessMode\n", __smallIntegerVal(aFileDescriptor));
  3717 	printf("fstat on '%d' for accessMode\n", __smallIntegerVal(aFileDescriptor));
  3717 # endif
  3718 # endif
  3718         __BEGIN_INTERRUPTABLE__
  3719 	__BEGIN_INTERRUPTABLE__
  3719         do {
  3720 	do {
  3720             ret = fstat(__smallIntegerVal(aFileDescriptor), &buf);
  3721 	    ret = fstat(__smallIntegerVal(aFileDescriptor), &buf);
  3721         } while ((ret < 0) && (errno == EINTR));
  3722 	} while ((ret < 0) && (errno == EINTR));
  3722         __END_INTERRUPTABLE__
  3723 	__END_INTERRUPTABLE__
  3723 
  3724 
  3724         if (ret < 0) {
  3725 	if (ret < 0) {
  3725             @global(LastErrorNumber) = __mkSmallInteger(errno);
  3726 	    @global(LastErrorNumber) = __mkSmallInteger(errno);
  3726             RETURN ( nil );
  3727 	    RETURN ( nil );
  3727         }
  3728 	}
  3728         RETURN ( __mkSmallInteger(buf.st_mode & 0777) );
  3729 	RETURN ( __mkSmallInteger(buf.st_mode & 0777) );
  3729     }
  3730     }
  3730 %}.
  3731 %}.
  3731    ^ self primitiveFailed
  3732    ^ self primitiveFailed
  3732 
  3733 
  3733    "
  3734    "
  3734     '/' asFilename readingFileDo:[:s|
  3735     '/' asFilename readingFileDo:[:s|
  3735         (OperatingSystem accessModeOfFd:s fileDescriptor) printStringRadix:8
  3736 	(OperatingSystem accessModeOfFd:s fileDescriptor) printStringRadix:8
  3736     ].
  3737     ].
  3737    "
  3738    "
  3738 !
  3739 !
  3739 
  3740 
  3740 changeAccessModeOf:aPathName to:modeBits
  3741 changeAccessModeOf:aPathName to:modeBits
  3774 
  3775 
  3775 %{
  3776 %{
  3776     int ret;
  3777     int ret;
  3777 
  3778 
  3778     if (__isSmallInteger(aFileDescriptor) && __isSmallInteger(modeBits)) {
  3779     if (__isSmallInteger(aFileDescriptor) && __isSmallInteger(modeBits)) {
  3779         __BEGIN_INTERRUPTABLE__
  3780 	__BEGIN_INTERRUPTABLE__
  3780         do {
  3781 	do {
  3781             ret = fchmod(__smallIntegerVal(aFileDescriptor), __intVal(modeBits));
  3782 	    ret = fchmod(__smallIntegerVal(aFileDescriptor), __intVal(modeBits));
  3782         } while (ret < 0 && errno == EINTR);
  3783 	} while (ret < 0 && errno == EINTR);
  3783         __END_INTERRUPTABLE__
  3784 	__END_INTERRUPTABLE__
  3784         if (ret < 0) {
  3785 	if (ret < 0) {
  3785             @global(LastErrorNumber) = __mkSmallInteger(errno);
  3786 	    @global(LastErrorNumber) = __mkSmallInteger(errno);
  3786             RETURN ( false );
  3787 	    RETURN ( false );
  3787         }
  3788 	}
  3788         RETURN ( true );
  3789 	RETURN ( true );
  3789     }
  3790     }
  3790 %}.
  3791 %}.
  3791     ^ self primitiveFailed
  3792     ^ self primitiveFailed
  3792 ! !
  3793 ! !
  3793 
  3794 
  6711 
  6712 
  6712     "Created: 23.12.1995 / 14:19:20 / cg"
  6713     "Created: 23.12.1995 / 14:19:20 / cg"
  6713 !
  6714 !
  6714 
  6715 
  6715 getNetworkAddressInfo
  6716 getNetworkAddressInfo
  6716     "return a Dictionary of network interface information. 
  6717     "return a Dictionary of network interface information.
  6717         key -> name of interface
  6718 	key -> name of interface
  6718         value -> a Set of network address 
  6719 	value -> a Set of network address
  6719                 information for the interface - a dictionaries containing the 
  6720 		information for the interface - a dictionaries containing the
  6720                 information about the configuration of each interface in the system. 
  6721 		information about the configuration of each interface in the system.
  6721                 The dictionary keys are:
  6722 		The dictionary keys are:
  6722                     #address
  6723 		    #address
  6723                     #netmask
  6724 		    #netmask
  6724                     #flags
  6725 		    #flags
  6725                     #destAddress"
  6726 		    #destAddress"
  6726 
  6727 
  6727     |returnArray addressArray nameArray noOfIf retDictionary error retIndex|
  6728     |returnArray addressArray nameArray noOfIf retDictionary error retIndex|
  6728 
  6729 
  6729     noOfIf := 0.
  6730     noOfIf := 0.
  6730 
  6731 
  6740     int n_ifa = 0;
  6741     int n_ifa = 0;
  6741     int retI = 0;
  6742     int retI = 0;
  6742     OBJ t;
  6743     OBJ t;
  6743 
  6744 
  6744     if (getifaddrs(&ifap) < 0) {
  6745     if (getifaddrs(&ifap) < 0) {
  6745         error = __MKSTRING("getifaddrs() failed");
  6746 	error = __MKSTRING("getifaddrs() failed");
  6746         goto out;
  6747 	goto out;
  6747     }
  6748     }
  6748 
  6749 
  6749     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) n_ifa++;
  6750     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) n_ifa++;
  6750 
  6751 
  6751     returnArray = __ARRAY_NEW_INT(n_ifa*5);
  6752     returnArray = __ARRAY_NEW_INT(n_ifa*5);
  6752 
  6753 
  6753     if (returnArray == nil) {
  6754     if (returnArray == nil) {
  6754         /* Creating a string wouldn't work here */
  6755 	/* Creating a string wouldn't work here */
  6755         error = @symbol(allocationFailure);
  6756 	error = @symbol(allocationFailure);
  6756         goto bad;
  6757 	goto bad;
  6757     }
  6758     }
  6758 
  6759 
  6759     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) {
  6760     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) {
  6760         int family, len;
  6761 	int family, len;
  6761 
  6762 
  6762         if (ifaLoop->ifa_addr == 0)
  6763 	if (ifaLoop->ifa_addr == 0)
  6763                continue;
  6764 	       continue;
  6764         family = ifaLoop->ifa_addr->sa_family;
  6765 	family = ifaLoop->ifa_addr->sa_family;
  6765         switch (family) {
  6766 	switch (family) {
  6766         case AF_INET:
  6767 	case AF_INET:
  6767             len = sizeof(struct sockaddr_in);
  6768 	    len = sizeof(struct sockaddr_in);
  6768             break;
  6769 	    break;
  6769         case AF_INET6:
  6770 	case AF_INET6:
  6770             len = sizeof(struct sockaddr_in6);
  6771 	    len = sizeof(struct sockaddr_in6);
  6771             break;
  6772 	    break;
  6772 #if 0
  6773 #if 0
  6773         case AF_PACKET:
  6774 	case AF_PACKET:
  6774             len = sizeof(sockaddr_ll);
  6775 	    len = sizeof(sockaddr_ll);
  6775             break;
  6776 	    break;
  6776 #endif
  6777 #endif
  6777         default:
  6778 	default:
  6778             /* skip */
  6779 	    /* skip */
  6779             continue;
  6780 	    continue;
  6780         };
  6781 	};
  6781         t = __MKSTRING(ifaLoop->ifa_name);
  6782 	t = __MKSTRING(ifaLoop->ifa_name);
  6782         __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6783 	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6783         t = __MKUINT(ifaLoop->ifa_flags);
  6784 	t = __MKUINT(ifaLoop->ifa_flags);
  6784         __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6785 	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6785         t = __MKBYTEARRAY((char *)ifaLoop->ifa_addr, len);
  6786 	t = __MKBYTEARRAY((char *)ifaLoop->ifa_addr, len);
  6786         __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6787 	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
  6787         if (ifaLoop->ifa_netmask != 0) {
  6788 	if (ifaLoop->ifa_netmask != 0) {
  6788             t = __MKBYTEARRAY((char *)ifaLoop->ifa_netmask, len);
  6789 	    t = __MKBYTEARRAY((char *)ifaLoop->ifa_netmask, len);
  6789             __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
  6790 	    __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
  6790         }
  6791 	}
  6791         retI++;
  6792 	retI++;
  6792         if (ifaLoop->ifa_dstaddr != 0) {
  6793 	if (ifaLoop->ifa_dstaddr != 0) {
  6793             t = __MKBYTEARRAY((char *)ifaLoop->ifa_dstaddr, len);
  6794 	    t = __MKBYTEARRAY((char *)ifaLoop->ifa_dstaddr, len);
  6794             __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
  6795 	    __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
  6795         }
  6796 	}
  6796         retI++;
  6797 	retI++;
  6797     }
  6798     }
  6798 
  6799 
  6799     noOfIf = __mkSmallInteger(n_ifa);
  6800     noOfIf = __mkSmallInteger(n_ifa);
  6800 
  6801 
  6801 bad:
  6802 bad:
  6816     ** Open an INET socket
  6817     ** Open an INET socket
  6817     */
  6818     */
  6818 
  6819 
  6819     afinet_socket = socket(AF_INET, SOCK_DGRAM, 0);
  6820     afinet_socket = socket(AF_INET, SOCK_DGRAM, 0);
  6820     if (afinet_socket < 0) {
  6821     if (afinet_socket < 0) {
  6821         goto bad;
  6822 	goto bad;
  6822     }
  6823     }
  6823 
  6824 
  6824     /*
  6825     /*
  6825     ** Get the list of network interfaces
  6826     ** Get the list of network interfaces
  6826     */
  6827     */
  6827 
  6828 
  6828     ifc.ifc_len = sizeof (buf);
  6829     ifc.ifc_len = sizeof (buf);
  6829     ifc.ifc_buf = (caddr_t) buf;
  6830     ifc.ifc_buf = (caddr_t) buf;
  6830 
  6831 
  6831     if (ioctl (afinet_socket, SIOCGIFCONF, (caddr_t) &ifc) < 0) {
  6832     if (ioctl (afinet_socket, SIOCGIFCONF, (caddr_t) &ifc) < 0) {
  6832         close(afinet_socket);
  6833 	close(afinet_socket);
  6833         error = __MKSTRING("ioctl(SIOCGIFCONF) failed");
  6834 	error = __MKSTRING("ioctl(SIOCGIFCONF) failed");
  6834         goto bad;
  6835 	goto bad;
  6835     }
  6836     }
  6836 
  6837 
  6837     n_ifs = ifc.ifc_len / sizeof (struct ifreq);
  6838     n_ifs = ifc.ifc_len / sizeof (struct ifreq);
  6838 
  6839 
  6839     nameArray    = __ARRAY_NEW_INT(n_ifs);
  6840     nameArray    = __ARRAY_NEW_INT(n_ifs);
  6840     addressArray = __ARRAY_NEW_INT(n_ifs);
  6841     addressArray = __ARRAY_NEW_INT(n_ifs);
  6841 
  6842 
  6842     if (nameArray == nil || addressArray == nil) {
  6843     if (nameArray == nil || addressArray == nil) {
  6843         /* Creating a string wouldn/t work here */
  6844 	/* Creating a string wouldn/t work here */
  6844         error = @symbol(allocationFailure);
  6845 	error = @symbol(allocationFailure);
  6845         goto bad;
  6846 	goto bad;
  6846     }
  6847     }
  6847 
  6848 
  6848     /*
  6849     /*
  6849     ** Iterate of the list of the system's netif. Find all
  6850     ** Iterate of the list of the system's netif. Find all
  6850     ** active interfaces and their ethernet addresses
  6851     ** active interfaces and their ethernet addresses
  6851     */
  6852     */
  6852     countOfIf = 0;
  6853     countOfIf = 0;
  6853 
  6854 
  6854     for (i=0, ifr = ifc.ifc_req; i < n_ifs; i++, ifr++) {
  6855     for (i=0, ifr = ifc.ifc_req; i < n_ifs; i++, ifr++) {
  6855         /*
  6856 	/*
  6856         ** Get address for this interface
  6857 	** Get address for this interface
  6857         */
  6858 	*/
  6858         memset (&ifreq, 0, sizeof(ifreq));
  6859 	memset (&ifreq, 0, sizeof(ifreq));
  6859         memcpy (ifreq.ifr_name, ifr->ifr_name, sizeof(ifr->ifr_name));
  6860 	memcpy (ifreq.ifr_name, ifr->ifr_name, sizeof(ifr->ifr_name));
  6860         if (ioctl (afinet_socket, SIOCGIFADDR, &ifreq) >= 0) {
  6861 	if (ioctl (afinet_socket, SIOCGIFADDR, &ifreq) >= 0) {
  6861             t = __MKBYTEARRAY((char *)&ifreq.ifr_addr, sizeof(ifreq.ifr_addr));
  6862 	    t = __MKBYTEARRAY((char *)&ifreq.ifr_addr, sizeof(ifreq.ifr_addr));
  6862             __arrayVal(addressArray)[countOfIf] = t; __STORE(addressArray, t);
  6863 	    __arrayVal(addressArray)[countOfIf] = t; __STORE(addressArray, t);
  6863             t = __MKSTRING(&ifreq.ifr_name);
  6864 	    t = __MKSTRING(&ifreq.ifr_name);
  6864             __arrayVal(nameArray)[countOfIf] = t; __STORE(nameArray, t);
  6865 	    __arrayVal(nameArray)[countOfIf] = t; __STORE(nameArray, t);
  6865             countOfIf++;
  6866 	    countOfIf++;
  6866         } else {
  6867 	} else {
  6867             fprintf(stderr, "SIOCGIFADDR failed: %s\n", errno);
  6868 	    fprintf(stderr, "SIOCGIFADDR failed: %s\n", errno);
  6868         }
  6869 	}
  6869         error = __MKSTRING("ioctl(SIOCGIFCONF) failed");
  6870 	error = __MKSTRING("ioctl(SIOCGIFCONF) failed");
  6870     }
  6871     }
  6871 
  6872 
  6872     noOfIf = __mkSmallInteger(countOfIf);
  6873     noOfIf = __mkSmallInteger(countOfIf);
  6873 bad:
  6874 bad:
  6874     if (afinet_socket >= 0)
  6875     if (afinet_socket >= 0)
  6875         close(afinet_socket);
  6876 	close(afinet_socket);
  6876 #else
  6877 #else
  6877     error = @symbol(notSupported);
  6878     error = @symbol(notSupported);
  6878 #endif /* defined(SIOCGIFADDR) */
  6879 #endif /* defined(SIOCGIFADDR) */
  6879 out:;
  6880 out:;
  6880 %}.
  6881 %}.
  6881 
  6882 
  6882     retDictionary := Dictionary new:noOfIf.
  6883     retDictionary := Dictionary new:noOfIf.
  6883     error notNil ifTrue:[
  6884     error notNil ifTrue:[
  6884         self primitiveFailed:error.
  6885 	self primitiveFailed:error.
  6885         "return empty dictionary if proceeding from error"
  6886 	"return empty dictionary if proceeding from error"
  6886         ^  retDictionary.
  6887 	^  retDictionary.
  6887     ].
  6888     ].
  6888 
  6889 
  6889     retIndex := 1.
  6890     retIndex := 1.
  6890 
  6891 
  6891     1 to:noOfIf do:[:cnt|
  6892     1 to:noOfIf do:[:cnt|
  6892         |name addressBytes set dict|
  6893 	|name addressBytes set dict|
  6893 
  6894 
  6894         name := returnArray at:retIndex.
  6895 	name := returnArray at:retIndex.
  6895         addressBytes := returnArray at:retIndex+2.
  6896 	addressBytes := returnArray at:retIndex+2.
  6896 
  6897 
  6897         addressBytes notNil ifTrue:[
  6898 	addressBytes notNil ifTrue:[
  6898             set := retDictionary at:name ifAbsentPut:[Set new].
  6899 	    set := retDictionary at:name ifAbsentPut:[Set new].
  6899             dict := Dictionary new:5.
  6900 	    dict := Dictionary new:5.
  6900             dict at:#flags put:(returnArray at:retIndex+1).
  6901 	    dict at:#flags put:(returnArray at:retIndex+1).
  6901             dict at:#address put:(SocketAddress fromBytes:addressBytes).
  6902 	    dict at:#address put:(SocketAddress fromBytes:addressBytes).
  6902             addressBytes := returnArray at:retIndex+3.
  6903 	    addressBytes := returnArray at:retIndex+3.
  6903             addressBytes notNil ifTrue:[
  6904 	    addressBytes notNil ifTrue:[
  6904                 dict at:#netMask put:(SocketAddress fromBytes:addressBytes).
  6905 		dict at:#netMask put:(SocketAddress fromBytes:addressBytes).
  6905             ].
  6906 	    ].
  6906             addressBytes := returnArray at:retIndex+4.
  6907 	    addressBytes := returnArray at:retIndex+4.
  6907             addressBytes notNil ifTrue:[
  6908 	    addressBytes notNil ifTrue:[
  6908                 dict at:#destAddress put:(SocketAddress fromBytes:addressBytes).
  6909 		dict at:#destAddress put:(SocketAddress fromBytes:addressBytes).
  6909             ].
  6910 	    ].
  6910             set add:dict.
  6911 	    set add:dict.
  6911         ].
  6912 	].
  6912         retIndex := retIndex + 5.
  6913 	retIndex := retIndex + 5.
  6913     ].
  6914     ].
  6914 
  6915 
  6915     ^ retDictionary
  6916     ^ retDictionary
  6916 
  6917 
  6917     "
  6918     "
  8233 
  8234 
  8234      OperatingSystem setEnvironment:#LD_LIBRARY_PATH to:'/opt/oracle/instantclient10_1'.
  8235      OperatingSystem setEnvironment:#LD_LIBRARY_PATH to:'/opt/oracle/instantclient10_1'.
  8235     "
  8236     "
  8236 !
  8237 !
  8237 
  8238 
  8238 setLocale:categorySymbol to:localeStringOrNil 
  8239 setLocale:categorySymbol to:localeStringOrNil
  8239     "set (and get) the locale for categorySymbol (e.g. #LC_ALL, #LC_CTYPE,....).
  8240     "set (and get) the locale for categorySymbol (e.g. #LC_ALL, #LC_CTYPE,....).
  8240      If localeStringOrNil is nil, nothing is set.
  8241      If localeStringOrNil is nil, nothing is set.
  8241      If localeStringOrNil is empty, the locale for categorySymbol ist set from the environment.
  8242      If localeStringOrNil is empty, the locale for categorySymbol ist set from the environment.
  8242      If localeStringOrNil is 'C', the locale for categorySymbol ist set to the default.
  8243      If localeStringOrNil is 'C', the locale for categorySymbol ist set to the default.
  8243      If localeStringOrNil is to a locale name, the locale for categorySymbol ist set.
  8244      If localeStringOrNil is to a locale name, the locale for categorySymbol ist set.
  8244      The current locale setting is returned."
  8245      The current locale setting is returned."
  8245     
  8246 
  8246     |locale error|
  8247     |locale error|
  8247     
  8248 
  8248 %{
  8249 %{
  8249     int __category;
  8250     int __category;
  8250     char *__locale, *ret;
  8251     char *__locale, *ret;
  8251 
  8252 
  8252     if (categorySymbol == @symbol(LC_ALL)) {
  8253     if (categorySymbol == @symbol(LC_ALL)) {
  8253         __category = LC_ALL;
  8254 	__category = LC_ALL;
  8254     } else if (categorySymbol == @symbol(LC_COLLATE)) {
  8255     } else if (categorySymbol == @symbol(LC_COLLATE)) {
  8255         __category = LC_COLLATE;
  8256 	__category = LC_COLLATE;
  8256     } else if (categorySymbol == @symbol(LC_CTYPE)) {
  8257     } else if (categorySymbol == @symbol(LC_CTYPE)) {
  8257         __category = LC_CTYPE;
  8258 	__category = LC_CTYPE;
  8258     } else if (categorySymbol == @symbol(LC_MESSAGES)) {
  8259     } else if (categorySymbol == @symbol(LC_MESSAGES)) {
  8259         __category = LC_MESSAGES;
  8260 	__category = LC_MESSAGES;
  8260     } else if (categorySymbol == @symbol(LC_MONETARY)) {
  8261     } else if (categorySymbol == @symbol(LC_MONETARY)) {
  8261         __category = LC_MONETARY;
  8262 	__category = LC_MONETARY;
  8262     } else if (categorySymbol == @symbol(LC_NUMERIC)) {
  8263     } else if (categorySymbol == @symbol(LC_NUMERIC)) {
  8263         __category = LC_NUMERIC;
  8264 	__category = LC_NUMERIC;
  8264     } else if (categorySymbol == @symbol(LC_TIME)) {
  8265     } else if (categorySymbol == @symbol(LC_TIME)) {
  8265         __category = LC_TIME;
  8266 	__category = LC_TIME;
  8266     } else {
  8267     } else {
  8267         error = @symbol(argument1);
  8268 	error = @symbol(argument1);
  8268         goto out;
  8269 	goto out;
  8269     }
  8270     }
  8270 
  8271 
  8271     if (localeStringOrNil == nil) {
  8272     if (localeStringOrNil == nil) {
  8272         __locale = 0;
  8273 	__locale = 0;
  8273     } else if (__isStringLike(localeStringOrNil)){
  8274     } else if (__isStringLike(localeStringOrNil)){
  8274         __locale = __stringVal(localeStringOrNil);
  8275 	__locale = __stringVal(localeStringOrNil);
  8275     } else {
  8276     } else {
  8276         error = @symbol(argument1);
  8277 	error = @symbol(argument1);
  8277         goto out;
  8278 	goto out;
  8278     }
  8279     }
  8279 
  8280 
  8280     ret = setlocale(__category, __locale);
  8281     ret = setlocale(__category, __locale);
  8281     if (ret) {
  8282     if (ret) {
  8282         locale = __MKSTRING(ret);
  8283 	locale = __MKSTRING(ret);
  8283     }
  8284     }
  8284 
  8285 
  8285 out:;
  8286 out:;
  8286 %}.
  8287 %}.
  8287     locale notNil ifTrue:[
  8288     locale notNil ifTrue:[
  8288         ^ locale.
  8289 	^ locale.
  8289     ].
  8290     ].
  8290     ^ self primitiveFailed:error.
  8291     ^ self primitiveFailed:error.
  8291 
  8292 
  8292     "
  8293     "
  8293      OperatingSystem setLocale:#LC_ALL to:nil
  8294      OperatingSystem setLocale:#LC_ALL to:nil
  8689 
  8690 
  8690 	tm.tm_year = __intVal(y) - 1900;
  8691 	tm.tm_year = __intVal(y) - 1900;
  8691 	tm.tm_mon = __intVal(m) - 1;
  8692 	tm.tm_mon = __intVal(m) - 1;
  8692 	tm.tm_mday = __intVal(d);
  8693 	tm.tm_mday = __intVal(d);
  8693 	tm.tm_isdst = -1;
  8694 	tm.tm_isdst = -1;
  8694 
  8695 #ifdef HAS_TIMEGM
  8695 	t = mktime(&tm);                        /* mktime() interprets tm as localtime */
  8696 	if (utcBoolean == true) {               /* convert to utc time */
       
  8697 	    t = timegm(&tm);                    /* timegm() interprets tm as utc time */
       
  8698 	} else
       
  8699 #endif
       
  8700 	{
       
  8701 	    t = mktime(&tm);                    /* mktime() interprets tm as localtime */
       
  8702 	}
  8696 	if ((INT)t != -1) {
  8703 	if ((INT)t != -1) {
       
  8704 #ifndef HAS_TIMEGM
  8697 	    if (utcBoolean == true) {           /* convert to utc time */
  8705 	    if (utcBoolean == true) {           /* convert to utc time */
  8698 		t = (INT)t - TIMEZONE(&tm);     /* TIMZONE = seconds westward from 0 */
  8706 		t = (INT)t - TIMEZONE(&tm);     /* TIMZONE = seconds westward from 0 */
  8699 	    }
  8707 	    }
       
  8708 #endif
  8700 	    osSeconds = __MKINT((INT)t);        /* be careful, t can be negative at the start of the epoch ! */
  8709 	    osSeconds = __MKINT((INT)t);        /* be careful, t can be negative at the start of the epoch ! */
  8701 	}
  8710 	}
  8702     }
  8711     }
  8703 %}.
  8712 %}.
  8704     osSeconds notNil ifTrue:[
  8713     osSeconds notNil ifTrue:[
  9085 !UnixOperatingSystem class methodsFor:'users & groups'!
  9094 !UnixOperatingSystem class methodsFor:'users & groups'!
  9086 
  9095 
  9087 getDesktopDirectory
  9096 getDesktopDirectory
  9088     "{ Pragma: +optSpace }"
  9097     "{ Pragma: +optSpace }"
  9089     "return the name of the user's desktop directory."
  9098     "return the name of the user's desktop directory."
  9090     
  9099 
  9091     |home desktop|
  9100     |home desktop|
  9092 
  9101 
  9093     home := self getHomeDirectory.
  9102     home := self getHomeDirectory.
  9094     desktop := home,'/Desktop'.
  9103     desktop := home,'/Desktop'.
  9095     desktop asFilename exists ifTrue:[^ desktop].
  9104     desktop asFilename exists ifTrue:[^ desktop].
  9322 
  9331 
  9323     ^ (self getEffectiveUserID == 0)
  9332     ^ (self getEffectiveUserID == 0)
  9324     and:[self getUserID ~~ 0 ]
  9333     and:[self getUserID ~~ 0 ]
  9325 
  9334 
  9326     "
  9335     "
  9327      self isRunningWithElevatedRootOrAdminRights 
  9336      self isRunningWithElevatedRootOrAdminRights
  9328     "
  9337     "
  9329 !
  9338 !
  9330 
  9339 
  9331 isRunningWithRootOrAdminRights
  9340 isRunningWithRootOrAdminRights
  9332     "return true, if running with root rights (either an elevated normal user
  9341     "return true, if running with root rights (either an elevated normal user
 11599 
 11608 
 11600     domain := OperatingSystem domainCodeOf:domainArg.
 11609     domain := OperatingSystem domainCodeOf:domainArg.
 11601     type := OperatingSystem socketTypeCodeOf:typeArg.
 11610     type := OperatingSystem socketTypeCodeOf:typeArg.
 11602     proto := self protocolCodeOf:protoArg.
 11611     proto := self protocolCodeOf:protoArg.
 11603     serviceNameArg notNil ifTrue:[
 11612     serviceNameArg notNil ifTrue:[
 11604         serviceName := serviceNameArg printString.      "convert integer port numbers"
 11613 	serviceName := serviceNameArg printString.      "convert integer port numbers"
 11605     ].
 11614     ].
 11606 
 11615 
 11607     hostName isNil ifTrue:[
 11616     hostName isNil ifTrue:[
 11608         encodedHostName := nil.
 11617 	encodedHostName := nil.
 11609     ] ifFalse:[
 11618     ] ifFalse:[
 11610         encodedHostName := hostName utf8Encoded.
 11619 	encodedHostName := hostName utf8Encoded.
 11611     ].
 11620     ].
 11612     (encodedHostName ~~ hostName and:[OperatingSystem getCodeset ~~ #utf8]) ifTrue:[
 11621     (encodedHostName ~~ hostName and:[OperatingSystem getCodeset ~~ #utf8]) ifTrue:[
 11613         "hostName is not plain ASCII - so this is an IDN domain name. Have to ensure, that the locale is UTF-8.
 11622 	"hostName is not plain ASCII - so this is an IDN domain name. Have to ensure, that the locale is UTF-8.
 11614          Block interrupt to not affect othe ST/X processes while the locale is changed."
 11623 	 Block interrupt to not affect othe ST/X processes while the locale is changed."
 11615         |interruptsBlocked oldLocale|
 11624 	|interruptsBlocked oldLocale|
 11616 
 11625 
 11617         interruptsBlocked := OperatingSystem blockInterrupts.
 11626 	interruptsBlocked := OperatingSystem blockInterrupts.
 11618         oldLocale := OperatingSystem setLocale:#'LC_CTYPE' to:nil.
 11627 	oldLocale := OperatingSystem setLocale:#'LC_CTYPE' to:nil.
 11619         OperatingSystem setLocale:#'LC_CTYPE' to:'en_US.UTF-8'.
 11628 	OperatingSystem setLocale:#'LC_CTYPE' to:'en_US.UTF-8'.
 11620         result := self primGetAddressInfo:encodedHostName serviceName:serviceName domainCode:domain socketTypeCode:type protocolCode:proto flags:flags.
 11629 	result := self primGetAddressInfo:encodedHostName serviceName:serviceName domainCode:domain socketTypeCode:type protocolCode:proto flags:flags.
 11621         OperatingSystem setLocale:#'LC_CTYPE' to:oldLocale.
 11630 	OperatingSystem setLocale:#'LC_CTYPE' to:oldLocale.
 11622         interruptsBlocked ifFalse:[
 11631 	interruptsBlocked ifFalse:[
 11623             OperatingSystem unblockInterrupts.
 11632 	    OperatingSystem unblockInterrupts.
 11624         ].
 11633 	].
 11625     ] ifFalse:[
 11634     ] ifFalse:[
 11626         result := self primGetAddressInfo:encodedHostName serviceName:serviceName domainCode:domain socketTypeCode:type protocolCode:proto flags:flags.
 11635 	result := self primGetAddressInfo:encodedHostName serviceName:serviceName domainCode:domain socketTypeCode:type protocolCode:proto flags:flags.
 11627     ].
 11636     ].
 11628     result isArray ifFalse:[
 11637     result isArray ifFalse:[
 11629         |request|
 11638 	|request|
 11630         request := SocketAddressInfo new
 11639 	request := SocketAddressInfo new
 11631             domain:domainArg;
 11640 	    domain:domainArg;
 11632             type:typeArg;
 11641 	    type:typeArg;
 11633             protocol:protoArg;
 11642 	    protocol:protoArg;
 11634             canonicalName:hostName;
 11643 	    canonicalName:hostName;
 11635             serviceName:serviceName.
 11644 	    serviceName:serviceName.
 11636         ^ (HostNameLookupError new
 11645 	^ (HostNameLookupError new
 11637                 parameter:result;
 11646 		parameter:result;
 11638                 messageText:' - ', (result printString);
 11647 		messageText:' - ', (result printString);
 11639                 request:request) raiseRequest.
 11648 		request:request) raiseRequest.
 11640     ].
 11649     ].
 11641     1 to:result size do:[:i |
 11650     1 to:result size do:[:i |
 11642         |entry dom info|
 11651 	|entry dom info|
 11643 
 11652 
 11644         entry := result at:i.
 11653 	entry := result at:i.
 11645 
 11654 
 11646         info := SocketAddressInfo new.
 11655 	info := SocketAddressInfo new.
 11647         info
 11656 	info
 11648             flags:(entry at:1);
 11657 	    flags:(entry at:1);
 11649             domain:(dom := OperatingSystem domainSymbolOf:(entry at:2));
 11658 	    domain:(dom := OperatingSystem domainSymbolOf:(entry at:2));
 11650             type:(OperatingSystem socketTypeSymbolOf:(entry at:3));
 11659 	    type:(OperatingSystem socketTypeSymbolOf:(entry at:3));
 11651             protocol:(self protocolSymbolOf:(entry at:4));
 11660 	    protocol:(self protocolSymbolOf:(entry at:4));
 11652             socketAddress:((SocketAddress newDomain:dom) fromBytes:(entry at:5));
 11661 	    socketAddress:((SocketAddress newDomain:dom) fromBytes:(entry at:5));
 11653             canonicalName:(entry at:6).
 11662 	    canonicalName:(entry at:6).
 11654 
 11663 
 11655         result at:i put:info.
 11664 	result at:i put:info.
 11656     ].
 11665     ].
 11657     ^ result
 11666     ^ result
 11658 
 11667 
 11659     "
 11668     "
 11660      self getAddressInfo:'localhost' serviceName:nil
 11669      self getAddressInfo:'localhost' serviceName:nil
 11661             domain:nil type:nil protocol:nil flags:nil
 11670 	    domain:nil type:nil protocol:nil flags:nil
 11662      self getAddressInfo:'localhost' serviceName:nil
 11671      self getAddressInfo:'localhost' serviceName:nil
 11663             domain:#inet type:#stream protocol:nil flags:nil
 11672 	    domain:#inet type:#stream protocol:nil flags:nil
 11664      self getAddressInfo:'localhost' serviceName:nil
 11673      self getAddressInfo:'localhost' serviceName:nil
 11665             domain:#inet type:#stream protocol:#tcp flags:nil
 11674 	    domain:#inet type:#stream protocol:#tcp flags:nil
 11666      self getAddressInfo:'blurb.exept.de' serviceName:nil
 11675      self getAddressInfo:'blurb.exept.de' serviceName:nil
 11667             domain:#inet type:nil protocol:nil flags:nil
 11676 	    domain:#inet type:nil protocol:nil flags:nil
 11668      self getAddressInfo:'1.2.3.4' serviceName:'bla'
 11677      self getAddressInfo:'1.2.3.4' serviceName:'bla'
 11669             domain:#inet type:nil protocol:nil flags:nil
 11678 	    domain:#inet type:nil protocol:nil flags:nil
 11670      self getAddressInfo:'localhost' serviceName:'echo'
 11679      self getAddressInfo:'localhost' serviceName:'echo'
 11671             domain:#inet type:nil protocol:nil flags:nil
 11680 	    domain:#inet type:nil protocol:nil flags:nil
 11672      self getAddressInfo:nil serviceName:'echo'
 11681      self getAddressInfo:nil serviceName:'echo'
 11673             domain:#inet type:nil protocol:nil flags:nil
 11682 	    domain:#inet type:nil protocol:nil flags:nil
 11674      self getAddressInfo:nil serviceName:nil
 11683      self getAddressInfo:nil serviceName:nil
 11675             domain:#inet type:nil protocol:nil flags:nil
 11684 	    domain:#inet type:nil protocol:nil flags:nil
 11676      self getAddressInfo:'www.google.de' serviceName:nil
 11685      self getAddressInfo:'www.google.de' serviceName:nil
 11677             domain:nil type:nil protocol:nil flags:nil
 11686 	    domain:nil type:nil protocol:nil flags:nil
 11678      self getAddressInfo:'www.exept.de' serviceName:nil
 11687      self getAddressInfo:'www.exept.de' serviceName:nil
 11679             domain:nil type:nil protocol:nil flags:nil
 11688 	    domain:nil type:nil protocol:nil flags:nil
 11680      self getAddressInfo:'www.exept.de' serviceName:nil
 11689      self getAddressInfo:'www.exept.de' serviceName:nil
 11681             domain:#'AF_INET' type:nil protocol:nil flags:nil
 11690 	    domain:#'AF_INET' type:nil protocol:nil flags:nil
 11682      self getAddressInfo:'www.exept.de' serviceName:nil
 11691      self getAddressInfo:'www.exept.de' serviceName:nil
 11683             domain:#'AF_INET6' type:nil protocol:nil flags:nil
 11692 	    domain:#'AF_INET6' type:nil protocol:nil flags:nil
 11684      self getAddressInfo:'www.baden-wrttemberg.de' serviceName:nil
 11693      self getAddressInfo:'www.baden-wrttemberg.de' serviceName:nil
 11685             domain:#'AF_INET' type:#stream protocol:nil flags:nil
 11694 	    domain:#'AF_INET' type:#stream protocol:nil flags:nil
 11686     "
 11695     "
 11687 !
 11696 !
 11688 
 11697 
 11689 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags
 11698 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags
 11690     "answer an Array containing the hostName and serviceName
 11699     "answer an Array containing the hostName and serviceName
 11932 #if !defined(NO_SOCKET)
 11941 #if !defined(NO_SOCKET)
 11933     char *__hostName, *__serviceName;
 11942     char *__hostName, *__serviceName;
 11934     int ret, cnt = 0;
 11943     int ret, cnt = 0;
 11935 
 11944 
 11936     if (hostName == nil) {
 11945     if (hostName == nil) {
 11937         __hostName = 0;
 11946 	__hostName = 0;
 11938     } else if (__isStringLike(hostName)) {
 11947     } else if (__isStringLike(hostName)) {
 11939         __hostName = __stringVal(hostName);
 11948 	__hostName = __stringVal(hostName);
 11940     } else {
 11949     } else {
 11941         error = @symbol(badArgument1);
 11950 	error = @symbol(badArgument1);
 11942         goto out;
 11951 	goto out;
 11943     }
 11952     }
 11944     if (serviceName == nil) {
 11953     if (serviceName == nil) {
 11945         __serviceName = 0;
 11954 	__serviceName = 0;
 11946     } else if (__isStringLike(serviceName)) {
 11955     } else if (__isStringLike(serviceName)) {
 11947         __serviceName = __stringVal(serviceName);
 11956 	__serviceName = __stringVal(serviceName);
 11948     } else {
 11957     } else {
 11949         error = @symbol(badArgument2);
 11958 	error = @symbol(badArgument2);
 11950         goto out;
 11959 	goto out;
 11951     }
 11960     }
 11952     if (__hostName == 0 && __serviceName == 0) {
 11961     if (__hostName == 0 && __serviceName == 0) {
 11953         error = @symbol(badArgument);
 11962 	error = @symbol(badArgument);
 11954         goto out;
 11963 	goto out;
 11955     }
 11964     }
 11956 
 11965 
 11957 {
 11966 {
 11958 # if defined(AI_NUMERICHOST)
 11967 # if defined(AI_NUMERICHOST)
 11959     /*
 11968     /*
 11964 
 11973 
 11965 #if defined(AI_IDN)
 11974 #if defined(AI_IDN)
 11966     hints.ai_flags = AI_IDN | AI_CANONIDN;      // map non-ascii domain names to IDN format
 11975     hints.ai_flags = AI_IDN | AI_CANONIDN;      // map non-ascii domain names to IDN format
 11967 #endif
 11976 #endif
 11968     if (__isSmallInteger(domain))
 11977     if (__isSmallInteger(domain))
 11969         hints.ai_family = __intVal(domain);
 11978 	hints.ai_family = __intVal(domain);
 11970     if (__isSmallInteger(type))
 11979     if (__isSmallInteger(type))
 11971         hints.ai_socktype = __intVal(type);
 11980 	hints.ai_socktype = __intVal(type);
 11972     if (__isSmallInteger(proto))
 11981     if (__isSmallInteger(proto))
 11973         hints.ai_protocol = __intVal(proto);
 11982 	hints.ai_protocol = __intVal(proto);
 11974     if (__isSmallInteger(flags))
 11983     if (__isSmallInteger(flags))
 11975         hints.ai_flags |= __intVal(flags);
 11984 	hints.ai_flags |= __intVal(flags);
 11976 
 11985 
 11977     do {
 11986     do {
 11978         /* reload */
 11987 	/* reload */
 11979         if (__hostName) {
 11988 	if (__hostName) {
 11980             __hostName = __stringVal(hostName);
 11989 	    __hostName = __stringVal(hostName);
 11981         }
 11990 	}
 11982         if (__serviceName) {
 11991 	if (__serviceName) {
 11983             __serviceName = __stringVal(serviceName);
 11992 	    __serviceName = __stringVal(serviceName);
 11984         }
 11993 	}
 11985 
 11994 
 11986 //        __BEGIN_INTERRUPTABLE__
 11995 //        __BEGIN_INTERRUPTABLE__
 11987         ret = getaddrinfo(__hostName, __serviceName, &hints, &info);
 11996 	ret = getaddrinfo(__hostName, __serviceName, &hints, &info);
 11988 //        __END_INTERRUPTABLE__
 11997 //        __END_INTERRUPTABLE__
 11989     } while (ret == EAI_SYSTEM && errno == EINTR);
 11998     } while (ret == EAI_SYSTEM && errno == EINTR);
 11990     if (ret != 0) {
 11999     if (ret != 0) {
 11991         switch (ret) {
 12000 	switch (ret) {
 11992         case EAI_FAMILY:
 12001 	case EAI_FAMILY:
 11993             error = @symbol(badProtocol);
 12002 	    error = @symbol(badProtocol);
 11994             break;
 12003 	    break;
 11995         case EAI_SOCKTYPE:
 12004 	case EAI_SOCKTYPE:
 11996             error = @symbol(badSocketType);
 12005 	    error = @symbol(badSocketType);
 11997             break;
 12006 	    break;
 11998         case EAI_BADFLAGS:
 12007 	case EAI_BADFLAGS:
 11999             error = @symbol(badFlags);
 12008 	    error = @symbol(badFlags);
 12000             break;
 12009 	    break;
 12001         case EAI_NONAME:
 12010 	case EAI_NONAME:
 12002             error = @symbol(unknownHost);
 12011 	    error = @symbol(unknownHost);
 12003             break;
 12012 	    break;
 12004         case EAI_SERVICE:
 12013 	case EAI_SERVICE:
 12005             error = @symbol(unknownService);
 12014 	    error = @symbol(unknownService);
 12006             break;
 12015 	    break;
 12007 #ifdef EAI_ADDRFAMILY
 12016 #ifdef EAI_ADDRFAMILY
 12008         case EAI_ADDRFAMILY :
 12017 	case EAI_ADDRFAMILY :
 12009             error = @symbol(unknownHostForProtocol);
 12018 	    error = @symbol(unknownHostForProtocol);
 12010             break;
 12019 	    break;
 12011 #endif
 12020 #endif
 12012 #ifdef EAI_NODATA
 12021 #ifdef EAI_NODATA
 12013         case EAI_NODATA:
 12022 	case EAI_NODATA:
 12014             error = @symbol(noAddress);
 12023 	    error = @symbol(noAddress);
 12015             break;
 12024 	    break;
 12016 #endif
 12025 #endif
 12017         case EAI_MEMORY:
 12026 	case EAI_MEMORY:
 12018             error = @symbol(allocationFailure);
 12027 	    error = @symbol(allocationFailure);
 12019             break;
 12028 	    break;
 12020         case EAI_FAIL:
 12029 	case EAI_FAIL:
 12021             error = @symbol(permanentFailure);
 12030 	    error = @symbol(permanentFailure);
 12022             break;
 12031 	    break;
 12023         case EAI_AGAIN:
 12032 	case EAI_AGAIN:
 12024             error = @symbol(tryAgain);
 12033 	    error = @symbol(tryAgain);
 12025             break;
 12034 	    break;
 12026         case EAI_SYSTEM:
 12035 	case EAI_SYSTEM:
 12027             error = @symbol(systemError);
 12036 	    error = @symbol(systemError);
 12028             break;
 12037 	    break;
 12029         default:
 12038 	default:
 12030             error = @symbol(unknownError);
 12039 	    error = @symbol(unknownError);
 12031         }
 12040 	}
 12032         errorString = __MKSTRING(gai_strerror(ret));
 12041 	errorString = __MKSTRING(gai_strerror(ret));
 12033         goto err;
 12042 	goto err;
 12034     }
 12043     }
 12035     for (cnt=0, infop=info; infop; infop=infop->ai_next)
 12044     for (cnt=0, infop=info; infop; infop=infop->ai_next)
 12036         cnt++;
 12045 	cnt++;
 12037 
 12046 
 12038     result = __ARRAY_NEW_INT(cnt);
 12047     result = __ARRAY_NEW_INT(cnt);
 12039     if (result == nil) {
 12048     if (result == nil) {
 12040         error = @symbol(allocationFailure);
 12049 	error = @symbol(allocationFailure);
 12041         goto err;
 12050 	goto err;
 12042     }
 12051     }
 12043     for (infop=info, cnt=0; infop; infop=infop->ai_next, cnt++) {
 12052     for (infop=info, cnt=0; infop; infop=infop->ai_next, cnt++) {
 12044         OBJ o, resp;
 12053 	OBJ o, resp;
 12045 
 12054 
 12046         resp = __ARRAY_NEW_INT(6);
 12055 	resp = __ARRAY_NEW_INT(6);
 12047         if (resp == nil) {
 12056 	if (resp == nil) {
 12048             error = @symbol(allocationFailure);
 12057 	    error = @symbol(allocationFailure);
 12049             goto err;
 12058 	    goto err;
 12050         }
 12059 	}
 12051 
 12060 
 12052         __ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp);
 12061 	__ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp);
 12053 
 12062 
 12054         __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags);
 12063 	__ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags);
 12055         __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family);
 12064 	__ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family);
 12056         __ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype);
 12065 	__ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype);
 12057         __ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol);
 12066 	__ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol);
 12058 
 12067 
 12059         __PROTECT__(resp);
 12068 	__PROTECT__(resp);
 12060         o = __BYTEARRAY_NEW_INT(infop->ai_addrlen);
 12069 	o = __BYTEARRAY_NEW_INT(infop->ai_addrlen);
 12061         __UNPROTECT__(resp);
 12070 	__UNPROTECT__(resp);
 12062         if (o == nil) {
 12071 	if (o == nil) {
 12063             error = @symbol(allocationFailure);
 12072 	    error = @symbol(allocationFailure);
 12064             goto err;
 12073 	    goto err;
 12065         }
 12074 	}
 12066         memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen);
 12075 	memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen);
 12067        __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o);
 12076        __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o);
 12068 
 12077 
 12069         if (infop->ai_canonname) {
 12078 	if (infop->ai_canonname) {
 12070             __PROTECT__(resp);
 12079 	    __PROTECT__(resp);
 12071             o = __MKSTRING(infop->ai_canonname);
 12080 	    o = __MKSTRING(infop->ai_canonname);
 12072             __UNPROTECT__(resp);
 12081 	    __UNPROTECT__(resp);
 12073             if (o == nil) {
 12082 	    if (o == nil) {
 12074                 error = @symbol(allocationFailure);
 12083 		error = @symbol(allocationFailure);
 12075                 goto err;
 12084 		goto err;
 12076             }
 12085 	    }
 12077             __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o);
 12086 	    __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o);
 12078         }
 12087 	}
 12079     }
 12088     }
 12080 
 12089 
 12081 err:
 12090 err:
 12082     if (info) freeaddrinfo(info);
 12091     if (info) freeaddrinfo(info);
 12083 
 12092 
 12090     char **addrpp;
 12099     char **addrpp;
 12091     int port = 0;
 12100     int port = 0;
 12092     int i;
 12101     int i;
 12093 
 12102 
 12094     if (__serviceName) {
 12103     if (__serviceName) {
 12095         struct servent *sp;
 12104 	struct servent *sp;
 12096         char *__proto = 0;
 12105 	char *__proto = 0;
 12097 
 12106 
 12098         if (__isStringLike(protoArg))
 12107 	if (__isStringLike(protoArg))
 12099             __proto = __stringVal(protoArg);
 12108 	    __proto = __stringVal(protoArg);
 12100 
 12109 
 12101         sp = getservbyname(__serviceName, __proto);
 12110 	sp = getservbyname(__serviceName, __proto);
 12102         if (sp == NULL) {
 12111 	if (sp == NULL) {
 12103             errorString = @symbol(unknownService);
 12112 	    errorString = @symbol(unknownService);
 12104             error = __mkSmallInteger(-3);
 12113 	    error = __mkSmallInteger(-3);
 12105             goto err;
 12114 	    goto err;
 12106         }
 12115 	}
 12107         port = sp->s_port;
 12116 	port = sp->s_port;
 12108     }
 12117     }
 12109 
 12118 
 12110     if (__hostName) {
 12119     if (__hostName) {
 12111 #  ifdef USE_H_ERRNO
 12120 #  ifdef USE_H_ERRNO
 12112         do {
 12121 	do {
 12113             if (hostName == nil) {
 12122 	    if (hostName == nil) {
 12114                 __hostName = 0;
 12123 		__hostName = 0;
 12115             } else if (__isStringLike(hostName)) {
 12124 	    } else if (__isStringLike(hostName)) {
 12116                 __hostName = __stringVal(hostName);
 12125 		__hostName = __stringVal(hostName);
 12117             }
 12126 	    }
 12118             /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname
 12127 	    /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname
 12119              * uses a static data area
 12128 	     * uses a static data area
 12120              */
 12129 	     */
 12121             __BEGIN_INTERRUPTABLE__
 12130 	    __BEGIN_INTERRUPTABLE__
 12122             hp = gethostbyname(__hostName);
 12131 	    hp = gethostbyname(__hostName);
 12123             __END_INTERRUPTABLE__
 12132 	    __END_INTERRUPTABLE__
 12124         } while ((hp == NULL)
 12133 	} while ((hp == NULL)
 12125                   && (
 12134 		  && (
 12126                         (h_errno == TRY_AGAIN)
 12135 			(h_errno == TRY_AGAIN)
 12127                       || errno == EINTR
 12136 		      || errno == EINTR
 12128 #   ifdef IRIX5_3
 12137 #   ifdef IRIX5_3
 12129                       || (errno == ECONNREFUSED)
 12138 		      || (errno == ECONNREFUSED)
 12130 #   endif
 12139 #   endif
 12131                      )
 12140 		     )
 12132         );
 12141 	);
 12133         if (hp == 0) {
 12142 	if (hp == 0) {
 12134             switch (h_errno) {
 12143 	    switch (h_errno) {
 12135             case HOST_NOT_FOUND:
 12144 	    case HOST_NOT_FOUND:
 12136                 errorString = @symbol(unknownHost);
 12145 		errorString = @symbol(unknownHost);
 12137                 break;
 12146 		break;
 12138             case NO_ADDRESS:
 12147 	    case NO_ADDRESS:
 12139                 errorString = @symbol(noAddress);
 12148 		errorString = @symbol(noAddress);
 12140                 break;
 12149 		break;
 12141             case NO_RECOVERY:
 12150 	    case NO_RECOVERY:
 12142                 errorString = @symbol(permanentFailure);
 12151 		errorString = @symbol(permanentFailure);
 12143                 break;
 12152 		break;
 12144             case TRY_AGAIN:
 12153 	    case TRY_AGAIN:
 12145                 errorString = @symbol(tryAgain);
 12154 		errorString = @symbol(tryAgain);
 12146                 break;
 12155 		break;
 12147             default:
 12156 	    default:
 12148                 errorString = @symbol(unknownError);
 12157 		errorString = @symbol(unknownError);
 12149                 break;
 12158 		break;
 12150             }
 12159 	    }
 12151             error = __mkSmallInteger(h_errno);
 12160 	    error = __mkSmallInteger(h_errno);
 12152             goto err;
 12161 	    goto err;
 12153         }
 12162 	}
 12154 #  else /* !USE_H_ERRNO */
 12163 #  else /* !USE_H_ERRNO */
 12155         hp = gethostbyname(__hostName);
 12164 	hp = gethostbyname(__hostName);
 12156         if (hp == 0) {
 12165 	if (hp == 0) {
 12157             errorString = @symbol(unknownHost);
 12166 	    errorString = @symbol(unknownHost);
 12158             error = __mkSmallInteger(-1);
 12167 	    error = __mkSmallInteger(-1);
 12159             goto err;
 12168 	    goto err;
 12160         }
 12169 	}
 12161 #  endif /* !USE_H_ERRNO*/
 12170 #  endif /* !USE_H_ERRNO*/
 12162 
 12171 
 12163         if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) {
 12172 	if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) {
 12164             errorString = @symbol(unknownHost);
 12173 	    errorString = @symbol(unknownHost);
 12165             error = __mkSmallInteger(-2);
 12174 	    error = __mkSmallInteger(-2);
 12166             goto err;
 12175 	    goto err;
 12167         }
 12176 	}
 12168 
 12177 
 12169         for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++)
 12178 	for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++)
 12170             cnt++;
 12179 	    cnt++;
 12171         addrpp = hp->h_addr_list;
 12180 	addrpp = hp->h_addr_list;
 12172     } else {
 12181     } else {
 12173         cnt = 1;
 12182 	cnt = 1;
 12174     }
 12183     }
 12175 
 12184 
 12176     result = __ARRAY_NEW_INT(cnt);
 12185     result = __ARRAY_NEW_INT(cnt);
 12177     if (result == nil) {
 12186     if (result == nil) {
 12178         error = @symbol(allocationFailure);
 12187 	error = @symbol(allocationFailure);
 12179         goto err;
 12188 	goto err;
 12180     }
 12189     }
 12181 
 12190 
 12182     for (i = 0; i < cnt; i++) {
 12191     for (i = 0; i < cnt; i++) {
 12183         OBJ o, resp;
 12192 	OBJ o, resp;
 12184         struct sockaddr_in *sa;
 12193 	struct sockaddr_in *sa;
 12185 
 12194 
 12186         resp = __ARRAY_NEW_INT(6);
 12195 	resp = __ARRAY_NEW_INT(6);
 12187         if (resp == nil) {
 12196 	if (resp == nil) {
 12188             error = @symbol(allocationFailure);
 12197 	    error = @symbol(allocationFailure);
 12189             goto err;
 12198 	    goto err;
 12190         }
 12199 	}
 12191 
 12200 
 12192         __ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp);
 12201 	__ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp);
 12193         __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0);
 12202 	__ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0);
 12194         __ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type);
 12203 	__ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type);
 12195         __ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto);
 12204 	__ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto);
 12196         __PROTECT__(resp);
 12205 	__PROTECT__(resp);
 12197         o = __BYTEARRAY_NEW_INT(sizeof(*sa));
 12206 	o = __BYTEARRAY_NEW_INT(sizeof(*sa));
 12198         __UNPROTECT__(resp);
 12207 	__UNPROTECT__(resp);
 12199         if (o == nil) {
 12208 	if (o == nil) {
 12200             error = @symbol(allocationFailure);
 12209 	    error = @symbol(allocationFailure);
 12201             goto err;
 12210 	    goto err;
 12202         }
 12211 	}
 12203         __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o);
 12212 	__ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o);
 12204         sa = (struct sockaddr_in *)__byteArrayVal(o);
 12213 	sa = (struct sockaddr_in *)__byteArrayVal(o);
 12205         sa->sin_port = port;
 12214 	sa->sin_port = port;
 12206 
 12215 
 12207         if (__hostName) {
 12216 	if (__hostName) {
 12208             sa->sin_family = hp->h_addrtype;
 12217 	    sa->sin_family = hp->h_addrtype;
 12209             memcpy(&sa->sin_addr, *addrpp, hp->h_length);
 12218 	    memcpy(&sa->sin_addr, *addrpp, hp->h_length);
 12210             __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype);
 12219 	    __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype);
 12211             if (hp->h_name) {
 12220 	    if (hp->h_name) {
 12212                 __PROTECT__(resp);
 12221 		__PROTECT__(resp);
 12213                 o = __MKSTRING(hp->h_name);
 12222 		o = __MKSTRING(hp->h_name);
 12214                 __UNPROTECT__(resp);
 12223 		__UNPROTECT__(resp);
 12215                 if (o == nil) {
 12224 		if (o == nil) {
 12216                     error = @symbol(allocationFailure);
 12225 		    error = @symbol(allocationFailure);
 12217                     goto err;
 12226 		    goto err;
 12218                 }
 12227 		}
 12219                 __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o);
 12228 		__ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o);
 12220             }
 12229 	    }
 12221             addrpp++;
 12230 	    addrpp++;
 12222         } else{
 12231 	} else{
 12223             __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain);
 12232 	    __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain);
 12224         }
 12233 	}
 12225     }
 12234     }
 12226 
 12235 
 12227 err:;
 12236 err:;
 12228 # endif /* ! AI_NUMERICHOST */
 12237 # endif /* ! AI_NUMERICHOST */
 12229 }
 12238 }
 12231     error = @symbol(notImplemented);
 12240     error = @symbol(notImplemented);
 12232 #endif
 12241 #endif
 12233 out:;
 12242 out:;
 12234 %}.
 12243 %}.
 12235     error notNil ifTrue:[
 12244     error notNil ifTrue:[
 12236         errorString notNil ifTrue:[
 12245 	errorString notNil ifTrue:[
 12237             ^ errorString.
 12246 	    ^ errorString.
 12238         ].
 12247 	].
 12239         ^ error.
 12248 	^ error.
 12240     ].
 12249     ].
 12241     ^ result.
 12250     ^ result.
 12242 ! !
 12251 ! !
 12243 
 12252 
 12244 !UnixOperatingSystem::SocketHandle methodsFor:'accepting'!
 12253 !UnixOperatingSystem::SocketHandle methodsFor:'accepting'!
 13080 ! !
 13089 ! !
 13081 
 13090 
 13082 !UnixOperatingSystem class methodsFor:'documentation'!
 13091 !UnixOperatingSystem class methodsFor:'documentation'!
 13083 
 13092 
 13084 version
 13093 version
 13085     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.338 2013-12-17 16:46:05 cg Exp $'
 13094     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.339 2014-01-25 00:30:52 cg Exp $'
 13086 !
 13095 !
 13087 
 13096 
 13088 version_CVS
 13097 version_CVS
 13089     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.338 2013-12-17 16:46:05 cg Exp $'
 13098     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.339 2014-01-25 00:30:52 cg Exp $'
 13090 !
 13099 !
 13091 
 13100 
 13092 version_HG
 13101 version_HG
 13093 
 13102 
 13094     ^ '$Changeset: <not expanded> $'
 13103     ^ '$Changeset: <not expanded> $'