📄 stdlibx.cpp
字号:
for (count=0; count<32; count++)
map[count] = 0;
/* Set bits in control map */
while (*ctrl)
{
map[*ctrl >> 3] |= (1 << (*ctrl & 7));
ctrl++;
}
/* 1st char NOT in control map stops search */
if (*str)
{
count=0;
while (map[*str >> 3] & (1 << (*str & 7)))
{
count++;
str++;
}
return(count);
}
return(0);
}
__int64 _atoi64(const char *nptr)
{
int c; /* current char */
__int64 total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
/* skip whitespace */
while ( isspace((int)(unsigned char)*nptr) )
++nptr;
c = (int)(unsigned char)*nptr++;
sign = c; /* save sign indication */
if (c == '-' || c == '+')
c = (int)(unsigned char)*nptr++; /* skip sign */
total = 0;
while (isdigit(c)) {
total = 10 * total + (c - '0'); /* accumulate digit */
c = (int)(unsigned char)*nptr++; /* get next char */
}
if (sign == '-')
return -total;
else
return total; /* return result, negated if necessary */
}
#endif
static void x64toa (unsigned __int64 val,char *buf,unsigned radix,int is_neg)
{
char *p; /* pointer to traverse string */
char *firstdig; /* pointer to first digit */
char temp; /* temp char */
unsigned digval; /* value of digit */
p = buf;
if ( is_neg )
{
*p++ = '-'; /* negative, so output '-' and negate */
val = (unsigned __int64)(-(__int64)val);
}
firstdig = p; /* save pointer to first digit */
do {
digval = (unsigned) (val % radix);
val /= radix; /* get next digit */
/* convert to ascii and store */
if (digval > 9)
*p++ = (char) (digval - 10 + 'a'); /* a letter */
else
*p++ = (char) (digval + '0'); /* a digit */
} while (val > 0);
/* We now have the digit of the number in the buffer, but in reverse
order. Thus we reverse them now. */
*p-- = '\0'; /* terminate string; p points to last digit */
do {
temp = *p;
*p = *firstdig;
*firstdig = temp; /* swap *p and *firstdig */
--p;
++firstdig; /* advance to next two digits */
} while (firstdig < p); /* repeat until halfway */
}
/* Actual functions just call conversion helper with neg flag set correctly,
and return pointer to buffer. */
char * _i64toa (__int64 val,char *buf,int radix)
{
x64toa((unsigned __int64)val, buf, radix, (radix == 10 && val < 0));
return buf;
}
char * _ui64toa (unsigned __int64 val,char *buf,int radix)
{
x64toa(val, buf, radix, 0);
return buf;
}
#if _WIN32_WCE < 0x502
int stricmp(const char* s1, const char* s2 ) { return _stricmp(s1, s2); }
int stricmp(const wchar_t* s1, const char* s2 )
{
int len = wcslen(s1);
if(NULL == s2) // Some optimization here
return len;
while(--len && (*s1++ == *s2++)) ;
return len;
};
#endif // _WIN32_WCE < 0x502
char* strdup( const char* s )
{
char* s1 = (char*) malloc(strlen(s) +1);
if( s1 )
strcpy( s1, s );
return s1;
}
int strcasecmp(const char* s1, const char* s2 )
{
return _stricmp(s1, s2);
}
int strncasecmp(const char* s1, const char* s2, int n)
{
return _strnicmp(s1, s2, n);
}
int strcasecmp(const wchar_t* s1, const char* s2 )
{
int len = wcslen(s1);
if(NULL == s2) // Some optimization here
return len;
while(--len && (*s1++ == *s2++)) ;
return len;
}
int strncasecmp( const wchar_t* s1, const char* s2, int n )
{
int len = wcslen(s1);
if(NULL == s2) // Some optimization here
return min(n, (int) wcslen(s1));
while(--len && (towlower(*(s1++)) == tolower(*(s2++))));
return len;
};
int strcasecmp(PString s1, const char* s2)
{
return _stricmp((const char*) s1, s2);
}
char * _mktemp (char *temp)
{
char *string = temp;
unsigned number;
int letter = 'a';
int xcount = 0;
int olderrno;
_ASSERTE(temp != NULL);
_ASSERTE(*temp != '\0');
number = (unsigned) GetCurrentProcess();
while (*string)
string++;
#ifndef _MBCS
while (*--string == 'X')
#else /* _MBCS */
while ((string>temp) && (!__isdbcscode(temp,string-1))
&& (*--string == 'X'))
#endif /* _MBCS */
{
xcount++;
*string = (char)((number % 10) + '0');
number /= 10;
}
if (*++string == '\0' || xcount != 6 )
return(NULL);
olderrno = errno; /* save current errno */
set_errno(0); /* make sure errno isn't EACCESS */
while ((_access(temp,0) == 0) || (errno == EACCES))
/* while file exists */
{
set_errno(0);
if (letter == 'z'+1)
{
set_errno(olderrno);
return(NULL);
}
*string = (char)letter++;
}
set_errno(olderrno);
return(temp);
}
void WINAPI DnsRecordListFree(PDNS_RECORD /*pRecordList*/, DNS_FREE_TYPE /*FreeType*/)
{
}
DNS_STATUS WINAPI DnsQuery_A(
const char* /*pszName*/,
WORD /*wType*/,
DWORD /*fOptions*/,
PIP4_ARRAY /*aipServers*/,
PDNS_RECORD* /*ppQueryResultsSet*/,
PVOID* /*pReserved*/
)
{
return 0;
}
LONG RegDeleteValue( HKEY hKey, const char* lpValueName )
{
return RegDeleteValue(hKey, PString(lpValueName).AsUCS2());
}
LONG RegQueryValueEx( HKEY hKey, const char* lpValueName, LPDWORD lpReserved,
LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData )
{
return RegQueryValueEx(hKey, PString(lpValueName).AsUCS2(), lpReserved, lpType, lpData, lpcbData);
}
LONG RegSetValueEx( HKEY hKey, const char* lpValueName, DWORD Reserved,
DWORD dwType, const BYTE* lpData, DWORD cbData )
{
return RegSetValueEx(hKey, PString(lpValueName).AsUCS2(), Reserved, dwType, lpData, cbData);
}
LONG RegCreateKeyEx( HKEY hKey, const char* lpSub, DWORD dwr, LPSTR lpcls, DWORD dwo,
REGSAM sam, LPSECURITY_ATTRIBUTES lpsa, PHKEY phk, LPDWORD lpdw )
{
return RegCreateKeyEx( hKey, PString(lpSub).AsUCS2(), dwr,
(LPWSTR) (LPCWSTR) PString(lpcls).AsUCS2(), // we know this value won't change
dwo, sam, lpsa, phk, lpdw );
}
LONG RegEnumKey(HKEY hKey, DWORD dwIndex, LPTSTR ptcsName, DWORD cbName)
{ DWORD cb = cbName;
return RegEnumKeyEx( hKey, dwIndex, ptcsName, &cb, 0L, NULL, NULL, NULL );
}
LONG RegEnumValueCe( HKEY hKey, DWORD dwIndex, LPTSTR ptcsValueName, LPDWORD lpcbValueName,
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData )
{
return RegEnumValue( hKey, dwIndex, ptcsValueName, lpcbValueName,
lpReserved, lpType, lpData, lpcbData );
}
UINT GetWindowsDirectory( char* lpBuffer, UINT uSize )
{
strncpy(lpBuffer, "\\Windows", uSize ); return uSize;
}
DWORD GetPrivateProfileString(
const char*, // lpAppName, // points to section name
const char*, // lpKeyName, // points to key name
const char*, // lpDefault, // points to default string
char*, // lpReturnedString, // points to destination buffer
DWORD, // nSize, // size of destination buffer
const char* ) // points to initialization filename
{
return (DWORD) -1L;
}
BOOL WritePrivateProfileString(
const char*, // lpAppName, // pointer to section name
const char*, // lpKeyName, // pointer to key name
const char*, // lpString, // pointer to string to add
const char* ) // pointer to initialization filename
{
return FALSE;
}
#pragma message ("Please don't forget to implement Get/SetProfileString!")
#if 0
PString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
LPCTSTR lpszDefault)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
if (m_pszRegistryKey != NULL)
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return lpszDefault;
CString strValue;
DWORD dwType=REG_NONE;
DWORD dwCount=0;
LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
(LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)), &dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hSecKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return strValue;
}
return lpszDefault;
}
return lpszDefault;
}
BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
LPCTSTR lpszValue)
{
ASSERT(lpszSection != NULL);
if (m_pszRegistryKey != NULL)
{
LONG lResult;
if (lpszEntry == NULL) //delete whole section
{
HKEY hAppKey = GetAppRegistryKey();
if (hAppKey == NULL)
return FALSE;
lResult = ::RegDeleteKey(hAppKey, lpszSection);
RegCloseKey(hAppKey);
}
else if (lpszValue == NULL)
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
// necessary to cast away const below
lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
RegCloseKey(hSecKey);
}
else
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
(LPBYTE)lpszValue, (ATL::lstrlen(lpszValue)+1)*sizeof(TCHAR));
RegCloseKey(hSecKey);
}
return lResult == ERROR_SUCCESS;
}
return FALSE;
}
#endif // profiles
#endif // _WIN32_WCE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -