. Changes in shared code that don't affect open-vm-tools functionality.
. Refactoring of functions from lib/user to lib/misc.
. guest_os: Use the official defines instead of simple strings.
. code cleanup and code-style related changes.
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
* because you don't want to display error messages after a user has
* cancelled an operation.
*/
- result = MSGID(fileio.cancel) "The operation was cancelled by the user";
+ result = MSGID(fileio.cancel) "The operation was canceled by the user";
break;
case FILEIO_ERROR:
*/
/* Linux */
-#define STR_OS_ANNVIX "Annvix"
-#define STR_OS_ARCH "Arch"
-#define STR_OS_ARKLINUX "Arklinux"
-#define STR_OS_ASIANUX_3 "asianux3"
-#define STR_OS_ASIANUX_4 "asianux4"
-#define STR_OS_AUROX "Aurox"
-#define STR_OS_ASIANUX "asianux"
-#define STR_OS_BLACKCAT "BlackCat"
-#define STR_OS_COBALT "Cobalt"
-#define STR_OS_CONECTIVA "Conectiva"
-#define STR_OS_DEBIAN "Debian"
-#define STR_OS_DEBIAN_4 "debian4"
-#define STR_OS_DEBIAN_5 "debian5"
-#define STR_OS_FEDORA "Fedora"
-#define STR_OS_GENTOO "Gentoo"
-#define STR_OS_IMMUNIX "Immunix"
-#define STR_OS_LINUX "linux"
+#define STR_OS_ANNVIX "Annvix"
+#define STR_OS_ARCH "Arch"
+#define STR_OS_ARKLINUX "Arklinux"
+#define STR_OS_ASIANUX_3 "asianux3"
+#define STR_OS_ASIANUX_4 "asianux4"
+#define STR_OS_AUROX "Aurox"
+#define STR_OS_ASIANUX "asianux"
+#define STR_OS_BLACKCAT "BlackCat"
+#define STR_OS_COBALT "Cobalt"
+#define STR_OS_CONECTIVA "Conectiva"
+#define STR_OS_DEBIAN "Debian"
+#define STR_OS_DEBIAN_4 "debian4"
+#define STR_OS_DEBIAN_5 "debian5"
+#define STR_OS_FEDORA "Fedora"
+#define STR_OS_GENTOO "Gentoo"
+#define STR_OS_IMMUNIX "Immunix"
+#define STR_OS_LINUX "linux"
#define STR_OS_LINUX_FROM_SCRATCH "Linux-From-Scratch"
-#define STR_OS_LINUX_FULL "Other Linux"
-#define STR_OS_LINUX_PPC "Linux-PPC"
-#define STR_OS_MANDRAKE "mandrake"
-#define STR_OS_MANDRAKE_FULL "Mandrake Linux"
-#define STR_OS_MANDRIVA "mandriva"
-#define STR_OS_MKLINUX "MkLinux"
-#define STR_OS_NOVELL "nld9"
-#define STR_OS_NOVELL_FULL "Novell Linux Desktop 9"
-#define STR_OS_OTHER "otherlinux"
-#define STR_OS_OTHER_24 "other24xlinux"
-#define STR_OS_OTHER_24_FULL "Other Linux 2.4.x kernel"
-#define STR_OS_OTHER_26 "other26xlinux"
-#define STR_OS_OTHER_26_FULL "Other Linux 2.6.x kernel"
-#define STR_OS_OTHER_FULL "Other Linux"
-#define STR_OS_PLD "PLD"
-#define STR_OS_RED_HAT "redhat"
-#define STR_OS_RED_HAT_EN "rhel"
-#define STR_OS_RED_HAT_EN_2 "rhel2"
-#define STR_OS_RED_HAT_EN_2_FULL "Red Hat Enterprise Linux 2"
-#define STR_OS_RED_HAT_EN_3 "rhel3"
-#define STR_OS_RED_HAT_EN_3_FULL "Red Hat Enterprise Linux 3"
-#define STR_OS_RED_HAT_EN_4 "rhel4"
-#define STR_OS_RED_HAT_EN_4_FULL "Red Hat Enterprise Linux 4"
-#define STR_OS_RED_HAT_FULL "Red Hat Linux"
-#define STR_OS_SLACKWARE "Slackware"
-#define STR_OS_SLES_10 "sles10"
-#define STR_OS_SLES_10_FULL "SUSE Linux Enterprise Server 10"
-#define STR_OS_SLES_11 "sles11"
-#define STR_OS_SLES_11_FULL "SUSE Linux Enterprise Server 11"
-#define STR_OS_SMESERVER "SMEServer"
-#define STR_OS_SUN_DESK "sjds"
-#define STR_OS_SUN_DESK_FULL "Sun Java Desktop System"
-#define STR_OS_SUSE "suse"
-#define STR_OS_SUSE_EN "sles"
-#define STR_OS_SUSE_EN_FULL "SUSE Linux Enterprise Server"
-#define STR_OS_SUSE_FULL "SUSE Linux"
-#define STR_OS_TINYSOFA "Tiny Sofa"
-#define STR_OS_TURBO "turbolinux"
-#define STR_OS_TURBO_FULL "Turbolinux"
-#define STR_OS_UBUNTU "Ubuntu"
-#define STR_OS_ULTRAPENGUIN "UltraPenguin"
-#define STR_OS_UNITEDLINUX "UnitedLinux"
-#define STR_OS_VALINUX "VALinux"
-#define STR_OS_YELLOW_DOG "Yellow Dog"
+#define STR_OS_LINUX_FULL "Other Linux"
+#define STR_OS_LINUX_PPC "Linux-PPC"
+#define STR_OS_MANDRAKE "mandrake"
+#define STR_OS_MANDRAKE_FULL "Mandrake Linux"
+#define STR_OS_MANDRIVA "mandriva"
+#define STR_OS_MKLINUX "MkLinux"
+#define STR_OS_NOVELL "nld9"
+#define STR_OS_NOVELL_FULL "Novell Linux Desktop 9"
+#define STR_OS_OTHER "otherlinux"
+#define STR_OS_OTHER_24 "other24xlinux"
+#define STR_OS_OTHER_24_FULL "Other Linux 2.4.x kernel"
+#define STR_OS_OTHER_26 "other26xlinux"
+#define STR_OS_OTHER_26_FULL "Other Linux 2.6.x kernel"
+#define STR_OS_OTHER_FULL "Other Linux"
+#define STR_OS_PLD "PLD"
+#define STR_OS_RED_HAT "redhat"
+#define STR_OS_RED_HAT_EN "rhel"
+#define STR_OS_RED_HAT_EN_2 "rhel2"
+#define STR_OS_RED_HAT_EN_2_FULL "Red Hat Enterprise Linux 2"
+#define STR_OS_RED_HAT_EN_3 "rhel3"
+#define STR_OS_RED_HAT_EN_3_FULL "Red Hat Enterprise Linux 3"
+#define STR_OS_RED_HAT_EN_4 "rhel4"
+#define STR_OS_RED_HAT_EN_4_FULL "Red Hat Enterprise Linux 4"
+#define STR_OS_RED_HAT_FULL "Red Hat Linux"
+#define STR_OS_SLACKWARE "Slackware"
+#define STR_OS_SLES_10 "sles10"
+#define STR_OS_SLES_10_FULL "SUSE Linux Enterprise Server 10"
+#define STR_OS_SLES_11 "sles11"
+#define STR_OS_SLES_11_FULL "SUSE Linux Enterprise Server 11"
+#define STR_OS_SMESERVER "SMEServer"
+#define STR_OS_SUN_DESK "sjds"
+#define STR_OS_SUN_DESK_FULL "Sun Java Desktop System"
+#define STR_OS_SUSE "suse"
+#define STR_OS_SUSE_EN "sles"
+#define STR_OS_SUSE_EN_FULL "SUSE Linux Enterprise Server"
+#define STR_OS_SUSE_FULL "SUSE Linux"
+#define STR_OS_TINYSOFA "Tiny Sofa"
+#define STR_OS_TURBO "turbolinux"
+#define STR_OS_TURBO_FULL "Turbolinux"
+#define STR_OS_UBUNTU "Ubuntu"
+#define STR_OS_ULTRAPENGUIN "UltraPenguin"
+#define STR_OS_UNITEDLINUX "UnitedLinux"
+#define STR_OS_VALINUX "VALinux"
+#define STR_OS_YELLOW_DOG "Yellow Dog"
/* Windows */
-#define STR_OS_WIN_31 "win31"
-#define STR_OS_WIN_31_FULL "Windows 3.1"
-#define STR_OS_WIN_95 "win95"
-#define STR_OS_WIN_95_FULL "Windows 95"
-#define STR_OS_WIN_98 "win98"
-#define STR_OS_WIN_98_FULL "Windows 98"
-#define STR_OS_WIN_ME "winMe"
-#define STR_OS_WIN_ME_FULL "Windows Me"
-#define STR_OS_WIN_NT "winNT"
-#define STR_OS_WIN_NT_FULL "Windows NT"
-#define STR_OS_WIN_2000_PRO "win2000Pro"
-#define STR_OS_WIN_2000_PRO_FULL "Windows 2000 Professional"
-#define STR_OS_WIN_2000_SERV "win2000Serv"
-#define STR_OS_WIN_2000_SERV_FULL "Windows 2000 Server"
-#define STR_OS_WIN_2000_ADV_SERV "win2000AdvServ"
-#define STR_OS_WIN_2000_ADV_SERV_FULL "Windows 2000 Advanced Server"
-#define STR_OS_WIN_2000_DATACENT_SERV "win2000DataCentServ"
+#define STR_OS_WIN_31 "win31"
+#define STR_OS_WIN_31_FULL "Windows 3.1"
+#define STR_OS_WIN_95 "win95"
+#define STR_OS_WIN_95_FULL "Windows 95"
+#define STR_OS_WIN_98 "win98"
+#define STR_OS_WIN_98_FULL "Windows 98"
+#define STR_OS_WIN_ME "winMe"
+#define STR_OS_WIN_ME_FULL "Windows Me"
+#define STR_OS_WIN_NT "winNT"
+#define STR_OS_WIN_NT_FULL "Windows NT"
+#define STR_OS_WIN_2000_PRO "win2000Pro"
+#define STR_OS_WIN_2000_PRO_FULL "Windows 2000 Professional"
+#define STR_OS_WIN_2000_SERV "win2000Serv"
+#define STR_OS_WIN_2000_SERV_FULL "Windows 2000 Server"
+#define STR_OS_WIN_2000_ADV_SERV "win2000AdvServ"
+#define STR_OS_WIN_2000_ADV_SERV_FULL "Windows 2000 Advanced Server"
+#define STR_OS_WIN_2000_DATACENT_SERV "win2000DataCentServ"
#define STR_OS_WIN_2000_DATACENT_SERV_FULL "Windows 2000 Data Center Server"
-#define STR_OS_WIN_XP_HOME "winXPHome"
-#define STR_OS_WIN_XP_HOME_FULL "Windows XP Home Edition"
-#define STR_OS_WIN_XP_PRO "winXPPro"
-#define STR_OS_WIN_XP_PRO_FULL "Windows XP Professional"
-#define STR_OS_WIN_XP_PRO_X64 "winXPPro-64"
-#define STR_OS_WIN_XP_PRO_X64_FULL "Windows XP Professional x64 Edition"
-#define STR_OS_WIN_NET_WEB "winNetWeb"
-#define STR_OS_WIN_NET_WEB_FULL "Windows Server 2003 Web Edition"
-#define STR_OS_WIN_NET_ST "winNetStandard"
-#define STR_OS_WIN_NET_ST_FULL "Windows Server 2003 Standard Edition"
-#define STR_OS_WIN_NET_EN "winNetEnterprise"
-#define STR_OS_WIN_NET_EN_FULL "Windows Server 2003 Enterprise Edition"
-#define STR_OS_WIN_NET_BUS "winNetBusiness"
-#define STR_OS_WIN_NET_BUS_FULL "Windows Server 2003 Small Business"
-#define STR_OS_WIN_NET_COMPCLUSTER "winNetComputeCluster"
+#define STR_OS_WIN_XP_HOME "winXPHome"
+#define STR_OS_WIN_XP_HOME_FULL "Windows XP Home Edition"
+#define STR_OS_WIN_XP_PRO "winXPPro"
+#define STR_OS_WIN_XP_PRO_FULL "Windows XP Professional"
+#define STR_OS_WIN_XP_PRO_X64 "winXPPro-64"
+#define STR_OS_WIN_XP_PRO_X64_FULL "Windows XP Professional x64 Edition"
+#define STR_OS_WIN_NET_WEB "winNetWeb"
+#define STR_OS_WIN_NET_WEB_FULL "Windows Server 2003 Web Edition"
+#define STR_OS_WIN_NET_ST "winNetStandard"
+#define STR_OS_WIN_NET_ST_FULL "Windows Server 2003 Standard Edition"
+#define STR_OS_WIN_NET_EN "winNetEnterprise"
+#define STR_OS_WIN_NET_EN_FULL "Windows Server 2003 Enterprise Edition"
+#define STR_OS_WIN_NET_BUS "winNetBusiness"
+#define STR_OS_WIN_NET_BUS_FULL "Windows Server 2003 Small Business"
+#define STR_OS_WIN_NET_COMPCLUSTER "winNetComputeCluster"
#define STR_OS_WIN_NET_COMPCLUSTER_FULL "Windows Server 2003 Compute Cluster Edition"
-#define STR_OS_WIN_NET_STORAGESERVER "winNetStorageSvr"
+#define STR_OS_WIN_NET_STORAGESERVER "winNetStorageSvr"
#define STR_OS_WIN_NET_STORAGESERVER_FULL "Windows Storage Server 2003"
-#define STR_OS_WIN_NET_DC_FULL "Windows Server 2003 Datacenter Edition"
-#define STR_OS_WIN_NET_DC "winNetDatacenter"
-#define STR_OS_WIN_LONG "longhorn"
-#define STR_OS_WIN_VISTA "winVista"
-#define STR_OS_WIN_VISTA_FULL "Windows Vista"
-#define STR_OS_WIN_VISTA_X64 "winVista-64"
-#define STR_OS_WIN_VISTA_X64_FULL "Windows Vista x64 Edition"
-#define STR_OS_WIN_VISTA_ULTIMATE "winVistaUltimate-32"
-#define STR_OS_WIN_VISTA_ULTIMATE_FULL "Windows Vista Ultimate Edition"
-#define STR_OS_WIN_VISTA_HOME_PREMIUM "winVistaHomePremium-32"
+#define STR_OS_WIN_NET_DC_FULL "Windows Server 2003 Datacenter Edition"
+#define STR_OS_WIN_NET_DC "winNetDatacenter"
+#define STR_OS_WIN_LONG "longhorn"
+#define STR_OS_WIN_VISTA "winVista"
+#define STR_OS_WIN_VISTA_FULL "Windows Vista"
+#define STR_OS_WIN_VISTA_X64 "winVista-64"
+#define STR_OS_WIN_VISTA_X64_FULL "Windows Vista x64 Edition"
+#define STR_OS_WIN_VISTA_ULTIMATE "winVistaUltimate-32"
+#define STR_OS_WIN_VISTA_ULTIMATE_FULL "Windows Vista Ultimate Edition"
+#define STR_OS_WIN_VISTA_HOME_PREMIUM "winVistaHomePremium-32"
#define STR_OS_WIN_VISTA_HOME_PREMIUM_FULL "Windows Vista Home Premium Edition"
-#define STR_OS_WIN_VISTA_HOME_BASIC "winVistaHomeBasic-32"
+#define STR_OS_WIN_VISTA_HOME_BASIC "winVistaHomeBasic-32"
#define STR_OS_WIN_VISTA_HOME_BASIC_FULL "Windows Vista Home Basic Edition"
-#define STR_OS_WIN_VISTA_ENTERPRISE "winVistaEnterprise-32"
+#define STR_OS_WIN_VISTA_ENTERPRISE "winVistaEnterprise-32"
#define STR_OS_WIN_VISTA_ENTERPRISE_FULL "Windows Vista Enterprise Edition"
-#define STR_OS_WIN_VISTA_BUSINESS "winVistaBusiness-32"
-#define STR_OS_WIN_VISTA_BUSINESS_FULL "Windows Vista Business Edition"
-#define STR_OS_WIN_VISTA_STARTER "winVistaStarter-32"
-#define STR_OS_WIN_VISTA_STARTER_FULL "Windows Vista Starter Edition"
-#define STR_OS_WIN_2008_CLUSTER "winServer2008Cluster-32"
+#define STR_OS_WIN_VISTA_BUSINESS "winVistaBusiness-32"
+#define STR_OS_WIN_VISTA_BUSINESS_FULL "Windows Vista Business Edition"
+#define STR_OS_WIN_VISTA_STARTER "winVistaStarter-32"
+#define STR_OS_WIN_VISTA_STARTER_FULL "Windows Vista Starter Edition"
+#define STR_OS_WIN_2008_CLUSTER "winServer2008Cluster-32"
#define STR_OS_WIN_2008_CLUSTER_FULL "Windows Server 2008 Cluster Server Edition"
-#define STR_OS_WIN_2008_DATACENTER "winServer2008Datacenter-32"
+#define STR_OS_WIN_2008_DATACENTER "winServer2008Datacenter-32"
#define STR_OS_WIN_2008_DATACENTER_FULL "Windows Server 2008 Datacenter Edition"
#define STR_OS_WIN_2008_DATACENTER_CORE "winServer2008DatacenterCore-32"
#define STR_OS_WIN_2008_DATACENTER_CORE_FULL "Windows Server 2008 Datacenter Edition (core installation)"
-#define STR_OS_WIN_2008_ENTERPRISE "winServer2008Enterprise-32"
+#define STR_OS_WIN_2008_ENTERPRISE "winServer2008Enterprise-32"
#define STR_OS_WIN_2008_ENTERPRISE_FULL "Windows Server 2008 Enterprise Edition"
#define STR_OS_WIN_2008_ENTERPRISE_CORE "winServer2008EnterpriseCore-32"
#define STR_OS_WIN_2008_ENTERPRISE_CORE_FULL "Windows Server 2008 Enterprise Edition (core installation)"
#define STR_OS_WIN_2008_WEB_SERVER_FULL "Windows Server 2008 Web Server Edition"
/* Windows 64-bit */
-#define STR_OS_WIN_VISTA_ULTIMATE_X64 "winVistaUltimate-64"
-#define STR_OS_WIN_VISTA_HOME_PREMIUM_X64 "winVistaHomePremium-64"
-#define STR_OS_WIN_VISTA_HOME_BASIC_X64 "winVistaHomeBasic-64"
-#define STR_OS_WIN_VISTA_ENTERPRISE_X64 "winVistaEnterprise-64"
-#define STR_OS_WIN_VISTA_BUSINESS_X64 "winVistaBusiness-64"
-#define STR_OS_WIN_VISTA_STARTER_X64 "winVistaStarter-64"
-#define STR_OS_WIN_2008_CLUSTER_X64 "winServer2008Cluster-64"
-#define STR_OS_WIN_2008_DATACENTER_X64 "winServer2008Datacenter-64"
-#define STR_OS_WIN_2008_DATACENTER_CORE_X64 "winServer2008DatacenterCore-64"
-#define STR_OS_WIN_2008_ENTERPRISE_X64 "winServer2008Enterprise-64"
-#define STR_OS_WIN_2008_ENTERPRISE_CORE_X64 "winServer2008EnterpriseCore-64"
+#define STR_OS_WIN_VISTA_ULTIMATE_X64 "winVistaUltimate-64"
+#define STR_OS_WIN_VISTA_HOME_PREMIUM_X64 "winVistaHomePremium-64"
+#define STR_OS_WIN_VISTA_HOME_BASIC_X64 "winVistaHomeBasic-64"
+#define STR_OS_WIN_VISTA_ENTERPRISE_X64 "winVistaEnterprise-64"
+#define STR_OS_WIN_VISTA_BUSINESS_X64 "winVistaBusiness-64"
+#define STR_OS_WIN_VISTA_STARTER_X64 "winVistaStarter-64"
+#define STR_OS_WIN_2008_CLUSTER_X64 "winServer2008Cluster-64"
+#define STR_OS_WIN_2008_DATACENTER_X64 "winServer2008Datacenter-64"
+#define STR_OS_WIN_2008_DATACENTER_CORE_X64 "winServer2008DatacenterCore-64"
+#define STR_OS_WIN_2008_ENTERPRISE_X64 "winServer2008Enterprise-64"
+#define STR_OS_WIN_2008_ENTERPRISE_CORE_X64 "winServer2008EnterpriseCore-64"
#define STR_OS_WIN_2008_ENTERPRISE_ITANIUM_X64 "winServer2008EnterpriseItanium-64"
#define STR_OS_WIN_2008_MEDIUM_MANAGEMENT_X64 "winServer2008MediumManagement-64"
-#define STR_OS_WIN_2008_MEDIUM_MESSAGING_X64 "winServer2008MediumMessaging-64"
-#define STR_OS_WIN_2008_MEDIUM_SECURITY_X64 "winServer2008MediumSecurity-64"
+#define STR_OS_WIN_2008_MEDIUM_MESSAGING_X64 "winServer2008MediumMessaging-64"
+#define STR_OS_WIN_2008_MEDIUM_SECURITY_X64 "winServer2008MediumSecurity-64"
#define STR_OS_WIN_2008_SERVER_FOR_SMALLBUSINESS_X64 "winServer2008ForSmallBusiness-64"
-#define STR_OS_WIN_2008_SMALL_BUSINESS_X64 "winServer2008SmallBusiness-64"
+#define STR_OS_WIN_2008_SMALL_BUSINESS_X64 "winServer2008SmallBusiness-64"
#define STR_OS_WIN_2008_SMALL_BUSINESS_PREMIUM_X64 "winServer2008SmallBusinessPremium-64"
-#define STR_OS_WIN_2008_STANDARD_X64 "winServer2008Standard-64"
-#define STR_OS_WIN_2008_STANDARD_CORE_X64 "winServer2008StandardCore-64"
+#define STR_OS_WIN_2008_STANDARD_X64 "winServer2008Standard-64"
+#define STR_OS_WIN_2008_STANDARD_CORE_X64 "winServer2008StandardCore-64"
#define STR_OS_WIN_2008_STORAGE_ENTERPRISE_X64 "winServer2008StorageEnterprise-64"
-#define STR_OS_WIN_2008_STORAGE_EXPRESS_X64 "winServer2008StorageExpress-64"
-#define STR_OS_WIN_2008_STORAGE_STANDARD_X64 "winServer2008StorageStandard-64"
+#define STR_OS_WIN_2008_STORAGE_EXPRESS_X64 "winServer2008StorageExpress-64"
+#define STR_OS_WIN_2008_STORAGE_STANDARD_X64 "winServer2008StorageStandard-64"
#define STR_OS_WIN_2008_STORAGE_WORKGROUP_X64 "winServer2008StorageWorkgroup-64"
-#define STR_OS_WIN_2008_WEB_SERVER_X64 "winServer2008Web-64"
+#define STR_OS_WIN_2008_WEB_SERVER_X64 "winServer2008Web-64"
/* Windows 7 */
VixError Vix_TranslateCOMError(HRESULT comError);
#endif
+#endif // VIX_HIDE_BORA_DEPENDENCIES
+
/*
* This defines additional error codes.
* The public error codes are defined in vix.h
/* WARNING. Do not exceed 2**16 */
};
-#endif // VIX_HIDE_BORA_DEPENDENCIES
-
-
-
/*
*-----------------------------------------------------------------------------
*
*/
Bool
-Base64_Encode(uint8 const *src, // IN
- size_t srcSize, // IN
- char *dst, // OUT
- size_t dstMax, // IN: max result length, including NUL byte
- size_t *dstSize) // OUT: result length, may be NULL
+Base64_Encode(uint8 const *src, // IN:
+ size_t srcSize, // IN:
+ char *dst, // OUT:
+ size_t dstMax, // IN: max result length, including NUL byte
+ size_t *dstSize) // OUT: result length, may be NULL
{
char *dst0 = dst;
+
ASSERT(src || srcSize == 0);
ASSERT(dst);
- if (4 * ((srcSize+2) / 3) >= dstMax) {
+ if (4 * ((srcSize + 2) / 3) >= dstMax) {
if (dstSize) {
*dstSize = 0;
}
+
return FALSE;
}
if (dstSize) {
*dstSize = dst - dst0;
}
+
return TRUE;
}
+
#ifdef __I_WANT_TO_TEST_THIS__
main()
{
}
#endif
+
/*
*----------------------------------------------------------------------------
*
*/
Bool
-Base64_Decode(char const *in, // IN
- uint8 *out, // OUT
- size_t outSize, // IN
- size_t *dataLength) // OUT
+Base64_Decode(char const *in, // IN:
+ uint8 *out, // OUT:
+ size_t outSize, // IN:
+ size_t *dataLength) // OUT:
{
uint32 b = 0;
int n = 0;
*/
Bool
-Base64_ValidEncoding(char const *src, // IN
- size_t srcLength) // IN
+Base64_ValidEncoding(char const *src, // IN:
+ size_t srcLength) // IN:
{
size_t i;
+
ASSERT(src);
for (i = 0; i < srcLength; i++) {
uint8 c = src[i]; /* MSVC CRT will die on negative arguments to is* */
return FALSE;
}
}
+
return TRUE;
}
*/
size_t
-Base64_EncodedLength(uint8 const *src, size_t srcLength) {
+Base64_EncodedLength(uint8 const *src, // IN:
+ size_t srcLength) // IN:
+{
return ((srcLength + 2) / 3 * 4) + 1;
}
*/
size_t
-Base64_DecodedLength(char const *src, size_t srcLength) {
+Base64_DecodedLength(char const *src, // IN:
+ size_t srcLength) // IN:
+{
size_t length;
ASSERT(src);
# include <str.h>
#else
# if defined(__linux__)
-# define _GNU_SOURCE // see nl_langinfo_l explanation below
+# define _GNU_SOURCE // see nl_langinfo_l explanation below
# endif
# include <string.h>
# include <stdlib.h>
*
* Results:
* 0 on failure.
- * Length of sequence and Unicode character in *uchar on success.
+ * Length of sequence and Unicode character in *uchar on success.
*
* Side effects:
* None.
*/
static INLINE int
-CodeSetOldGetUtf8(const char *string, // IN: string
- const char *end, // IN: end of string
- uint32 *uchar) // OUT: the Unicode character
+CodeSetOldGetUtf8(const char *string, // IN: string
+ const char *end, // IN: end of string
+ uint32 *uchar) // OUT: the Unicode character
{
uint8 *p = (uint8 *) string;
uint8 *e;
while (++p < e) {
if ((*p & 0xc0) != 0x80) {
- // bad trailing byte
- return 0;
+ // bad trailing byte
+ return 0;
}
c <<= 6;
c += *p - 0x80;
if (uchar != NULL) {
*uchar = c;
}
+
return len;
}
*/
static Bool
-CodeSetOldDuplicateStr(const char *bufIn, // IN: Input string
- size_t sizeIn, // IN: Input string length
- char **bufOut, // OUT: "Converted" string
- size_t *sizeOut) // OUT: Length of string
+CodeSetOldDuplicateStr(const char *bufIn, // IN: Input string
+ size_t sizeIn, // IN: Input string length
+ char **bufOut, // OUT: "Converted" string
+ size_t *sizeOut) // OUT: Length of string
{
char *myBufOut;
if (sizeOut) {
*sizeOut = sizeIn;
}
+
return TRUE;
}
#endif
*/
static Bool
-CodeSetOldDynBufFinalize(Bool ok, // IN: Earlier steps succeeded
- DynBuf *db, // IN: Buffer with converted string
- char **bufOut, // OUT: Converted string
+CodeSetOldDynBufFinalize(Bool ok, // IN: Earlier steps succeeded
+ DynBuf *db, // IN: Buffer with converted string
+ char **bufOut, // OUT: Converted string
size_t *sizeOut) // OUT: Length of string in bytes
{
if (!ok || !DynBuf_Append(db, &nul, sizeof nul) || !DynBuf_Trim(db)) {
DynBuf_Destroy(db);
+
return FALSE;
}
if (sizeOut) {
*sizeOut = DynBuf_GetSize(db) - sizeof nul;
}
+
return TRUE;
}
*/
static Bool
-CodeSetOldUtf8ToUtf16leDb(const char *bufIn, // IN
- size_t sizeIn, // IN
- DynBuf *db) // IN
+CodeSetOldUtf8ToUtf16leDb(const char *bufIn, // IN:
+ size_t sizeIn, // IN:
+ DynBuf *db) // IN:
{
const char *bufEnd = bufIn + sizeIn;
size_t currentSize;
int n = CodeSetOldGetUtf8(bufIn, bufEnd, &uniChar);
if (n <= 0) {
- return FALSE;
+ return FALSE;
}
bufIn += n;
}
/* All went fine, update buffer size. */
DynBuf_SetSize(db, currentSize);
+
return TRUE;
}
*/
static Bool
-CodeSetOldGenericToUtf16leDb(UINT codeIn, // IN
- char const *bufIn, // IN
- size_t sizeIn, // IN
- DynBuf *db) // IN
+CodeSetOldGenericToUtf16leDb(UINT codeIn, // IN:
+ char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ DynBuf *db) // IN:
{
/*
* Undocumented: calling MultiByteToWideChar() with sizeIn == 0 returns 0
* with GetLastError() set to ERROR_INVALID_PARAMETER. Isn't this API
* robust? --hpreg
*/
+
if (sizeIn) {
size_t initialSize;
DWORD flags = GetInvalidCharsFlag();
* So MB_ERR_INVALID_CHARS added, otherwise can
* lead to security issues see bug 154114.
*/
- result = MultiByteToWideChar(codeIn,
- flags,
- bufIn,
- sizeIn,
+ result = MultiByteToWideChar(codeIn, flags, bufIn, sizeIn,
(wchar_t *)((char *)DynBuf_Get(db) + initialSize),
(DynBuf_GetAllocatedSize(db) - initialSize) /
sizeof(wchar_t));
* yields the same string size that was passed in.
* If not, then dropped characters so fail.
*/
+
if (!invalidCharsCheck) {
resultReverse = WideCharToMultiByte(codeIn, 0,
(wchar_t *)((char *)DynBuf_Get(db) + initialSize),
*/
static Bool
-CodeSetOldUtf16leToGeneric(char const *bufIn, // IN
- size_t sizeIn, // IN
- UINT codeOut, // IN
- DynBuf *db) // IN
+CodeSetOldUtf16leToGeneric(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ UINT codeOut, // IN:
+ DynBuf *db) // IN:
{
/*
* Undocumented: calling WideCharToMultiByte() with sizeIn == 0 returns 0
* with GetLastError() set to ERROR_INVALID_PARAMETER. Isn't this API
* robust? --hpreg
*/
+
if (sizeIn) {
size_t initialSize;
Bool canHaveSubstitution = codeOut != CP_UTF8 && codeOut != CP_UTF7;
* Undocumented: if the input buffer is not NUL-terminated, the output
* buffer will not be NUL-terminated either --hpreg
*/
+
return TRUE;
}
*/
static Bool
-CodeSetOldUtf16leToCurrent(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOldUtf16leToCurrent(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
/* XXX We should probably use CP_THREAD_ACP on Windows 2000/XP --hpreg */
ok = CodeSetOldUtf16leToGeneric(bufIn, sizeIn, CP_ACP, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf8Normalize(char const *bufIn, // IN
- size_t sizeIn, // IN
- Bool precomposed, // IN
- DynBuf *db) // OUT
+CodeSetOld_Utf8Normalize(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ Bool precomposed, // IN:
+ DynBuf *db) // OUT:
{
Bool ok = FALSE;
CFStringRef str = NULL;
CFIndex len, lenMut;
size_t initialSize = DynBuf_GetSize(db);
- str = CFStringCreateWithCString(NULL,
- bufIn,
- kCFStringEncodingUTF8);
+ str = CFStringCreateWithCString(NULL, bufIn, kCFStringEncodingUTF8);
if (str == NULL) {
goto exit;
}
/*
* Normalize the string, Form C - precomposed or D, not.
*/
- CFStringNormalize(mutStr,
- (precomposed ? kCFStringNormalizationFormC :
- kCFStringNormalizationFormD));
+
+ CFStringNormalize(mutStr, (precomposed ? kCFStringNormalizationFormC :
+ kCFStringNormalizationFormD));
/*
* Get the number (in terms of UTF-16 code units)
* of characters in a string.
*/
+
lenMut = CFStringGetLength(mutStr);
/*
* specified length (in UTF-16 code units) will take up
* if encoded in a specified encoding.
*/
- len = CFStringGetMaximumSizeForEncoding(lenMut,
- kCFStringEncodingUTF8);
+
+ len = CFStringGetMaximumSizeForEncoding(lenMut, kCFStringEncodingUTF8);
if (len + 1 > initialSize) {
if (DynBuf_Enlarge(db, len + 1 - initialSize) == FALSE) {
ok = FALSE;
* Copies the character contents of a string to a local C
* string buffer after converting the characters to UTF-8.
*/
- ok = CFStringGetCString(mutStr,
- (char *)DynBuf_Get(db),
- len + 1,
- kCFStringEncodingUTF8);
+
+ ok = CFStringGetCString(mutStr, (char *)DynBuf_Get(db),
+ len + 1, kCFStringEncodingUTF8);
if (ok) {
/* Remove the NUL terminator that the above includes. */
DynBuf_SetSize(db, strlen((char *)DynBuf_Get(db)));
#elif defined(sun)
char *locale = setlocale(LC_CTYPE, NULL);
+
if (!setlocale(LC_CTYPE, "")) {
/*
* If the machine is configured incorrectly (no current locale),
if (!strcmp(gFilenameEncoding, "@locale")) {
free(gFilenameEncoding);
cachedCodeset = CodeSetOldGetCodeSetFromLocale();
+
return cachedCodeset;
}
cachedCodeset = gFilenameEncoding;
+
return cachedCodeset;
}
if (getenv("G_BROKEN_FILENAMES")) {
cachedCodeset = CodeSetOldGetCodeSetFromLocale();
+
return cachedCodeset;
}
*/
static INLINE_SINGLE_CALLER iconv_t
-CodeSetOldIconvOpen(const char *codeIn, // IN
- const char *codeOut, // IN
- unsigned int flags) // IN
+CodeSetOldIconvOpen(const char *codeIn, // IN:
+ const char *codeOut, // IN:
+ unsigned int flags) // IN:
{
#ifdef __linux__
if (flags) {
* only use TRANSLIT and bail out after the first non-translitible
* character.
*/
+
codeOutExt = Str_Asprintf(NULL, "%s//TRANSLIT", codeOut);
if (codeOutExt) {
iconv_t cd = iconv_open(codeOutExt, codeIn);
}
}
#endif
+
return iconv_open(codeOut, codeIn);
}
*/
Bool
-CodeSetOld_GenericToGenericDb(char const *codeIn, // IN
- char const *bufIn, // IN
- size_t sizeIn, // IN
- char const *codeOut, // IN
- unsigned int flags, // IN
- DynBuf *db) // IN/OUT
+CodeSetOld_GenericToGenericDb(char const *codeIn, // IN:
+ char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char const *codeOut, // IN:
+ unsigned int flags, // IN:
+ DynBuf *db) // IN/OUT:
{
iconv_t cd;
* can be sure that at least one character is
* converted each call to iconv().
*/
+
size = DynBuf_GetSize(db);
if (DynBuf_Enlarge(db, size + 4) == FALSE) {
goto error;
* in the standard. However, the implementation of iconv doesn't
* change bufIn so a simple cast is safe. --plangdale
*/
+
#if defined(GLIBC_VERSION_22)
status = iconv(cd, (char **)&bufIn, &sizeIn, &out, &outLeft);
#else
* characters were transliterated) or even -1 with errno set to
* EILSEQ (if some characters were ignored).
*/
+
if (sizeIn == 0) {
break;
}
if (status != -1) {
goto error;
}
- /*
- * Some libc implementations (one on ESX3, and one on Ganesh's
- * box) silently ignore //IGNORE. So if caller asked for
- * getting conversion done at any cost, just return success
- * even if failure occured. User will get truncated
- * message, but that's our best. We have no idea whether
- * incoming encoding is 8bit, 16bit, or what, so we cannot
- * skip over characters in input stream and recover :-(
- */
- if ((flags & CSGTG_IGNORE) && errno == EILSEQ) {
- break;
- }
+
+ /*
+ * Some libc implementations (one on ESX3, and one on Ganesh's
+ * box) silently ignore //IGNORE. So if caller asked for
+ * getting conversion done at any cost, just return success
+ * even if failure occured. User will get truncated
+ * message, but that's our best. We have no idea whether
+ * incoming encoding is 8bit, 16bit, or what, so we cannot
+ * skip over characters in input stream and recover :-(
+ */
+
+ if ((flags & CSGTG_IGNORE) && errno == EILSEQ) {
+ break;
+ }
if (errno != E2BIG) {
goto error;
}
*/
Bool
-CodeSetOld_GenericToGenericDb(char const *codeIn, // IN
- char const *bufIn, // IN
- size_t sizeIn, // IN
- char const *codeOut, // IN
- unsigned int flags, // IN
- DynBuf *db) // IN/OUT
+CodeSetOld_GenericToGenericDb(char const *codeIn, // IN:
+ char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char const *codeOut, // IN:
+ unsigned int flags, // IN:
+ DynBuf *db) // IN/OUT:
{
Bool ret = FALSE;
StringEncoding encIn = Unicode_EncodingNameToEnum(codeIn);
goto exit;
}
} else if (STRING_ENCODING_US_ASCII == encOut) {
- if (!CodeSetOld_Utf8ToAsciiDb(bufIn, sizeIn, flags, db)) {
- goto exit;
- }
+ if (!CodeSetOld_Utf8ToAsciiDb(bufIn, sizeIn, flags, db)) {
+ goto exit;
+ }
} else {
goto exit;
}
}
} else if (STRING_ENCODING_US_ASCII == encIn) {
if (STRING_ENCODING_UTF8 == encOut) {
- if (!CodeSetOld_AsciiToUtf8Db(bufIn, sizeIn, flags, db)) {
- goto exit;
- }
+ if (!CodeSetOld_AsciiToUtf8Db(bufIn, sizeIn, flags, db)) {
+ goto exit;
+ }
} else {
goto exit;
}
if (bufOut != NULL) {
if (DynBuf_GetSize(db) == 0) {
- DynBuf_Attach(db, sizeOut, bufOut);
- bufOut = NULL;
+ DynBuf_Attach(db, sizeOut, bufOut);
+ bufOut = NULL;
} else {
- if (!DynBuf_Append(db, bufOut, sizeOut)) {
- goto exit;
- }
+ if (!DynBuf_Append(db, bufOut, sizeOut)) {
+ goto exit;
+ }
}
}
exit:
free(bufOut);
+
return ret;
}
*/
Bool
-CodeSetOld_GenericToGeneric(const char *codeIn, // IN
- const char *bufIn, // IN
- size_t sizeIn, // IN
- const char *codeOut, // IN
- unsigned int flags, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_GenericToGeneric(const char *codeIn, // IN:
+ const char *bufIn, // IN:
+ size_t sizeIn, // IN:
+ const char *codeOut, // IN:
+ unsigned int flags, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_GenericToGenericDb(codeIn, bufIn, sizeIn,
- codeOut, flags, &db);
+ codeOut, flags, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf8ToCurrent(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf8ToCurrent(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(CURRENT_IS_UTF8)
return CodeSetOldDuplicateStr(bufIn, sizeIn, bufOut, sizeOut);
ok = CodeSetOld_GenericToGenericDb("UTF-8", bufIn, sizeIn,
CodeSetOld_GetCurrentCodeSet(),
0, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#elif defined(_WIN32)
char *buf;
*/
Bool
-CodeSetOld_CurrentToUtf8(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_CurrentToUtf8(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(CURRENT_IS_UTF8)
return CodeSetOldDuplicateStr(bufIn, sizeIn, bufOut, sizeOut);
DynBuf_Init(&db);
ok = CodeSetOld_GenericToGenericDb(CodeSetOld_GetCurrentCodeSet(), bufIn,
sizeIn, "UTF-8", 0, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#elif defined(_WIN32)
char *buf;
status = CodeSetOld_Utf16leToUtf8(buf, size, bufOut, sizeOut);
free(buf);
+
return status;
#else
#error
*/
Bool
-CodeSetOld_Utf16leToUtf8Db(char const *bufIn, // IN
- size_t sizeIn, // IN
- DynBuf *db) // IN
+CodeSetOld_Utf16leToUtf8Db(char const *bufIn, // IN
+ size_t sizeIn, // IN
+ DynBuf *db) // IN
{
const uint16 *utf16In;
size_t numCodeUnits;
uint8 *dbBytes;
size_t size;
- if ( utf16In[codeUnitIndex] < 0xD800
- || utf16In[codeUnitIndex] > 0xDFFF) {
+ if (utf16In[codeUnitIndex] < 0xD800 ||
+ utf16In[codeUnitIndex] > 0xDFFF) {
// Non-surrogate UTF-16 code units directly represent a code point.
codePoint = utf16In[codeUnitIndex];
} else {
static const uint32 SURROGATE_OFFSET =
- (0xD800 << 10UL) + 0xDC00 - 0x10000;
+ (0xD800 << 10UL) + 0xDC00 - 0x10000;
uint16 surrogateLead = utf16In[codeUnitIndex];
uint16 surrogateTrail;
surrogateTrail = utf16In[codeUnitIndex];
// Ensure we have a lead surrogate followed by a trail surrogate.
- if ( surrogateLead > 0xDBFF
- || surrogateTrail < 0xDC00
- || surrogateTrail > 0xDFFF) {
+ if (surrogateLead > 0xDBFF ||
+ surrogateTrail < 0xDC00 ||
+ surrogateTrail > 0xDFFF) {
return FALSE;
}
* -> result [0x10000, 0x10FFFF]
*/
codePoint = ((uint32)surrogateLead << 10UL) +
- (uint32)surrogateTrail - SURROGATE_OFFSET;
+ (uint32)surrogateTrail - SURROGATE_OFFSET;
ASSERT(codePoint >= 0x10000 && codePoint <= 0x10FFFF);
}
size = DynBuf_GetSize(db);
// We'll need at most 4 more bytes for this code point.
- if ( DynBuf_GetAllocatedSize(db) < size + 4
- && DynBuf_Enlarge(db, size + 4) == FALSE) {
+ if (DynBuf_GetAllocatedSize(db) < size + 4 &&
+ DynBuf_Enlarge(db, size + 4) == FALSE) {
return FALSE;
}
* See the surrogate pair handling block above for the math
* that ensures we're in the range [0x10000, 0x10FFFF] here.
*/
+
ASSERT(codePoint <= 0x10FFFF);
dbBytes[0] = 0xF0 | (codePoint >> 18);
dbBytes[1] = 0x80 | ((codePoint >> 12) & 0x3F);
*/
Bool
-CodeSetOld_Utf16leToUtf8(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf16leToUtf8(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_Utf16leToUtf8Db(bufIn, sizeIn, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf8ToUtf16le(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf8ToUtf16le(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOldUtf8ToUtf16leDb(bufIn, sizeIn, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf8FormDToUtf8FormC(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf8FormDToUtf8FormC(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(__APPLE__)
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_Utf8Normalize(bufIn, sizeIn, TRUE, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#else
NOT_IMPLEMENTED();
*/
Bool
-CodeSetOld_Utf8FormCToUtf8FormD(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf8FormCToUtf8FormD(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(__APPLE__)
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_Utf8Normalize(bufIn, sizeIn, FALSE, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#else
NOT_IMPLEMENTED();
*/
Bool
-CodeSetOld_CurrentToUtf16le(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_CurrentToUtf16le(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
#else
#error
#endif
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf16leToCurrent(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf16leToCurrent(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(CURRENT_IS_UTF8)
return CodeSetOld_Utf16leToUtf8(bufIn, sizeIn, bufOut, sizeOut);
DynBuf_Init(&db);
ok = CodeSetOld_GenericToGenericDb("UTF-16LE", bufIn, sizeIn,
CodeSetOld_GetCurrentCodeSet(), 0, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#elif defined(_WIN32)
return CodeSetOldUtf16leToCurrent(bufIn, sizeIn, bufOut, sizeOut);
*/
Bool
-CodeSetOld_Utf16beToCurrent(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf16beToCurrent(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
#if defined(CURRENT_IS_UTF8)
Bool status;
swab(bufIn, temp, sizeIn);
status = CodeSetOld_Utf16leToUtf8(temp, sizeIn, bufOut, sizeOut);
free(temp);
+
return status;
#elif defined(USE_ICONV)
DynBuf db;
DynBuf_Init(&db);
ok = CodeSetOld_GenericToGenericDb("UTF-16BE", bufIn, sizeIn,
CodeSetOld_GetCurrentCodeSet(), 0, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
#elif defined(_WIN32)
char c;
error:
free(bufIn_dup);
+
return status;
#else
#error
*/
Bool
-CodeSetOld_Utf16beToUtf8(char const *bufIn, // IN
- size_t sizeIn, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf16beToUtf8(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_Utf16beToUtf8Db(bufIn, sizeIn, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf16beToUtf8Db(char const *bufIn, // IN
- size_t sizeIn, // IN
- DynBuf *db) // IN
+CodeSetOld_Utf16beToUtf8Db(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ DynBuf *db) // IN:
{
int i;
char *temp;
Bool ret = FALSE;
+
if ((temp = malloc(sizeIn)) == NULL) {
return ret;
}
ret = CodeSetOld_Utf16leToUtf8Db(temp, sizeIn, db);
free(temp);
+
return ret;
}
*/
Bool
-CodeSetOld_AsciiToUtf8(const char *bufIn, // IN
- size_t sizeIn, // IN
- unsigned int flags, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_AsciiToUtf8(const char *bufIn, // IN:
+ size_t sizeIn, // IN:
+ unsigned int flags, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_AsciiToUtf8Db(bufIn, sizeIn, flags, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_AsciiToUtf8Db(char const *bufIn, // IN
- size_t sizeIn, // IN
- unsigned int flags, // IN
- DynBuf *db) // OUT
+CodeSetOld_AsciiToUtf8Db(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ unsigned int flags, // IN:
+ DynBuf *db) // OUT:
{
size_t oldSize = DynBuf_GetSize(db);
size_t i;
for (i = 0; i < sizeIn; i++) {
if (UNLIKELY((unsigned char) bufIn[i] >= 0x80)) {
- if (flags == 0) {
- DynBuf_SetSize(db, oldSize);
- return FALSE;
- }
- DynBuf_Append(db, bufIn + last, i - last);
- if ((flags & CSGTG_TRANSLIT) != 0) {
- DynBuf_Append(db, "\xef\xbf\xbd", 3);
- }
- last = i + 1;
+ if (flags == 0) {
+ DynBuf_SetSize(db, oldSize);
+
+ return FALSE;
+ }
+ DynBuf_Append(db, bufIn + last, i - last);
+ if ((flags & CSGTG_TRANSLIT) != 0) {
+ DynBuf_Append(db, "\xef\xbf\xbd", 3);
+ }
+ last = i + 1;
}
}
DynBuf_Append(db, bufIn + last, i - last);
*/
Bool
-CodeSetOld_Utf8ToAscii(const char *bufIn, // IN
- size_t sizeIn, // IN
- unsigned int flags, // IN
- char **bufOut, // OUT
- size_t *sizeOut) // OUT
+CodeSetOld_Utf8ToAscii(const char *bufIn, // IN:
+ size_t sizeIn, // IN:
+ unsigned int flags, // IN:
+ char **bufOut, // OUT:
+ size_t *sizeOut) // OUT:
{
DynBuf db;
Bool ok;
DynBuf_Init(&db);
ok = CodeSetOld_Utf8ToAsciiDb(bufIn, sizeIn, flags, &db);
+
return CodeSetOldDynBufFinalize(ok, &db, bufOut, sizeOut);
}
*/
Bool
-CodeSetOld_Utf8ToAsciiDb(char const *bufIn, // IN
- size_t sizeIn, // IN
- unsigned int flags, // IN
- DynBuf *db) // OUT
+CodeSetOld_Utf8ToAsciiDb(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ unsigned int flags, // IN:
+ DynBuf *db) // OUT:
{
size_t oldSize = DynBuf_GetSize(db);
uint8 *p = (uint8 *) bufIn;
for (; p < end; p++) {
if (UNLIKELY(*p >= 0x80)) {
- int n;
-
- if (flags == 0) {
- DynBuf_SetSize(db, oldSize);
- return FALSE;
- }
- DynBuf_Append(db, last, p - last);
- if ((flags & CSGTG_TRANSLIT) != 0) {
- DynBuf_Append(db, "\x1a", 1);
- }
- if ((n = CodeSetOldGetUtf8((char *)p, (char *)end, NULL)) > 0) {
- p += n - 1;
- }
- last = p + 1;
+ int n;
+
+ if (flags == 0) {
+ DynBuf_SetSize(db, oldSize);
+
+ return FALSE;
+ }
+ DynBuf_Append(db, last, p - last);
+ if ((flags & CSGTG_TRANSLIT) != 0) {
+ DynBuf_Append(db, "\x1a", 1);
+ }
+ if ((n = CodeSetOldGetUtf8((char *)p, (char *)end, NULL)) > 0) {
+ p += n - 1;
+ }
+ last = p + 1;
}
}
DynBuf_Append(db, last, p - last);
*/
static Bool
-CodeSetOldIso88591ToUtf8Db(char const *bufIn, // IN
- size_t sizeIn, // IN
- unsigned int flags, // IN
- DynBuf *db) // OUT
+CodeSetOldIso88591ToUtf8Db(char const *bufIn, // IN:
+ size_t sizeIn, // IN:
+ unsigned int flags, // IN:
+ DynBuf *db) // OUT:
{
size_t i;
size_t last = 0;
for (i = 0; i < sizeIn; i++) {
unsigned int c = (unsigned char)bufIn[i];
+
if (UNLIKELY(c >= 0x80)) {
unsigned char buf[2];
buf[0] = 0xC0 | (c >> 6);
buf[1] = 0x80 | (c & 0x3F);
- DynBuf_Append(db, bufIn + last, i - last);
+ DynBuf_Append(db, bufIn + last, i - last);
DynBuf_Append(db, buf, sizeof buf);
- last = i + 1;
+ last = i + 1;
}
}
DynBuf_Append(db, bufIn + last, i - last);
+
return TRUE;
}
#endif
* If GetVersionEx failed, we are running something earlier than NT4+SP6,
* thus we cannot use MB_ERR_INVALID_CHARS
*/
+
retval = 0;
bFirstCall = FALSE;
+
return retval;
}
}
bFirstCall = FALSE;
+
return retval;
}
#endif
*/
Bool
-CodeSetOld_IsEncodingSupported(const char *name) // IN
+CodeSetOld_IsEncodingSupported(const char *name) // IN:
{
ASSERT(name);
+
return (STRING_ENCODING_UNKNOWN != Unicode_EncodingNameToEnum(name));
}
DynBuf_Init(&db);
ok = CodeSetOld_GenericToGenericDb(code, buf, size, "UTF-8",
- CSGTG_NORMAL, &db);
+ CSGTG_NORMAL, &db);
DynBuf_Destroy(&db);
+
return ok;
}
*/
Bool
-CodeSetOld_Init(UNUSED_PARAM(const char *dataDir))
+CodeSetOld_Init(UNUSED_PARAM(const char *dataDir)) // IN:
{
return TRUE;
}
* decimal number. If the input is not an hexadecimal digit character, the
* output is -1 --hpreg
*/
+
static int const Hex2Dec[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
* Table to use to quickly convert a decimal number into an ASCII hexadecimal
* digit character --hpreg
*/
+
static char const Dec2Hex[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
/* We must escape that byte --hpreg */
escSeq[0] = Dec2Hex[ubyte >> 4];
- escSeq[1] = Dec2Hex[ubyte & 0xF];
- if ( DynBuf_Append(&b, &buf[startUnescaped],
- index - startUnescaped) == FALSE
- || DynBuf_Append(&b, escStr, escStrLen) == FALSE
- || DynBuf_Append(&b, escSeq, sizeof escSeq) == FALSE) {
+ escSeq[1] = Dec2Hex[ubyte & 0xF];
+ if (DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ DynBuf_Append(&b, escStr, escStrLen) == FALSE ||
+ DynBuf_Append(&b, escSeq, sizeof escSeq) == FALSE) {
goto nem;
}
startUnescaped = index + 1;
}
}
- if ( /* Last unescaped chunk (if any) --hpreg */
- DynBuf_Append(&b, &buf[startUnescaped],
- index - startUnescaped) == FALSE
- /* NUL terminator --hpreg */
- || DynBuf_Append(&b, "", 1) == FALSE
- || DynBuf_Trim(&b) == FALSE) {
+ if (/* Last unescaped chunk (if any) --hpreg */
+ DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ /* NUL terminator --hpreg */
+ DynBuf_Append(&b, "", 1) == FALSE ||
+ DynBuf_Trim(&b) == FALSE) {
goto nem;
}
char escaped;
escaped = h << 4 | l;
- if ( DynBuf_Append(&b, &buf[startUnescaped],
- index - 2 - startUnescaped) == FALSE
- || DynBuf_Append(&b, &escaped, 1) == FALSE) {
+ if (DynBuf_Append(&b, &buf[startUnescaped],
+ index - 2 - startUnescaped) == FALSE ||
+ DynBuf_Append(&b, &escaped, 1) == FALSE) {
goto nem;
}
startUnescaped = index + 1;
}
}
- if ( /* Last unescaped chunk (if any) --hpreg */
- DynBuf_Append(&b, &buf[startUnescaped],
- index - startUnescaped) == FALSE
- /* NUL terminator --hpreg */
- || DynBuf_Append(&b, "", 1) == FALSE
- || DynBuf_Trim(&b) == FALSE) {
+ if (/* Last unescaped chunk (if any) --hpreg */
+ DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ /* NUL terminator --hpreg */
+ DynBuf_Append(&b, "", 1) == FALSE ||
+ DynBuf_Trim(&b) == FALSE) {
goto nem;
}
* Identify all chunks in buf (\r\n being the chunk separator), and copy
* them into b --hpreg
*/
+
for (index = 0; index < sizeIn; index++) {
char byte;
state = 0;
if (byte == '\n') {
if (DynBuf_Append(&b, &buf[startUnescaped],
- index - 1 - startUnescaped) == FALSE) {
+ index - 1 - startUnescaped) == FALSE) {
goto nem;
}
startUnescaped = index;
}
}
- if ( /* Last unescaped chunk (if any) --hpreg */
- DynBuf_Append(&b, &buf[startUnescaped], index - startUnescaped)
- == FALSE
- /* NUL terminator --hpreg */
- || DynBuf_Append(&b, "", 1) == FALSE
- || DynBuf_Trim(&b) == FALSE) {
+ if (/* Last unescaped chunk (if any) --hpreg */
+ DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ /* NUL terminator --hpreg */
+ DynBuf_Append(&b, "", 1) == FALSE ||
+ DynBuf_Trim(&b) == FALSE) {
goto nem;
}
if (buf[index] == '\'') {
/* We must escape that byte --hpreg */
- if ( DynBuf_Append(&b, &buf[startUnescaped],
- index - startUnescaped) == FALSE
- || DynBuf_Append(&b, escSeq,
- sizeof(escSeq)) == FALSE) {
+ if (DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ DynBuf_Append(&b, escSeq, sizeof(escSeq)) == FALSE) {
goto nem;
}
startUnescaped = index;
}
}
- if ( /* Last unescaped chunk (if any) --hpreg */
- DynBuf_Append(&b, &buf[startUnescaped],
- index - startUnescaped) == FALSE
- || DynBuf_Append(&b, be, sizeof(be)) == FALSE
- /* NUL terminator --hpreg */
- || DynBuf_Append(&b, "", 1) == FALSE
- || DynBuf_Trim(&b) == FALSE) {
+ if (/* Last unescaped chunk (if any) --hpreg */
+ DynBuf_Append(&b, &buf[startUnescaped],
+ index - startUnescaped) == FALSE ||
+ DynBuf_Append(&b, be, sizeof(be)) == FALSE ||
+ /* NUL terminator --hpreg */
+ DynBuf_Append(&b, "", 1) == FALSE ||
+ DynBuf_Trim(&b) == FALSE) {
goto nem;
}
}
}
}
+
return NULL;
}
}
DynBuf_Append(&result, &nullbyte, sizeof('\0'));
+
return DynBuf_Get(&result);
}
switch (ht->keyType) {
case HASH_STRING_KEY: {
int c;
+
while ((c = (unsigned char) *s++)) {
h ^= c;
h = h << HASH_ROTATE | h >> (32 - HASH_ROTATE);
break;
case HASH_ISTRING_KEY: {
int c;
+
while ((c = tolower((unsigned char) *s++))) {
h ^= c;
h = h << HASH_ROTATE | h >> (32 - HASH_ROTATE);
{
int numBits = ht->numBits;
uint32 mask = MASK(numBits);
+
for (; h > mask; h = (h & mask) ^ (h >> numBits)) {
}
}
ASSERT(h < ht->numEntries);
+
return h;
}
for (i = 0; i < ht->numEntries; i++) {
HashTableEntry *entry;
+
while ((entry = ENTRY(ht->buckets[i])) != NULL) {
SETENTRY(ht->buckets[i], ENTRY(entry->next));
if (ht->copyKey) {
if (clientData) {
*clientData = Atomic_ReadPtr(&entry->clientData);
}
+
return TRUE;
}
ht->freeEntryFn(Atomic_ReadPtr(&entry->clientData));
}
free(entry);
+
return TRUE;
}
}
+
return FALSE;
}
#ifndef NO_ATOMIC_HASHTABLE
if (ht->atomic && ht->freeEntryFn) {
void *old = Atomic_ReadWritePtr(&entry->clientData, clientData);
+
ht->freeEntryFn(old);
} else
#endif
}
Atomic_WritePtr(&entry->clientData, clientData);
}
+
return TRUE;
}
oldEntry = HashTableLookup(ht, keyStr, hash);
if (oldEntry != NULL) {
- if(entry != NULL) {
+ if (entry != NULL) {
if (ht->copyKey) {
free((char *) entry->keyStr);
}
free(entry);
}
+
return oldEntry;
}
}
ht->numElements++;
+
return NULL;
}
/* fill array */
for (i = 0, j = 0; i < ht->numEntries; i++) {
HashTableEntry *entry;
+
for (entry = ENTRY(ht->buckets[i]);
entry != NULL;
entry = ENTRY(entry->next)) {
for (i = 0; i < ht->numEntries; i++) {
HashTableEntry *entry;
+
for (entry = ENTRY(ht->buckets[i]);
entry != NULL;
entry = ENTRY(entry->next)) {
int result = (*cb)(entry->keyStr, Atomic_ReadPtr(&entry->clientData),
clientData);
+
if (result) {
return result;
}
}
}
+
return 0;
}
#include <sys/time.h>
#include <sys/timeb.h>
#include <pwd.h>
+#include <pthread.h>
#include <sys/resource.h>
#if defined(sun)
#include <sys/systeminfo.h>
static LSBDistroInfo lsbFields[] = {
- {"DISTRIB_ID=", "DISTRIB_ID=%s"},
- {"DISTRIB_RELEASE=", "DISTRIB_RELEASE=%s"},
- {"DISTRIB_CODENAME=", "DISTRIB_CODENAME=%s"},
+ {"DISTRIB_ID=", "DISTRIB_ID=%s"},
+ {"DISTRIB_RELEASE=", "DISTRIB_RELEASE=%s"},
+ {"DISTRIB_CODENAME=", "DISTRIB_CODENAME=%s"},
{"DISTRIB_DESCRIPTION=", "DISTRIB_DESCRIPTION=%s"},
{NULL, NULL},
};
static DistroInfo distroArray[] = {
- {"RedHat", "/etc/redhat-release"},
- {"RedHat", "/etc/redhat_version"},
- {"Sun", "/etc/sun-release"},
- {"SuSE", "/etc/SuSE-release"},
- {"SuSE", "/etc/novell-release"},
- {"SuSE", "/etc/sles-release"},
- {"Debian", "/etc/debian_version"},
- {"Debian", "/etc/debian_release"},
- {"Mandrake", "/etc/mandrake-release"},
- {"Mandriva", "/etc/mandriva-release"},
- {"Mandrake", "/etc/mandrakelinux-release"},
- {"TurboLinux", "/etc/turbolinux-release"},
- {"Fedora Core", "/etc/fedora-release"},
- {"Gentoo", "/etc/gentoo-release"},
- {"Novell", "/etc/nld-release"},
- {"Ubuntu", "/etc/lsb-release"},
- {"Annvix", "/etc/annvix-release"},
- {"Arch", "/etc/arch-release"},
- {"Arklinux", "/etc/arklinux-release"},
- {"Aurox", "/etc/aurox-release"},
- {"BlackCat", "/etc/blackcat-release"},
- {"Cobalt", "/etc/cobalt-release"},
- {"Conectiva", "/etc/conectiva-release"},
- {"Immunix", "/etc/immunix-release"},
- {"Knoppix", "/etc/knoppix_version"},
+ {"RedHat", "/etc/redhat-release"},
+ {"RedHat", "/etc/redhat_version"},
+ {"Sun", "/etc/sun-release"},
+ {"SuSE", "/etc/SuSE-release"},
+ {"SuSE", "/etc/novell-release"},
+ {"SuSE", "/etc/sles-release"},
+ {"Debian", "/etc/debian_version"},
+ {"Debian", "/etc/debian_release"},
+ {"Mandrake", "/etc/mandrake-release"},
+ {"Mandriva", "/etc/mandriva-release"},
+ {"Mandrake", "/etc/mandrakelinux-release"},
+ {"TurboLinux", "/etc/turbolinux-release"},
+ {"Fedora Core", "/etc/fedora-release"},
+ {"Gentoo", "/etc/gentoo-release"},
+ {"Novell", "/etc/nld-release"},
+ {"Ubuntu", "/etc/lsb-release"},
+ {"Annvix", "/etc/annvix-release"},
+ {"Arch", "/etc/arch-release"},
+ {"Arklinux", "/etc/arklinux-release"},
+ {"Aurox", "/etc/aurox-release"},
+ {"BlackCat", "/etc/blackcat-release"},
+ {"Cobalt", "/etc/cobalt-release"},
+ {"Conectiva", "/etc/conectiva-release"},
+ {"Immunix", "/etc/immunix-release"},
+ {"Knoppix", "/etc/knoppix_version"},
{"Linux-From-Scratch", "/etc/lfs-release"},
- {"Linux-PPC", "/etc/linuxppc-release"},
- {"MkLinux", "/etc/mklinux-release"},
- {"PLD", "/etc/pld-release"},
- {"Slackware", "/etc/slackware-version"},
- {"Slackware", "/etc/slackware-release"},
- {"SMEServer", "/etc/e-smith-release"},
- {"Solaris", "/etc/release"},
- {"Tiny Sofa", "/etc/tinysofa-release"},
- {"UltraPenguin", "/etc/ultrapenguin-release"},
- {"UnitedLinux", "/etc/UnitedLinux-release"},
- {"VALinux", "/etc/va-release"},
- {"Yellow Dog", "/etc/yellowdog-release"},
+ {"Linux-PPC", "/etc/linuxppc-release"},
+ {"MkLinux", "/etc/mklinux-release"},
+ {"PLD", "/etc/pld-release"},
+ {"Slackware", "/etc/slackware-version"},
+ {"Slackware", "/etc/slackware-release"},
+ {"SMEServer", "/etc/e-smith-release"},
+ {"Solaris", "/etc/release"},
+ {"Tiny Sofa", "/etc/tinysofa-release"},
+ {"UltraPenguin", "/etc/ultrapenguin-release"},
+ {"UnitedLinux", "/etc/UnitedLinux-release"},
+ {"VALinux", "/etc/va-release"},
+ {"Yellow Dog", "/etc/yellowdog-release"},
{NULL, NULL},
};
# if !defined SOL10
/*
* XXX: This is bad. We define SI_ARCHITECTURE_K to what it is on Solaris
- * 10 so that we can use a single guestd build for Solaris 9 and 10. In the
+ * 10 so that we can use a single guestd build for Solaris 9 and 10. In the
* future we should have the Solaris 9 build just return 32 -- since it did
* not support 64-bit x86 -- and let the Solaris 10 headers define
* SI_ARCHITECTURE_K, then have the installer symlink to the correct binary.
char *dashPtr;
/*
- * FreeBSD releases report their version as "x.y-RELEASE". We'll be naive
- * look for the first dash, and use everything before it as the version
- * number.
+ * FreeBSD releases report their version as "x.y-RELEASE". We'll be
+ * naive look for the first dash, and use everything before it as the
+ * version number.
*/
dashPtr = Str_Strchr(buf.release, '-');
/*
* Solaris releases report their version as "x.y". For our supported
* releases it seems that x is always "5", and is ignored in favor of
- * y for the version number.
+ * "y" for the version number.
*/
if (sscanf(buf.release, "5.%2[0-9]", solarisRelease) == 1) {
if (HostType_OSIsVMK()) {
VMK_ReturnStatus status = VMKernel_HTEnabledCPU();
+
if (status != VMK_OK) {
return TRUE;
} else {
if (logical == 0 && cores == 0) {
logical = HostinfoReadProc("logical");
cores = HostinfoReadProc("cores");
+
if (logical <= 0 || cores <= 0) {
logical = cores = 0;
}
uint32
Hostinfo_NumCPUs(void)
{
-#if defined(__APPLE__)
+#if defined(sun)
+ static int count = 0;
+
+ if (count <= 0) {
+ count = sysconf(_SC_NPROCESSORS_CONF);
+ }
+
+ return count;
+#elif defined(__APPLE__)
uint32 out;
size_t outSize = sizeof out;
res = getloadavg(avg, 3);
if (res < 3) {
NOT_TESTED_ONCE();
+
return FALSE;
}
_exit(EXIT_SUCCESS);
}
} else {
- Err_SetErrno(err);
+ errno = err;
if (pidPath) {
Posix_Unlink(pidPath);
/*
* popen(3) incorrectly executes the shell with the identity of the calling
* process, ignoring a potential per-thread identity. And starting with
- * Mac OS 10.6 it is even worse: if there is a per-thread identity, popen(3)
- * removes it!
+ * Mac OS 10.6 it is even worse: if there is a per-thread identity,
+ * popen(3) removes it!
*
* So we run this code in a separate process which runs with the same
* identity as the current thread.
if (VmkSyscall_Init(FALSE, NULL, 0)) {
status = VMKernel_GetUptimeUS(&uptime);
+
if (status == VMK_OK) {
return uptime;
}
return Hostinfo_RawSystemTimerUS();
#else
- static Atomic_uint32 mutex = {0};
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
VmTimeType curTime;
VmTimeType newTime;
static VmTimeType lastTimeRead;
static VmTimeType lastTimeReset;
- /* Get and take lock. */
- while (Atomic_ReadWrite(&mutex, 1)); // Spinlock.
+ pthread_mutex_lock(&mutex); // use native mechanism, just like Windows
curTime = Hostinfo_RawSystemTimerUS();
lastTimeRead = newTime;
exit:
- /* Release lock. */
- Atomic_Write(&mutex, 0);
+ pthread_mutex_unlock(&mutex);
return newTime;
#endif
}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Hostinfo_GetModulePath --
+ *
+ * Retrieve the full path to the executable. Not supported under VMvisor.
+ *
+ * Note: If your process is running with elevated privileges
+ * (setuid/setgid), treat the path returned by this function as
+ * untrusted (for example, do not pass it to exec or open).
+ *
+ * This function returns a path that is under the control of the
+ * user. An attacker could manipulate the path returned by this
+ * function to elevate privileges.
+ *
+ * Results:
+ * On success: The allocated, NUL-terminated file path.
+ * Note: This path can be a symbolic or hard link; it's just one
+ * possible path to access the executable.
+ *
+ * On failure: NULL.
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Unicode
+Hostinfo_GetModulePath(uint32 priv) // IN:
+{
+ Unicode path;
+
+#if defined(__APPLE__)
+ uint32_t pathSize = FILE_MAXPATH;
+#else
+ uid_t uid = -1;
+#endif
+
+ if ((priv != HGMP_PRIVILEGE) && (priv != HGMP_NO_PRIVILEGE)) {
+ Warning("%s: invalid privilege parameter\n", __FUNCTION__);
+
+ return NULL;
+ }
+
+#if defined(__APPLE__)
+ path = Util_SafeMalloc(pathSize);
+ if (_NSGetExecutablePath(path, &pathSize)) {
+ Warning(LGPFX" %s: _NSGetExecutablePath failed.\n", __FUNCTION__);
+ free(path);
+
+ return NULL;
+ }
+
+#else
+#if defined(VMX86_SERVER)
+ if (HostType_OSIsVMK()) {
+ return NULL;
+ }
+#endif
+
+ // "/proc/self/exe" only exists on Linux 2.2+.
+ ASSERT(Hostinfo_OSVersion(0) >= 2 && Hostinfo_OSVersion(1) >= 2);
+
+ if (priv == HGMP_PRIVILEGE) {
+ uid = Id_BeginSuperUser();
+ }
+
+ path = Posix_ReadLink("/proc/self/exe");
+
+ if (priv == HGMP_PRIVILEGE) {
+ Id_EndSuperUser(uid);
+ }
+
+ if (path == NULL) {
+ Warning(LGPFX" %s: readlink failed: %s\n", __FUNCTION__,
+ strerror(errno));
+ }
+#endif
+
+ return path;
+}
while (numBytesLeft > 0) {
size_t c = MIN(numBytesLeft, iov->entries[i].iov_len);
void *buf;
+
ASSERT_NOT_IMPLEMENTED(i < iov->numEntries);
buf = iov->entries[i].iov_base;
ASSERT(buf && buf != LAZY_ALLOC_MAGIC);
return FALSE;
}
}
+
return TRUE;
}
if (regionV->numBytes > regionV->numSectors * sectorSize) {
int spillover;
- spillover = (int) (regionV->numBytes - regionV->numSectors * sectorSize);
+ spillover = (int) (regionV->numBytes -
+ regionV->numSectors * sectorSize);
ASSERT(spillover < curEntry->iov_len);
ASSERT(spillover > 0);
/*
- * Truncate the last overlapping entry and store the excess. After we
- * finish this region, we'll smash this last entry with its remainder
- * and just move on to the next region.
+ * Truncate the last overlapping entry and store the excess. After
+ * we finish this region, we'll smash this last entry with its
+ * remainder and just move on to the next region.
*/
+
regionV->numBytes -= spillover;
curEntry->iov_len -= spillover;
overlap->iov_len = spillover;
break;
} else if (regionV->numBytes == regionV->numSectors * sectorSize) {
/*
- * Clean finish. The last entry for this region will be handled with
- * no overlap, so increment past it for the start of the next
- * region's entries.
+ * Clean finish. The last entry for this region will be handled
+ * with no overlap, so increment past it for the start of the next
+ * region's entries.
*/
+
overlap->iov_len = 0;
curEntry++;
break;
/*
* The resulting iov cannot have more entries than the incoming one.
*/
+
v = Util_SafeMalloc(sizeof *v + origV->numEntries * sizeof(struct iovec));
iov = &v->iov;
memcpy(iov, origV, sizeof *iov);
/*
* Handle lazy allocation of backing store.
*/
+
if (origV->entries->iov_base == LAZY_ALLOC_MAGIC &&
origV->entries->iov_len == 0) {
v->iov.entries = v->e;
memcpy(v->iov.entries, iovIn->entries,
iovIn->numEntries * sizeof(struct iovec));
+
return &v->iov;
}
Log(LGPFX"%s:%d i %d (of %d), offsets: entry %"FMTSZ"u, iov %"FMTSZ"u "
"invalid iov offset\n",
__FILE__, __LINE__, i, numEntries, entryOffset, iovOffset);
+
return numEntries;
}
ASSERT(entryOffset < entryLen);
*entryOffsetp = entryOffset;
+
return i - 1;
}
Log(LGPFX"%s:%d iov [%"FMT64"u:%"FMT64"u] and [%"FMT64"u:%"FMT64"u] - "
"no overlap!\n", __FILE__, __LINE__, srcIov->startSector,
srcIov->numSectors, dstIov->startSector, dstIov->numSectors);
+
return 0;
}
entryLen = MIN(count, srcEntries[i].iov_len - srcEntryOffset);
copyLen = IOV_WriteBufToIovPlus(
- (uint8 *)(srcEntries[i].iov_base) + srcEntryOffset,
- entryLen,
- dstIov->entries,
- dstIov->numEntries,
- dstIovOffset);
+ (uint8 *)(srcEntries[i].iov_base) + srcEntryOffset,
+ entryLen, dstIov->entries,
+ dstIov->numEntries, dstIovOffset);
if (copyLen == 0) { /* finished */
break;
*/
static IP_ADAPTER_INFO *
-FindWindowsAdapter(IP_ADAPTER_INFO *head, // IN:
- char *pattern, // IN:
- Bool findPattern) // IN:
+FindWindowsAdapter(IP_ADAPTER_INFO *head, // IN:
+ char *pattern, // IN:
+ Bool findPattern) // IN:
{
IP_ADAPTER_INFO *adapterInfo;
IP_ADAPTER_INFO *adapterChoice = NULL;
static int
ObtainHardwareID(uint64 *hardwareID) // OUT:
{
- void *buf;
- DWORD status;
- HMODULE dllHandle;
+ void *buf;
+ DWORD status;
+ HMODULE dllHandle;
IP_ADAPTER_INFO *adapterList;
IP_ADAPTER_INFO *adapterChoice;
- DWORD (WINAPI *getAdaptersFn)(IP_ADAPTER_INFO *, ULONG *);
+ DWORD (WINAPI *getAdaptersFn)(IP_ADAPTER_INFO *, ULONG *);
- ULONG bufLen = 0;
+ ULONG bufLen = 0;
// Deal with BUG 21643
dllHandle = LoadLibrary(TEXT("icmp.dll"));
if (!dllHandle) {
Warning("%s Failed to load icmp.dll.\n", __FUNCTION__);
+
return EINVAL;
}
if (!dllHandle) {
Warning("%s Failed to load iphlpapi.dll.\n", __FUNCTION__);
+
return EINVAL;
}
if (!getAdaptersFn) {
FreeLibrary(dllHandle);
Warning("%s Failed to find GetAdaptersInfo.\n", __FUNCTION__);
+
return EINVAL;
}
default:
FreeLibrary(dllHandle);
- Warning("%s GetAdaptersInfo failure %d: %d.\n",
- __FUNCTION__, __LINE__, status);
+ Warning("%s GetAdaptersInfo failure %d: %d.\n", __FUNCTION__,
+ __LINE__, status);
+
return EINVAL;
- break;
}
buf = malloc(bufLen);
if (buf == NULL) {
FreeLibrary(dllHandle);
+
return ENOMEM;
}
if (status != NO_ERROR) {
// something is seriously wrong; worked before...
- Warning("%s GetAdaptersInfo failure %d: %d.\n",
- __FUNCTION__, __LINE__, status);
+ Warning("%s GetAdaptersInfo failure %d: %d.\n", __FUNCTION__,
+ __LINE__, status);
free(buf);
*/
static struct ifaddrs *
-CheckEthernet(struct ifaddrs *ifp, // IN:
- uint32 n) // IN:
+CheckEthernet(struct ifaddrs *ifp, // IN:
+ uint32 n) // IN:
{
struct ifaddrs *p;
- char name[8];
+ char name[8];
// Construct the interface name
Str_Sprintf(name, sizeof name, "en%u", n);
*/
static int
-ObtainHardwareID(uint64 *hardwareID) // OUT:
+ObtainHardwareID(uint64 *hardwareID) // OUT:
{
- uint32 i;
+ uint32 i;
struct ifaddrs *p;
struct ifaddrs *ifp;
*/
static int
-ObtainHardwareID(uint64 *hardwareID) // OUT:
+ObtainHardwareID(uint64 *hardwareID) // OUT:
{
uint32 i;
*/
static int
-ObtainHardwareID(uint64 *hardwareID) // OUT:
+ObtainHardwareID(uint64 *hardwareID) // OUT:
{
*hardwareID = gethostid();
*/
void
-Hostinfo_MachineID(uint32 *hostNameHash, // OUT:
- uint64 *hostHardwareID) // OUT:
+Hostinfo_MachineID(uint32 *hostNameHash, // OUT:
+ uint64 *hostHardwareID) // OUT:
{
static Bool fetchValues = TRUE;
static uint64 cachedHardwareID;
*/
int
-daemon(int nochdir, int noclose)
+daemon(int nochdir, // IN:
+ int noclose) // IN:
{
int fd;
close (fd);
}
}
+
return (0);
}
#endif
if (CryptGenRandom(csp, size, buffer) == FALSE) {
CryptReleaseContext(csp, 0);
Log("%s: CryptGenRandom failed %d\n", __FUNCTION__, GetLastError());
+
return FALSE;
}
if (CryptReleaseContext(csp, 0) == FALSE) {
Log("%s: CryptReleaseContext failed %d\n", __FUNCTION__,
GetLastError());
+
return FALSE;
}
#else
if (fd == -1) {
Log("%s: Failed to open random device: %d\n", __FUNCTION__, errno);
+
return FALSE;
}
close(fd);
Log("%s: Short read: %d\n", __FUNCTION__, error);
+
return FALSE;
}
if (bytesRead > 0) {
if (close(fd) == -1) {
Log("%s: Failed to close: %d\n", __FUNCTION__, errno);
+
return FALSE;
}
#endif
val = strtol(str, &ptr, 0);
*out = (int32)val;
+
/*
- * Input must be complete, no overflow, and value read must fit into 32 bits -
- * both signed and unsigned values are accepted.
+ * Input must be complete, no overflow, and value read must fit into
+ * 32 bits - both signed and unsigned values are accepted.
*/
- return *ptr == '\0' && errno != ERANGE && (val == (int32)val || val == (uint32)val);
+
+ return *ptr == '\0' && errno != ERANGE &&
+ (val == (int32)val || val == (uint32)val);
}
val = strtoul(str, &ptr, 0);
*out = (uint32)val;
+
/*
- * Input must be complete, no overflow, and value read must fit into 32 bits -
- * both signed and unsigned values are accepted.
+ * Input must be complete, no overflow, and value read must fit into 32
+ * bits - both signed and unsigned values are accepted.
*/
- return *ptr == '\0' && errno != ERANGE && (val == (uint32)val || val == (int32)val);
+
+ return *ptr == '\0' && errno != ERANGE &&
+ (val == (uint32)val || val == (int32)val);
}
*
* Converts a string containing a measure of disk capacity (such as
* "100MB" or "1.5k") into an unadorned and primitive quantity of sector
- * capacity. The comment before the switch statement describes the kinds of
- * disk capacity expressible.
+ * capacity. The comment before the switch statement describes the kinds
+ * of disk capacity expressible.
*
* Results:
* TRUE if conversion was successful, FALSE otherwise.
quantity *= (double)(1 << shift);
} else {
/*
- * No suffix, so multiply by the number of bytes per unit as specified by
- * the caller.
+ * No suffix, so multiply by the number of bytes per unit as specified
+ * by the caller.
*/
+
quantity *= (double)bytes;
}
/*
- * Convert from "number of bytes" to "number of sectors", rounding up or down
- * appropriately.
+ * Convert from "number of bytes" to "number of sectors", rounding up or
+ * down appropriately.
*
- * XXX: We should use DISKLIB_SECTOR_SIZE, but do we really want the disklib
- * header dependencies in this file?
+ * XXX: We should use DISKLIB_SECTOR_SIZE, but do we really want the
+ * disklib header dependencies in this file?
*
*/
*out = (SectorType)((quantity + 256) / 512);
+
return TRUE;
}
#endif
/*
* XXX TODO, BUG 199661:
* This is a direct copy of Msg_FormatSizeInBytes without localization.
- * These two functions should ideally share the basic functionality, and just
- * differ in the string localization
+ * These two functions should ideally share the basic functionality, and
+ * just differ in the string localization
*/
+
char const *fmt;
double sizeInSelectedUnit;
unsigned int precision;
bufLength -= len;
buf = next;
}
+
return longest;
}
{
ASSERT(s != NULL);
ASSERT(prefix != NULL);
+
return Str_Strncmp(s, prefix, strlen(prefix)) == 0;
}
{
ASSERT(s != NULL);
ASSERT(prefix != NULL);
+
return Str_Strncasecmp(s, prefix, strlen(prefix)) == 0;
}
* Detects if a string ends with another string.
*
* Results:
- * TRUE if string 'suffix' is found at the end of string 's', FALSE otherwise.
+ * TRUE if string 'suffix' is found at the end of string 's'
+ * FALSE otherwise.
*
* Side effects:
* None.
* Arbitrary lower-limit on buffer size allocation, to avoid doing
* many tiny enlarge operations.
*/
+
const size_t minAllocSize = 128;
while (1) {
* happens, believe it or not. See bug 253674.
*/
- ASSERT(i + size == allocSize || ((char*)DynBuf_Get(b))[i + size] == '\0');
+ ASSERT(i + size == allocSize ||
+ ((char *)DynBuf_Get(b))[i + size] == '\0');
+
DynBuf_SetSize(b, size + i);
break;
*/
Bool success = DynBuf_Enlarge(b, size + minAllocSize);
+
if (!success) {
return FALSE;
}
static void TimeUtilInit(TimeUtil_Date *d);
static Bool TimeUtilLoadDate(TimeUtil_Date *d, const char *date);
static Bool TimeUtilIsLeapYear(unsigned int year);
-static Bool TimeUtilIsValidDate(unsigned int year, unsigned int month, unsigned int day);
+static Bool TimeUtilIsValidDate(unsigned int year,
+ unsigned int month,
+ unsigned int day);
/*
* Function to guess Windows TZ Index and Name by using time offset in
* a lookup table
*/
-static int TimeUtilFindIndexAndNameByUTCOffset(int utcStdOffMins, const char **ptzName);
+
+static int TimeUtilFindIndexAndNameByUTCOffset(int utcStdOffMins,
+ const char **ptzName);
#if defined(_WIN32)
/*
* Reduce the string to a known and handled format: YYYYMMDD.
* Then, passed to internal function TimeUtilLoadDate.
*/
+
if (strlen(date) == 8) {
/* 'YYYYMMDD' */
return TimeUtilLoadDate(d, date);
* intentionally subtract an additional 2 days for each year
* and an additional 3 days.
*/
+
dayCount = dayCount + 3 + 2 * (dayCount / 365);
subYear = dayCount / 365;
* making sure on the valid range, without checking
* for leap year, etc.
*/
+
if ((estDay > 28) && (estMonth == 2)) {
estDay = 28;
}
* we also copy the time from the original argument in making
* sure that it does not play role in the comparison.
*/
+
estRes.hour = d->hour;
estRes.minute = d->minute;
estRes.second = d->second;
* guaranteed to be lower than the actual result. Otherwise,
* infinite loop will happen.
*/
+
ASSERT(TimeUtil_DateLowerThan(&estRes, d));
/*
* Done by moving up (moving forward) the estimated a day at a time
* until they are the correct one (i.e. estDate + arg #day = arg date)
*/
+
temp = estRes;
TimeUtil_DaysAdd(&temp, nr);
while (TimeUtil_DateLowerThan(&temp, d)) {
/* Get the current local date. */
TimeUtil_PopulateWithCurrent(TRUE, &c);
- /* Compute how many days we can add to the current date before reaching
- the given date */
+ /*
+ * Compute how many days we can add to the current date before reaching
+ * the given date
+ */
+
for (i = 0; i < MAX_DAYSLEFT + 1; i++) {
- if ( c.year > d->year
- || (c.year == d->year && c.month > d->month)
- || (c.year == d->year && c.month == d->month && c.day >= d->day)) {
+ if ((c.year > d->year) ||
+ (c.year == d->year && c.month > d->month) ||
+ (c.year == d->year && c.month == d->month && c.day >= d->day)) {
/* current date >= given date */
return i;
}
return NULL;
}
- if (!TimeUtil_UTCTimeToSystemTime((const __time64_t) utcTime, &systemTime)) {
+ if (!TimeUtil_UTCTimeToSystemTime((const __time64_t) utcTime,
+ &systemTime)) {
return NULL;
}
char *str;
str = Util_SafeStrdup(ctime((const time_t *) &utcTime));
str[strlen(str)-1] = '\0';
+
return str;
#endif // _WIN32
}
TimeUtil_UnixTimeToNtTime(struct timespec unixTime) // IN: Time in Unix format
{
return (VmTimeType)unixTime.tv_sec * 10000000 +
- unixTime.tv_nsec / 100 + UNIX_EPOCH;
+ unixTime.tv_nsec / 100 + UNIX_EPOCH;
}
#endif // _WIN32 && N_PLAT_NLM
* _localtime64 support years up through 3000. At least it says
* so. I'm getting garbage only after reaching year 4408.
*/
+
if (utcTime < 0 || utcTime > (60LL * 60 * 24 * 365 * (3000 - 1970))) {
return FALSE;
}
* Main reason for this test is to cut out negative values _localtime64
* likes to return for some inputs.
*/
+
if (atmYear < 1601 || atmYear > 30827 ||
atmMonth < 1 || atmMonth > 12 ||
atm->tm_wday < 0 || atm->tm_wday > 6 ||
* Offset is to standard (no need for DST adjustment).
* Negative is east of prime meridian.
*/
+
utcStdOffMins = 0 - timezone/60;
#else
/*
* Offset is to local (need to adjust for DST).
* Negative is west of prime meridian.
*/
+
utcStdOffMins = tim.tm_gmtoff/60;
if (tim.tm_isdst) {
utcStdOffMins -= 60;
/* If we don't have it yet, look up windowsCode. */
if (winTimeZoneIndex < 0) {
- winTimeZoneIndex = TimeUtilFindIndexAndNameByUTCOffset(utcStdOffMins, &tzNameByUTCOffset);
+ winTimeZoneIndex = TimeUtilFindIndexAndNameByUTCOffset(utcStdOffMins,
+ &tzNameByUTCOffset);
if (winTimeZoneIndex >= 0) {
*ptzName = Unicode_AllocWithUTF8(tzNameByUTCOffset);
}
/*
* Initialize the table
*/
+
if (TimeUtilIsLeapYear(year)) {
monthdays[2] = 29;
} else {
return FALSE;
}
- if (!TimeUtilIsValidDate((unsigned int) year, (unsigned int) month, (unsigned int) day)) {
+ if (!TimeUtilIsValidDate((unsigned int) year, (unsigned int) month,
+ (unsigned int) day)) {
return FALSE;
}
"Windows NT\\"
"CurrentVersion\\"
"Time Zones",
- 0,
- KEY_READ,
- &parentKey) != ERROR_SUCCESS) {
+ 0, KEY_READ, &parentKey) != ERROR_SUCCESS) {
/* Failed to open registry */
return (-1);
}
keyIndex = 0;
while (
timeZoneIndex < 0 &&
- Win32U_RegEnumKeyEx(parentKey,
- keyIndex,
- childKeyName,
- &childKeyLen,
+ Win32U_RegEnumKeyEx(parentKey, keyIndex, childKeyName, &childKeyLen,
0,0,0,0) == ERROR_SUCCESS) {
-
- char* std;
+ char *std;
DWORD stdSize;
/* Open child key */
}
/* Get size of "Std" value */
- if (Win32U_RegQueryValueEx(childKey,
- "Std", 0, 0,
+ if (Win32U_RegQueryValueEx(childKey, "Std", 0, 0,
NULL, &stdSize) == ERROR_SUCCESS) {
/* Get value of "Std" */
std = (char*) calloc(stdSize+1, sizeof(char));
if (std != NULL) {
- if (Win32U_RegQueryValueEx(childKey,
- "Std", 0, 0,
- (LPBYTE) std, &stdSize) == ERROR_SUCCESS) {
+ if (Win32U_RegQueryValueEx(childKey, "Std", 0, 0, (LPBYTE) std,
+ &stdSize) == ERROR_SUCCESS) {
/* Make sure there is at least one EOS */
std[stdSize] = '\0';
/* Is this the name we want? */
if (!strcmp(std, targetName)) {
-
/* yes: look up value of "Index" */
DWORD val = 0;
DWORD valSize = sizeof(val);
- if (Win32U_RegQueryValueEx(childKey,
- "Index", 0, 0,
+
+ if (Win32U_RegQueryValueEx(childKey, "Index", 0, 0,
(LPBYTE) &val,
&valSize) == ERROR_SUCCESS) {
timeZoneIndex = val;
*/
char *
-Util_GetCanonicalPath(const char *path) // IN
+Util_GetCanonicalPath(const char *path) // IN:
{
char *canonicalPath = NULL;
*/
char *
-Util_GetCanonicalPathForHash(const char *path) // IN: UTF-8
+Util_GetCanonicalPathForHash(const char *path) // IN: UTF-8
{
char *ret = NULL;
char *cpath = Util_GetCanonicalPath(path);
*/
static char*
-UtilGetLegacyEncodedString(const char *path) // IN: UTF-8
+UtilGetLegacyEncodedString(const char *path) // IN: UTF-8
{
char *ret = NULL;
char *cpath = Util_GetCanonicalPath(path);
*/
char *
-Util_CompatGetCanonicalPath(const char *path) // IN: UTF-8
+Util_CompatGetCanonicalPath(const char *path) // IN: UTF-8
{
char *cpath = Util_GetCanonicalPath(path);
char *ret = NULL;
* path case-sensitivity.
*
* XXX: This implementation makes assumptions about the host filesystem's
- * case sensitivity without any regard to what filesystem the provided
- * paths actually use. There are many ways to break this assumption,
- * on any of our supported host OSes! The return value of this function
- * cannot be trusted.
+ * case sensitivity without any regard to what filesystem the
+ * provided paths actually use. There are many ways to break this
+ * assumption, on any of our supported host OSes! The return value
+ * of this function cannot be trusted.
*
* Results:
* TRUE if the paths are equivalenr, FALSE if they are not.
*/
Bool
-Util_CanonicalPathsIdentical(const char *path1, // IN
- const char *path2) // IN
+Util_CanonicalPathsIdentical(const char *path1, // IN:
+ const char *path2) // IN:
{
ASSERT(path1);
ASSERT(path2);
+
#if defined(linux)
return (strcmp(path1, path2) == 0);
#elif defined(_WIN32)
*/
unsigned
-Util_GetPrime(unsigned n0)
+Util_GetPrime(unsigned n0) // IN:
{
unsigned i, ii, n, nn;
*/
static void *
-SuperFgets(FILE *stream, // IN
- size_t *count, // IN/OUT
- void *bufIn) // OUT
+SuperFgets(FILE *stream, // IN:
+ size_t *count, // IN/OUT:
+ void *bufIn) // OUT:
{
char *buf = (char *)bufIn;
size_t size = 0;
*
* Read the next line from a stream.
*
- * A line is defined as an arbitrary long sequence of arbitrary bytes, that
- * ends with the first occurrence of one of these line terminators:
+ * A line is defined as an arbitrary long sequence of arbitrary bytes,
+ * that ends with the first occurrence of one of these line terminators:
* . \r\n (the ANSI way, in text mode)
* . \n (the UNIX way)
* . \r (the Legacy Mac (pre-OS X) way)
* will be interpreted as two newlines in text mode ('\r' followed by
* '\r\n'), but three newlines in binary mode ('\r', '\r', '\n').
*
- * If maxBufLength is non-zero at most maxBufLength bytes will be allocated.
+ * If maxBufLength is non-zero at most maxBufLength bytes will be
+ * allocated.
*
* Results:
* StdIO_Success on success: '*buf' is an allocated, NUL terminated buffer
* that contains the line (excluding the line
- * terminator). If not NULL, '*count' contains the
- * size of the buffer (excluding the NUL
+ * terminator). If not NULL, '*count' contains
+ * the size of the buffer (excluding the NUL
* terminator)
* StdIO_EOF if there is no next line (end of stream)
* StdIO_Error on failure: errno is set accordingly
*/
StdIO_Status
-StdIO_ReadNextLine(FILE *stream, // IN
- char **buf, // OUT
- size_t maxBufLength, // IN
- size_t *count) // OUT
+StdIO_ReadNextLine(FILE *stream, // IN:
+ char **buf, // OUT:
+ size_t maxBufLength, // IN:
+ size_t *count) // OUT:
{
DynBuf b;
* The dynamic buffer must be at least 2 bytes large, so that at least
* 1 stream byte and fgets()'s NUL byte can fit --hpreg
*/
+
if (DynBuf_Enlarge(&b, 2) == FALSE) {
errno = ENOMEM;
goto error;
if (size == 0 && feof(stream)) {
/* Reached end-of-file before reading anything */
DynBuf_Destroy(&b);
+
return StdIO_EOF;
}
bit mask & shift operations.
------------------------------------------------------------------------ */
-typedef unsigned long UTF32; /* at least 32 bits */
-typedef unsigned short UTF16; /* at least 16 bits */
-typedef unsigned char UTF8; /* typically 8 bits */
-typedef unsigned char Boolean; /* 0 or 1 */
+#include "vm_basic_types.h"
+
+typedef uint32 UTF32; /* at least 32 bits */
+typedef uint16 UTF16; /* at least 16 bits */
+typedef uint8 UTF8; /* typically 8 bits */
+typedef unsigned char Boolean; /* 0 or 1 */
/* Some fundamental constants */
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
Str_Vsnprintf(buf, sizeof buf, fmt, args);
va_end(args);
- Warning("Msg_Append: %s\n", buf);
+ Warning("%s [STUB]: %s\n", __FUNCTION__, buf);
}
Str_Vsnprintf(buf, sizeof buf, fmt, args);
va_end(args);
- Warning("Msg_Question: %s\n", buf);
+ Warning("%s [STUB]: %s\n", __FUNCTION__, buf);
return (unsigned int) defaultAnswer;
}
* 497 days. This function can detect the wrapping and still return
* a correct, monotonic, 64 bit wide value if it is called at least
* once every 497 days.
- *
+ *
* Result:
* The value on success
* -1 on failure (never happens in this implementation)
/*
* Dummy variable b/c times(NULL) segfaults on FreeBSD 3.2 --greg
*/
- struct tms tp;
+ struct tms tp;
#if !defined (VM_X86_64)
static uint64 base = 0;
ASSERT(secs);
ASSERT(usecs);
-
+
if (gettimeofday(&tv, NULL) < 0) {
return FALSE;
}
struct timeval oldTx;
int error;
- /*
+ /*
* Solaris needs first argument non-NULL and zero
* to get the old timeval value.
*/
int64 newTime;
int64 secs;
int64 usecs;
-
+
if (!System_GetCurrentTime(&secs, &usecs)) {
return FALSE;
}
-
+
if (System_IsTimeSlewEnabled()) {
System_DisableTimeSlew();
}
newTime = (secs + deltaSecs) * 1000000L + (usecs + deltaUsecs);
ASSERT(newTime > 0);
-
+
/*
* timeval.tv_sec is a 32-bit signed integer. So, Linux will treat
- * newTime as a time before the epoch if newTime is a time 68 years
- * after the epoch (beacuse of overflow).
+ * newTime as a time before the epoch if newTime is a time 68 years
+ * after the epoch (beacuse of overflow).
*
- * If it is a 64-bit linux, everything should be fine.
+ * If it is a 64-bit linux, everything should be fine.
*/
if (sizeof tv.tv_sec < 8 && newTime / 1000000L > MAX_INT32) {
Log("System_AddToCurrentTime() overflow: deltaSecs=%"FMT64"d, secs=%"FMT64"d\n",
return FALSE;
}
-
+
tv.tv_sec = newTime / 1000000L;
tv.tv_usec = newTime % 1000000L;
if (settimeofday(&tv, NULL) < 0) {
return FALSE;
}
-
+
return TRUE;
}
do {
char *newBuf;
bufSize *= 2;
-
+
newBuf = realloc(buf, bufSize);
if (newBuf == NULL) {
goto out;
*
* Results:
* TRUE if this is an ACPI system.
- * FALSE if this is not an ACPI system.
+ * FALSE if this is not an ACPI system.
*
* Side effects:
* None.
/*
*-----------------------------------------------------------------------------
- *
- * System_Shutdown --
+ *
+ * System_Shutdown --
*
* Initiate system shutdown.
- *
- * Return value:
+ *
+ * Return value:
* None.
- *
+ *
* Side effects:
* None.
*
/*
*-----------------------------------------------------------------------------
- *
- * System_IsUserAdmin --
+ *
+ * System_IsUserAdmin --
*
* On Windows this functions checks if the calling user has membership in
* the Administrators group (for NT platforms). On POSIX machines, we simply
* check if the user's effective UID is root.
- *
- * Return value:
+ *
+ * Return value:
* TRUE if the user has an effective UID of root.
* FALSE if not.
- *
+ *
* Side effects:
* None.
*
const char *valueName) // IN: UTF-8
{
char *result;
-
+
#if defined(sun)
result = NULL;
#else
*
* System_UnsetEnv --
*
- * Unset environment variable.
+ * Unset environment variable.
*
* Results:
* 0 if success, -1 otherwise.
*
* System_SetLDPath --
*
- * Set LD_LIBRARY_PATH. If native is TRUE, use VMWARE_LD_LIBRARY_PATH
+ * Set LD_LIBRARY_PATH. If native is TRUE, use VMWARE_LD_LIBRARY_PATH
* as the value (and ignore the path argument, which should be set to
* NULL in this case). If native is FALSE, use the passed in path (and
* if that path is NULL, unsetenv the value).
* responsible for calling free() on this pointer.
*
* Side effects:
- * Manipulates the value of LD_LIBRARY_PATH variable.
+ * Manipulates the value of LD_LIBRARY_PATH variable.
*
*----------------------------------------------------------------------
*/
free(p);
} else if (path) {
/*
- * Set LD_LIBRARY_PATH to the specified value.
+ * Set LD_LIBRARY_PATH to the specified value.
*/
System_SetEnv(TRUE, "LD_LIBRARY_PATH", (char *) path);
} else {
* whether the value was set in the native environment. Based on this:
* VMWARE_FOO="1foo" -> FOO="foo"
* VMWARE_FOO="1" -> FOO=""
- * VMWARE_FOO="0 VMWARE_UNDEFINED" -> FOO is unset in the native environment
+ * VMWARE_FOO="0" -> FOO is unset in the native environment
*
* Variables without the VMWARE_ prefix are just copied over to the new
* environment. Note, of course, that VMWARE_-prefixed variables take
* XXX Should we move this marker to a separate header?
*/
char *realKey = &key[prefixLength];
- char *realValue = (strcmp(value, "0 VMWARE_UNDEFINED") == 0)
+ char *realValue = (value[0] == '0')
? NULL
: Util_SafeStrdup(&value[1]);
HashTable_ReplaceOrInsert(environTable, realKey, realValue);
noinst_LTLIBRARIES = libUser.la
libUser_la_SOURCES =
-libUser_la_SOURCES += hostinfoPosix2.c
libUser_la_SOURCES += util.c
libUser_la_SOURCES += utilPosix.c
+++ /dev/null
-/*********************************************************
- * Copyright (C) 1998 VMware, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation version 2.1 and no later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- *********************************************************/
-
-/*
- * hostinfoPosix.c --
- *
- * Interface to host-specific information functions for Posix hosts
- *
- * I created this file for this only reason: the functions it contains should
- * be callable by _any_ VMware userland program --hpreg
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/utsname.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <pwd.h>
-#include <sys/resource.h>
-#if defined(__APPLE__)
-#define SYS_NMLN _SYS_NAMELEN
-#include <assert.h>
-#include <CoreServices/CoreServices.h>
-#include <mach-o/dyld.h>
-#include <mach/host_info.h>
-#include <mach/mach_host.h>
-#include <mach/mach_init.h>
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-#include <sys/sysctl.h>
-#elif defined(__FreeBSD__)
-#include <sys/sysctl.h>
-#if !defined(RLIMIT_AS)
-# if defined(RLIMIT_VMEM)
-# define RLIMIT_AS RLIMIT_VMEM
-# else
-# define RLIMIT_AS RLIMIT_RSS
-# endif
-#endif
-#else
-#if !defined(USING_AUTOCONF) || defined(HAVE_SYS_VFS_H)
-#include <sys/vfs.h>
-#endif
-#if !defined(sun) && (!defined(USING_AUTOCONF) || (defined(HAVE_SYS_IO_H) && defined(HAVE_SYS_SYSINFO_H)))
-#include <sys/io.h>
-#include <sys/sysinfo.h>
-#ifndef HAVE_SYSINFO
-#define HAVE_SYSINFO 1
-#endif
-#endif
-#endif
-
-#if defined(__APPLE__) || defined(__FreeBSD__)
-#include <paths.h>
-#endif
-
-#if !defined(_PATH_DEVNULL)
-#define _PATH_DEVNULL "/dev/null"
-#endif
-
-#include "vmware.h"
-#include "hostType.h"
-#include "hostinfo.h"
-#include "vm_version.h"
-#include "str.h"
-#include "msg.h"
-#include "log.h"
-#include "posix.h"
-#include "file.h"
-#include "backdoor_def.h"
-#include "util.h"
-#include "vmstdio.h"
-#include "su.h"
-#include "vm_atomic.h"
-#include "x86cpuid.h"
-#include "syncMutex.h"
-#include "unicode.h"
-
-#ifdef VMX86_SERVER
-#include "uwvmkAPI.h"
-#include "uwvmk.h"
-#include "vmkSyscall.h"
-#endif
-
-#define LGPFX "HOSTINFO:"
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * Hostinfo_GetModulePath --
- *
- * Retrieve the full path to the executable. Not supported under VMvisor.
- *
- * Note: If your process is running with elevated privileges
- * (setuid/setgid), treat the path returned by this function as
- * untrusted (for example, do not pass it to exec or open).
- *
- * This function returns a path that is under the control of the
- * user. An attacker could manipulate the path returned by this
- * function to elevate privileges.
- *
- * Results:
- * On success: The allocated, NUL-terminated file path.
- * Note: This path can be a symbolic or hard link; it's just one
- * possible path to access the executable.
- *
- * On failure: NULL.
- *
- * Side effects:
- * None
- *
- *-----------------------------------------------------------------------------
- */
-
-Unicode
-Hostinfo_GetModulePath(uint32 priv) // IN:
-{
- Unicode path;
-
-#if defined(__APPLE__)
- uint32_t pathSize = FILE_MAXPATH;
-#else
- uid_t uid = -1;
-#endif
-
- if ((priv != HGMP_PRIVILEGE) && (priv != HGMP_NO_PRIVILEGE)) {
- Warning("%s: invalid privilege parameter\n", __FUNCTION__);
-
- return NULL;
- }
-
-#if defined(__APPLE__)
- path = Util_SafeMalloc(pathSize);
- if (_NSGetExecutablePath(path, &pathSize)) {
- Warning(LGPFX" %s: _NSGetExecutablePath failed.\n", __FUNCTION__);
- free(path);
-
- return NULL;
- }
-
-#else
-#if defined(VMX86_SERVER)
- if (HostType_OSIsVMK()) {
- return NULL;
- }
-#endif
-
- // "/proc/self/exe" only exists on Linux 2.2+.
- ASSERT(Hostinfo_OSVersion(0) >= 2 && Hostinfo_OSVersion(1) >= 2);
-
- if (priv == HGMP_PRIVILEGE) {
- uid = Id_BeginSuperUser();
- }
-
- path = Posix_ReadLink("/proc/self/exe");
-
- if (priv == HGMP_PRIVILEGE) {
- Id_EndSuperUser(uid);
- }
-
- if (path == NULL) {
- Warning(LGPFX" %s: readlink failed: %s\n", __FUNCTION__,
- Err_ErrString());
- }
-#endif
-
- return path;
-}