这篇教程C++ wcstombs函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中wcstombs函数的典型用法代码示例。如果您正苦于以下问题:C++ wcstombs函数的具体用法?C++ wcstombs怎么用?C++ wcstombs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了wcstombs函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: trace_ds_s/* * This function is careful to do line breaks based on wchar_t's, not * bytes, so multi-byte characters are traced properly. * However, it doesn't know that DBCS characters are two columns wide, so it * will get those wrong and break too late. To get that right, it needs some * sort of function to tell it that a wchar_t is double-width, which we lack at * the moment. * * If wchar_t's are Unicode, it could perhaps use some sort of heuristic based * on which plane the character is in. */static voidtrace_ds_s(char *s, Boolean can_break){ int len = strlen(s); int len0 = len + 1; int wlen; Boolean nl = False; wchar_t *w_buf; /* wchar_t translation of s */ wchar_t *w_cur; /* current wchar_t pointer */ wchar_t *w_chunk; /* transient wchar_t buffer */ char *mb_chunk; /* transient multibyte buffer */ if (!toggled(TRACING) || tracef == NULL || !len) return; /* Allocate buffers for chunks of output data. */ mb_chunk = Malloc(len0); w_chunk = (wchar_t *)Malloc(len0 * sizeof(wchar_t)); /* Convert the input string to wchar_t's. */ w_buf = (wchar_t *)Malloc(len0 * sizeof(wchar_t)); wlen = mbstowcs(w_buf, s, len); if (wlen < 0) Error("trace_ds_s: mbstowcs failed"); w_cur = w_buf; /* Check for a trailing newline. */ if (len && s[len-1] == '/n') { wlen--; nl = True; } if (!can_break && dscnt + wlen >= 75) { wtrace(".../n... "); dscnt = 0; } while (dscnt + wlen >= 75) { int plen = 75-dscnt; int mblen; if (plen) { memcpy(w_chunk, w_cur, plen * sizeof(wchar_t)); w_chunk[plen] = 0; mblen = wcstombs(mb_chunk, w_chunk, len0); if (mblen <= 0) Error("trace_ds_s: wcstombs 1 failed"); } else { mb_chunk[0] = '/0'; mblen = 0; } wtrace("%.*s .../n... ", mblen, mb_chunk); dscnt = 4; w_cur += plen; wlen -= plen; } if (wlen) { int mblen; memcpy(w_chunk, w_cur, wlen * sizeof(wchar_t)); w_chunk[wlen] = 0; mblen = wcstombs(mb_chunk, w_chunk, len0); if (mblen <= 0) Error("trace_ds_s: wcstombs 2 failed"); wtrace("%.*s", mblen, mb_chunk); dscnt += wlen; } if (nl) { wtrace("/n"); dscnt = 0; } Free(mb_chunk); Free(w_buf); Free(w_chunk);}
开发者ID:hharte,项目名称:c3270,代码行数:87,
示例2: PyMem_Free/* Encode a wide character string to the locale encoding with the surrogateescape error handler: surrogate characters in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF. Return a pointer to a newly allocated byte string, use PyMem_Free() to free the memory. Return NULL on encoding or memory allocation error. If error_pos is not NULL, *error_pos is set to the index of the invalid character on encoding error, or set to (size_t)-1 otherwise. Use the Py_DecodeLocale() function to decode the bytes string back to a wide character string. */char*Py_EncodeLocale(const wchar_t *text, size_t *error_pos){#if defined(__APPLE__) || defined(__ANDROID__) Py_ssize_t len; PyObject *unicode, *bytes = NULL; char *cpath; unicode = PyUnicode_FromWideChar(text, wcslen(text)); if (unicode == NULL) return NULL; bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape"); Py_DECREF(unicode); if (bytes == NULL) { PyErr_Clear(); if (error_pos != NULL) *error_pos = (size_t)-1; return NULL; } len = PyBytes_GET_SIZE(bytes); cpath = PyMem_Malloc(len+1); if (cpath == NULL) { PyErr_Clear(); Py_DECREF(bytes); if (error_pos != NULL) *error_pos = (size_t)-1; return NULL; } memcpy(cpath, PyBytes_AsString(bytes), len + 1); Py_DECREF(bytes); return cpath;#else /* __APPLE__ */ const size_t len = wcslen(text); char *result = NULL, *bytes = NULL; size_t i, size, converted; wchar_t c, buf[2];#ifndef MS_WINDOWS if (force_ascii == -1) force_ascii = check_force_ascii(); if (force_ascii) return encode_ascii_surrogateescape(text, error_pos);#endif /* The function works in two steps: 1. compute the length of the output buffer in bytes (size) 2. outputs the bytes */ size = 0; buf[1] = 0; while (1) { for (i=0; i < len; i++) { c = text[i]; if (c >= 0xdc80 && c <= 0xdcff) { /* UTF-8b surrogate */ if (bytes != NULL) { *bytes++ = c - 0xdc00; size--; } else size++; continue; } else { buf[0] = c; if (bytes != NULL) converted = wcstombs(bytes, buf, size); else converted = wcstombs(NULL, buf, 0); if (converted == (size_t)-1) { if (result != NULL) PyMem_Free(result); if (error_pos != NULL) *error_pos = i; return NULL; } if (bytes != NULL) { bytes += converted; size -= converted; } else size += converted; } } if (result != NULL) { *bytes = '/0';//.........这里部分代码省略.........
开发者ID:3lnc,项目名称:cpython,代码行数:101,
示例3: LUKS_DumpLUKSDataToFile// ----------------------------------------------------------------------------BOOL LUKS_DumpLUKSDataToFile( MODULE_DETAILS_MAIN* mainDriver, WCHAR* filename, unsigned char* userKey, BOOL baseIVCypherOnHashLength, WCHAR* dumpFilename){ BOOL retval; LUKS_HEADER_EXT LUKSHeader; int i; char hashTitle[MAX_PRETTYPRINTED_TITLE]; char cypherTitle[MAX_PRETTYPRINTED_TITLE]; int keySlot; BYTE* keyMaterial; char IVHashTitle[MAX_PRETTYPRINTED_TITLE]; char IVCypherTitle[MAX_PRETTYPRINTED_TITLE]; char sectorIVGenMethodTitle[MAX_PRETTYPRINTED_TITLE]; char filenameAsChar[FREEOTFE_MAX_FILENAME_LENGTH * 4]; FILE* hFile; WCHAR* tmpStringGUID; char* prettyPrintData; int prettyPrintDataLength; retval = TRUE; // Sanity; source file must exist if (retval) { retval = ( SDUCheckFileExists(filename) && (!(SDUCheckFileExists(dumpFilename))) ); } if (retval) { hFile = _wfopen(dumpFilename, TEXT("w+")); driver_AddStdDumpHeader(hFile, "LUKS Dump"); // Get the LUKS header from the volume... if (!(LUKS_ReadLUKSHeader(filename, &LUKSHeader))) { if (LUKS_IsLUKSVolume(filename)) { fprintf(hFile, "ERROR: Unable to read LUKS header?!/n"); } else { fprintf(hFile, "Unable to read LUKS header; this does not appear to be a LUKS volume./n"); } } else { fprintf(hFile, "/n"); fprintf(hFile, "/n"); driver_AddStdDumpSection(hFile, "cryptsetup Style Dump"); wcstombs(filenameAsChar, filename, sizeof(filenameAsChar)); fprintf(hFile, "LUKS header information for %s/n", filenameAsChar); SecZeroMemory(filenameAsChar, sizeof(filenameAsChar)); fprintf(hFile, "/n"); fprintf(hFile, "Version: %d/n", LUKSHeader.rawHeader.version); fprintf(hFile, "Cipher name: %s/n", LUKSHeader.rawHeader.cipher_name); fprintf(hFile, "Cipher mode: %s/n", LUKSHeader.rawHeader.cipher_mode); fprintf(hFile, "Hash spec: %s/n", LUKSHeader.rawHeader.hash_spec); fprintf(hFile, "Payload offset: %d/n", LUKSHeader.rawHeader.payload_offset); fprintf(hFile, "MK bits: %d/n", (LUKSHeader.rawHeader.key_bytes * 8)); // Convert from bytes to bits fprintf(hFile, "MK digest: "); LUKS_PrettyHex( hFile, (BYTE*)(&(LUKSHeader.rawHeader.mk_digest)), LUKS_DIGESTSIZE ); fprintf(hFile, "/n"); fprintf(hFile, "MK salt: "); LUKS_PrettyHex( hFile, &(LUKSHeader.rawHeader.mk_digest_salt[0]), (LUKS_SALTSIZE / 2) ); fprintf(hFile, "/n"); fprintf(hFile, " "); LUKS_PrettyHex( hFile, &(LUKSHeader.rawHeader.mk_digest_salt[(LUKS_SALTSIZE / 2)]), (LUKS_SALTSIZE / 2) ); fprintf(hFile, "/n"); fprintf(hFile, "MK iterations: %d/n", LUKSHeader.rawHeader.mk_digest_iter); fprintf(hFile, "UUID: %s/n", LUKSHeader.rawHeader.uuid); fprintf(hFile, "/n"); for (i = 0; i < LUKS_NUMKEYS; i++)//.........这里部分代码省略.........
开发者ID:Cristo-Conklin,项目名称:LibreCrypt,代码行数:101,
示例4: HookedCreateProcessInternalWBOOLWINAPIHookedCreateProcessInternalW( HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation, PHANDLE hNewToken ){ BOOL bReturn; CHAR szDllFullPath[MAX_PATH]; /* apply config rules if shellcode or ROP detected */ if ( DbgGetShellcodeFlag() == MCEDP_STATUS_SHELLCODE_FLAG_SET || DbgGetRopFlag() == MCEDP_STATUS_ROP_FLAG_SET ) { if ( MCEDP_REGCONFIG.SHELLCODE.ANALYSIS_SHELLCODE ) { CHAR *szApplicationNameA = (CHAR *)LocalAlloc(LMEM_ZEROINIT, 1024); CHAR *szCommandLineA = (CHAR *)LocalAlloc(LMEM_ZEROINIT, 1024); PXMLNODE XmlLogNode; PXMLNODE XmlIDLogNode; if ( lpApplicationName != NULL ) wcstombs( szApplicationNameA, lpApplicationName, 1024); if ( lpCommandLine != NULL ) wcstombs( szCommandLineA, lpCommandLine, 1024); XmlIDLogNode = mxmlNewElement( XmlShellcode, "row"); /* type */ XmlLogNode = mxmlNewElement( XmlIDLogNode, "type"); mxmlNewText( XmlLogNode, 0, "1"); /* exec */ XmlLogNode = mxmlNewElement( XmlIDLogNode, "exec_process"); mxmlNewText( XmlLogNode, 0, szApplicationNameA); XmlLogNode = mxmlNewElement( XmlIDLogNode, "exec_cmd"); mxmlNewText( XmlLogNode, 0, szCommandLineA); /* save */ SaveXml( XmlLog ); LocalFree(szApplicationNameA); LocalFree(szCommandLineA); } /* if malware execution is not allowd then terminate the process */ if ( MCEDP_REGCONFIG.GENERAL.ALLOW_MALWARE_EXEC == FALSE ) TerminateProcess(GetCurrentProcess(), STATUS_ACCESS_VIOLATION); /* let the malware execute */ return (CreateProcessInternalW_( hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, hNewToken)); } /* if the process is creating with CREATE_SUSPENDED flag, let it do its job */ if ( IsBitSet(dwCreationFlags, 2) ) { bReturn = CreateProcessInternalW_( hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, hNewToken); if ( bReturn != FALSE ) { strncpy( szDllFullPath, MCEDP_REGCONFIG.MCEDP_MODULE_PATH, MAX_PATH ); if ( InjectDLLIntoProcess( szDllFullPath, lpProcessInformation->hProcess ) != MCEDP_STATUS_SUCCESS ) { DEBUG_PRINTF(LDBG, NULL, "Module failed to inject itself into newly created process , PID : %d/n", lpProcessInformation->dwProcessId); return bReturn; } DEBUG_PRINTF(LDBG, NULL, "Module injected itself into newly created process , PID : %d/n", lpProcessInformation->dwProcessId); /* Sleep for INIT_WAIT_TIME sec and let MCEDP init itself in newly created process TODO : use a messaging mechanism and resume process after init finished instead of sleeping! */ Sleep(INIT_WAIT_TIME); return bReturn; } } else { /* if the process is not creating with CREATE_SUSPENDED flag, force it do it */ bReturn = CreateProcessInternalW_( hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED , lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, hNewToken); if ( bReturn != FALSE ) { /* TODO : We dont need this if ther process is already added into Protection List in registry, so we should remove this lines */ strncpy( szDllFullPath, MCEDP_REGCONFIG.MCEDP_MODULE_PATH, MAX_PATH ); if ( InjectDLLIntoProcess( szDllFullPath, lpProcessInformation->hProcess ) != MCEDP_STATUS_SUCCESS ) { DEBUG_PRINTF(LDBG, NULL, "Module failed to inject itself into newly created process , PID : %d/n", lpProcessInformation->dwProcessId); ResumeThread(lpProcessInformation->hThread); return bReturn; } DEBUG_PRINTF(LDBG, NULL, "Module injected itself into newly created process , PID : %d/n", lpProcessInformation->dwProcessId); /* Sleep for INIT_WAIT_TIME sec and let MCEDP init itself in newly created process//.........这里部分代码省略.........
开发者ID:amohanta,项目名称:pwnypot,代码行数:101,
示例5: __F_NAMEstatic int __F_NAME(__sopen,__wsopen)( const CHAR_TYPE *name, int mode, int shflag, va_list args ){ int rwmode; int handle; int attr; int permission; unsigned iomode_flags; tiny_ret_t rc; char dummy;#ifdef __WIDECHAR__ char mbName[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */#endif handle = -1; rc = 0; while( *name == STRING( ' ' ) ) ++name;#ifdef __WIDECHAR__ /*** If necessary, convert the wide filename to multibyte form ***/ if( wcstombs( mbName, name, sizeof( mbName ) ) == -1 ) { mbName[0] = '/0'; }#endif rwmode = mode & ( O_RDONLY | O_WRONLY | O_RDWR | O_NOINHERIT ); if( _dos_open( __F_NAME(name,mbName), rwmode | shflag, &handle ) == 0 ) { if( handle >= __NFiles ) { TinyClose( handle ); __set_errno( EMFILE ); return( -1 ); } } /* 17-apr-90 05-sep-91 */ if( (mode & (O_RDONLY | O_WRONLY | O_RDWR)) != O_RDONLY ) { if( handle != -1 ) { if( ! isatty( handle ) ) { /* if not a device */#if 0 rc = TinyAccess( name, 0 ); /* check for existence */ if( TINY_ERROR( rc ) ) { /* file does not exist */ TinyClose( handle ); /* close whatever file we got */ handle = -1; } else if( mode & O_EXCL ) { /* must not exist */#else /* Don't need to do the access check, since the file was opened and therefore must exist (TinyOpen can't create a file). We don't want to do the check because there are classes of items in the file system namespace that are not devices, but the TinyAccess will fail on (e.g. named pipes). */ /* must not exist if O_CREAT specified */ if( (mode & O_EXCL) && (mode & O_CREAT) ) {#endif TinyClose( handle ); __set_errno( EEXIST ); return( -1 ); } else if( mode & O_TRUNC ) { /* truncate file */ rc = TinyWrite( handle, &dummy, 0 ); if( TINY_ERROR( rc ) ) { TinyClose( handle ); return( __set_errno_dos( TINY_INFO( rc ) ) ); } } } } } if( handle == -1 ) { /* could not open */ if( (mode & O_CREAT) == 0 || _RWD_doserrno != E_nofile ) { return( -1 ); } /* creating the file */ permission = va_arg( args, int ); va_end( args ); if( permission == 0 ) permission = S_IWRITE | S_IREAD; permission &= ~_RWD_umaskval; /* 05-jan-95 */ attr = 0; if(( permission & S_IWRITE) == 0 ) attr = _A_RDONLY; #if 0 /* remove this support because it is not consistently available */ if( _RWD_osmajor >= 5 #ifdef __DOS_EXT__ && !_IsFlashTek() && !_IsRational() #endif ) { /* this function is only available in version DOS 5 and up */ /* this new way was added to handle the case of creating a */ /* new file with read-only access, but with a writeable */ /* file handle */ #ifdef __WIDECHAR__ rc = TinyCreateEx( mbName, rwmode|shflag, attr, TIO_OPEN ); #else rc = TinyCreateEx( name, rwmode|shflag, attr, TIO_OPEN ); #endif if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } handle = TINY_INFO( rc );//.........这里部分代码省略.........
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:101,
示例6: load_libsvoid load_libs(void) { struct dirent *entry; DIR *extdir; void *lib; initfun initializer; const char *ext; wchar_t path[512] = { 0 }; char *asciipath; _api *a = malloc(sizeof(_api)); chatenv *c = malloc(sizeof(chatenv)); c->get_users = rget_users; if (a == NULL) HANDLE_ERR("Unable to allocate memory for _api"); a->hook_msg = hook_msg; a->hook_join = hook_join; a->hook_part = hook_part; a->unhook = ev_unhook; a->events = ev_get_global(); a->setting_store = setting_store; a->setting_get = setting_get; a->chatenv = c; wchar_t *exts = setting_get(BKEY_EXTENSIONS_DIR); if (exts == NULL) { free(a); return; } char *asciidir = calloc(1, wcslen(exts) * 4); wcstombs(asciidir, exts, wcslen(exts) * 4); extdir = opendir(asciidir); if (extdir == NULL) { perror("Couldn't open extension directory"); exit(EXIT_FAILURE); return; } while ((entry = readdir(extdir))) { ext = get_extension(entry->d_name); if (strcmp(ext, "so") == 0) { wmemset(path, 0, 512); swprintf(path, 511, L"%s/%s", asciidir, entry->d_name); asciipath = calloc(1, 1022); wcstombs(asciipath, path, 1022); lib = dlopen(asciipath, RTLD_NOW); free(asciipath); if (lib == NULL) { wprintf(L"Unable to read %ls, invalid library/n", path); continue; } initializer = (initfun)dlsym(lib, BINIT_FUNCTION); if (initializer == NULL) { wprintf(L"Symbol %s not found in %ls, might want to fix that./n", BINIT_FUNCTION, path); continue; } initializer(a); } } free(asciidir); closedir(extdir);}
开发者ID:pikajude,项目名称:balloons,代码行数:64,
示例7: CUGP//.........这里部分代码省略......... for ( i = 0, cur = bufLMI; i < read; ++ i, ++ cur ) { // Note: the capital S in the format string will expect Unicode // strings, as this is a program written/compiled for ANSI. _wcsupr(cur->lgrmi2_domainandname); wcscpy(tempbuf,cur->lgrmi2_domainandname); wchar_t *t=wcsstr(tempbuf,seperator); t++; printf( "%S/n", t ); if (wcscmp(_wcsupr(t), _wcsupr((wchar_t *)user))==0) { laccess_vnc=TRUE; printf( "Local: User found in group /n" ); } } if ( bufLMI != NULL ) NetApiBufferFree( bufLMI ); } } while ( rc == ERROR_MORE_DATA ); /////////////////////////////////////////////////////////////////////// if ( h != 0 )FreeLibrary( h); } if ( !rcdomain){ DWORD rc; printf( "New added ---- just for testing /n"); wcscpy( (wchar_t *) server, (wchar_t *) buf ); byte *buf2 = 0; rc2 = NetWkstaGetInfoNT( 0 , 100 , &buf2 ) ; if( rc2 ) printf( "NetWkstaGetInfoA() returned %lu /n", rc2); else wcstombs( domain, ((WKSTA_INFO_100_NT *) buf2)->wki100_langroup, MAXLEN ); NetApiBufferFree( buf2 ); domain[MAXLEN - 1] = '/0'; printf("Detected domain = %s/n",domain); buf2 = 0; char userdomain[MAXLEN * sizeof(wchar_t)]; char userdom[MAXLEN]; strcpy(userdom,domain); strcat(userdom,"//"); strcat(userdom,userin); mbstowcs( (wchar_t *) userdomain, userdom, MAXLEN ); printf( "%S/n", userdomain); rc = NetUserGetGroupsNT( NULL ,(wchar_t *) userdomain, 0, 1,&buf2, MAX_PREFERRED_LENGTH, &read, &total); if ( rc == NERR_Success) { for ( i = 0; i < read; ++ i ) { wcstombs( groupname, ((LPLOCALGROUP_USERS_INFO_0_NT *) buf2)[i].grui0_name, MAXLEN ); groupname[MAXLEN - 1] = '/0'; // because strncpy won't do this if overflow#ifdef _MSC_VER _strupr(groupname); _strupr(groupin);#else _strupr(groupname); _strupr(groupin);#endif printf( "compare %s %s/n", groupname, group); if (strcmp(groupname, groupin)==0) { printf( "match .../n" ); laccess_vnc=TRUE; } else printf( "no match .../n" );
开发者ID:copilot-com,项目名称:CopilotVNC,代码行数:67,
示例8: PSYCHHIDCheckInit/* PSYCHHIDCheckInit() Check to see if we need to create the USB-HID device list. If it has not been created then create it. */void PsychHIDVerifyInit(void){ int busId, devId; pRecDevice currentDevice = NULL; struct hid_device_info* hid_dev = NULL; // If hid_devices list of all HID devices not yet initialized, // perform device enumeration: if (!hidlib_devices) { // Low-Level enumeration by HIDLIB: hidlib_devices = hid_enumerate(0x0, 0x0); // Build our own higher-level device list filled with info // from the low-level list: for (hid_dev = hidlib_devices; hid_dev != NULL; hid_dev = hid_dev->next) { // Allocate and zero-init high level struct currentDevice: currentDevice = calloc(1, sizeof(recDevice)); // Copy low-level props to corresponding high-level props: currentDevice->usagePage = hid_dev->usage_page; currentDevice->usage = hid_dev->usage; // Abuse the "transport" string for the device path. On OS/X this just contains "USB": sprintf(¤tDevice->transport[0], "%s", hid_dev->path); currentDevice->vendorID = hid_dev->vendor_id; currentDevice->productID = hid_dev->product_id; currentDevice->version = hid_dev->release_number; if (hid_dev->manufacturer_string) wcstombs(¤tDevice->manufacturer[0], hid_dev->manufacturer_string, 256); if (hid_dev->product_string) wcstombs(¤tDevice->product[0], hid_dev->product_string, 256); if (hid_dev->serial_number) wcstombs(¤tDevice->serial[0], hid_dev->serial_number, 256); // Convert unique device path into unique numeric location id: if (PSYCH_SYSTEM == PSYCH_LINUX) { // Use USB bus-id and device-id as unique location identifier: sscanf(hid_dev->path, "%x:%x", &busId, &devId); currentDevice->locID = (double) ((busId << 16) + (devId << 0)); } if (PSYCH_SYSTEM == PSYCH_WINDOWS) { // Use device container id as unique location identifier. // This may only work on Windows-7+ and is a bit of a hack here, // the id is a GUID, nothing related to busId or devId. We init // devId with the hid_dev pointer value, to get a devId and thereby // location id in case proper parsing of a container id doesn't work: busId = 0; devId = (int) hid_dev; if (strstr(hid_dev->path, "{")) sscanf(strstr(hid_dev->path, "{"), "{%x-%x", &busId, &devId); currentDevice->locID = (double) (((psych_uint64) busId << 32) + devId); } // Interface number is great for identifying DAQ devices, but not available // on OS/X, so this will be a Linux/Windows only thing. currentDevice->interfaceId = hid_dev->interface_number; // Enqueue record into linked list: currentDevice->pNext = hid_devices; hid_devices = currentDevice; } } return;}
开发者ID:Jakobth,项目名称:Psychtoolbox-3,代码行数:66,
示例9: enum_routes//.........这里部分代码省略......... if (!GetIfEntry) { ec = boost::asio::error::operation_not_supported; return std::vector<ip_route>(); }#if _WIN32_WINNT >= 0x0600 typedef DWORD (WINAPI *GetIpForwardTable2_t)( ADDRESS_FAMILY, PMIB_IPFORWARD_TABLE2*); typedef void (WINAPI *FreeMibTable_t)(PVOID Memory); GetIpForwardTable2_t GetIpForwardTable2 = (GetIpForwardTable2_t)GetProcAddress( iphlp, "GetIpForwardTable2"); FreeMibTable_t FreeMibTable = (FreeMibTable_t)GetProcAddress( iphlp, "FreeMibTable"); if (GetIpForwardTable2 && FreeMibTable) { MIB_IPFORWARD_TABLE2* routes = NULL; int res = GetIpForwardTable2(AF_UNSPEC, &routes); if (res == NO_ERROR) { for (int i = 0; i < routes->NumEntries; ++i) { ip_route r; r.gateway = sockaddr_to_address((const sockaddr*)&routes->Table[i].NextHop); r.destination = sockaddr_to_address( (const sockaddr*)&routes->Table[i].DestinationPrefix.Prefix); r.netmask = build_netmask(routes->Table[i].SitePrefixLength , routes->Table[i].DestinationPrefix.Prefix.si_family); MIB_IFROW ifentry; ifentry.dwIndex = routes->Table[i].InterfaceIndex; if (GetIfEntry(&ifentry) == NO_ERROR) { wcstombs(r.name, ifentry.wszName, sizeof(r.name)); r.mtu = ifentry.dwMtu; ret.push_back(r); } } } if (routes) FreeMibTable(routes); FreeLibrary(iphlp); return ret; }#endif // Get GetIpForwardTable() pointer typedef DWORD (WINAPI *GetIpForwardTable_t)(PMIB_IPFORWARDTABLE pIpForwardTable,PULONG pdwSize,BOOL bOrder); GetIpForwardTable_t GetIpForwardTable = (GetIpForwardTable_t)GetProcAddress( iphlp, "GetIpForwardTable"); if (!GetIpForwardTable) { FreeLibrary(iphlp); ec = boost::asio::error::operation_not_supported; return std::vector<ip_route>(); } MIB_IPFORWARDTABLE* routes = NULL; ULONG out_buf_size = 0; if (GetIpForwardTable(routes, &out_buf_size, FALSE) != ERROR_INSUFFICIENT_BUFFER) { FreeLibrary(iphlp); ec = boost::asio::error::operation_not_supported; return std::vector<ip_route>(); }
开发者ID:reignofmiracle,项目名称:libtorrent,代码行数:66,
示例10: mainintmain(int argc, char *argv[]){ wchar_t srcbuf[128]; char dstbuf[128]; /* * C/POSIX locale. */ printf("1..1/n"); /* Simple null terminated string. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 5); assert(strcmp(dstbuf, "hello") == 0); assert((unsigned char)dstbuf[6] == 0xcc); /* Not enough space in destination buffer. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, 4) == 4); assert(memcmp(dstbuf, "hell", 4) == 0); assert((unsigned char)dstbuf[5] == 0xcc); /* Null terminated string, internal dest. buffer */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); assert(wcstombs(NULL, srcbuf, sizeof(dstbuf)) == 5); /* Null terminated string, internal state. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 5); assert(strcmp(dstbuf, "hello") == 0); assert((unsigned char)dstbuf[6] == 0xcc); /* Null terminated string, internal state, internal dest. buffer. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); assert(wcstombs(NULL, srcbuf, 0) == 5); /* Empty source buffer. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); srcbuf[0] = L'/0'; memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 0); assert(dstbuf[0] == L'/0'); /* Zero length destination buffer. */ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); wcscpy(srcbuf, L"hello"); memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, 0) == 0); assert((unsigned char)dstbuf[0] == 0xcc); /* * Japanese (EUC) locale. */ assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0); assert(MB_CUR_MAX > 1); wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf)); srcbuf[0] = 0xA3C1; srcbuf[1] = 0x0020; srcbuf[2] = 0x0042; srcbuf[3] = 0x0020; srcbuf[4] = 0xA3C3; srcbuf[5] = 0x0000; memset(dstbuf, 0xcc, sizeof(dstbuf)); assert(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 7); assert(strcmp(dstbuf, "/xA3/xC1 B /xA3/xC3") == 0); assert((unsigned char)dstbuf[8] == 0xcc); printf("ok 1 - wcstombs()/n"); return (0);}
开发者ID:JabirTech,项目名称:Source,代码行数:83,
示例11: do_test//.........这里部分代码省略......... cp = "ABC"; mbsrtowcs (wsmallbuf, &cp, 10, &s); CHK_FAIL_END#endif cp = "A"; if (mbstowcs (wenough, cp, 10) != 1 || wcscmp (wenough, L"A") != 0) FAIL (); cp = "DEF"; if (mbstowcs (wenough, cp, l0 + 10) != 3 || wcscmp (wenough, L"DEF") != 0) FAIL ();#if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START wchar_t wsmallbuf[2]; cp = "ABC"; mbstowcs (wsmallbuf, cp, 10); CHK_FAIL_END#endif memset (&s, '/0', sizeof (s)); cp = "ABC"; wcscpy (wenough, L"DEF"); if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 || wcscmp (wenough, L"AEF") != 0) FAIL (); cp = "IJ"; if (mbsnrtowcs (wenough, &cp, 1, l0 + 10, &s) != 1 || wcscmp (wenough, L"IEF") != 0) FAIL ();#if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START wchar_t wsmallbuf[2]; cp = "ABC"; mbsnrtowcs (wsmallbuf, &cp, 3, 10, &s); CHK_FAIL_END#endif memset (&s, '/0', sizeof (s)); const wchar_t *wcp = L"A"; if (wcsrtombs (enough, &wcp, 10, &s) != 1 || strcmp (enough, "A") != 0) FAIL (); wcp = L"BC"; if (wcsrtombs (enough, &wcp, l0 + 10, &s) != 2 || strcmp (enough, "BC") != 0) FAIL ();#if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; wcsrtombs (smallbuf, &wcp, 10, &s); CHK_FAIL_END#endif memset (enough, 'Z', sizeof (enough)); wcp = L"EF"; if (wcstombs (enough, wcp, 10) != 2 || strcmp (enough, "EF") != 0) FAIL (); wcp = L"G"; if (wcstombs (enough, wcp, l0 + 10) != 1 || strcmp (enough, "G") != 0) FAIL ();#if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; wcstombs (smallbuf, wcp, 10); CHK_FAIL_END#endif memset (&s, '/0', sizeof (s)); wcp = L"AB"; if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1 || strcmp (enough, "A") != 0) FAIL (); wcp = L"BCD"; if (wcsnrtombs (enough, &wcp, 1, l0 + 10, &s) != 1 || strcmp (enough, "B") != 0) FAIL ();#if __USE_FORTIFY_LEVEL >= 1 CHK_FAIL_START char smallbuf[2]; wcp = L"ABC"; wcsnrtombs (smallbuf, &wcp, 3, 10, &s); CHK_FAIL_END#endif }
开发者ID:KrisChaplin,项目名称:octeon_toolchain-4.1,代码行数:101,
示例12: curlassert/* * Our thread-safe and smart strerror() replacement. * * The 'err' argument passed in to this function MUST be a true errno number * as reported on this system. We do no range checking on the number before * we pass it to the "number-to-message" convertion function and there might * be systems that don't do proper range checking in there themselves. * * We don't do range checking (on systems other than Windows) since there is * no good reliable and portable way to do it. */const char *Curl_strerror(struct connectdata *conn, int err){ char *buf, *p; size_t max; curlassert(conn); curlassert(err >= 0); buf = conn->syserr_buf; max = sizeof(conn->syserr_buf)-1; *buf = '/0';#if defined(WIN32) && !defined(__CYGWIN__)#ifdef _WIN32_WCE buf[0]=0; { wchar_t wbuf[256]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL); wcstombs(buf,wbuf,max); }#else /* 'sys_nerr' is the maximum errno number, it is not widely portable */ if (err >= 0 && err < sys_nerr) strncpy(buf, strerror(err), max); else { if (!get_winsock_error(err, buf, max) && !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, LANG_NEUTRAL, buf, (DWORD)max, NULL)) snprintf(buf, max, "Unknown error %d (%#x)", err, err); }#endif#else /* not native Windows coming up */ /* These should be atomic and hopefully thread-safe */#ifdef HAVE_STRERROR_R /* There are two different APIs for strerror_r(). The POSIX and the GLIBC versions. */#ifdef HAVE_POSIX_STRERROR_R strerror_r(err, buf, max); /* this may set errno to ERANGE if insufficient storage was supplied via 'strerrbuf' and 'buflen' to contain the generated message string, or EINVAL if the value of 'errnum' is not a valid error number.*/#else { /* HAVE_GLIBC_STRERROR_R */ char buffer[256]; char *msg = strerror_r(err, buffer, sizeof(buffer)); /* this version of strerror_r() only *might* use the buffer we pass to the function, but it always returns the error message as a pointer, so we must copy that string unconditionally */ strncpy(buf, msg, max); }#endif /* end of HAVE_GLIBC_STRERROR_R */#else /* HAVE_STRERROR_R */ strncpy(buf, strerror(err), max);#endif /* end of HAVE_STRERROR_R */#endif /* end of ! Windows */ buf[max] = '/0'; /* make sure the string is zero terminated */ /* strip trailing '/r/n' or '/n'. */ if ((p = strrchr(buf,'/n')) != NULL && (p - buf) >= 2) *p = '/0'; if ((p = strrchr(buf,'/r')) != NULL && (p - buf) >= 1) *p = '/0'; return buf;}
开发者ID:joshdekock,项目名称:jim-pspware,代码行数:83,
示例13: __ensureCapacity self->capacity = newCapacity; stringSelf->text = newText; return 0;}inline static int __ensureCapacity(struct WMutableString *const self, UInteger minCapacity) { if ( minCapacity > self->capacity ) return __grow(self, minCapacity); return 0;}inline static char *__wideToCharConverter(const wchar_t *restrict wideContent) { if ( wideContent == NULL ) return errno = EINVAL, (char *)NULL; size_t charContentSize = wcstombs(NULL, wideContent, 0); if ( charContentSize == (size_t)-1 ) return errno = 0, NULL; char *restrict charContent = calloc(charContentSize+1, sizeof(char)); if ( charContent == NULL ) return errno = ENOMEM, (char *)NULL; charContentSize = wcstombs(charContent, wideContent, charContentSize); if ( charContentSize == (size_t)-1 ) return free(charContent), errno = 0, (char *)NULL; return charContent;}inline static wchar_t *__charToWideConverter(const char *restrict charContent) { if ( charContent == NULL ) return errno = EINVAL, (wchar_t *)NULL; size_t wideContentSize = mbstowcs(NULL, charContent, 0);
开发者ID:averello,项目名称:cobj,代码行数:31,
示例14: PasswordFilter//.........这里部分代码省略......... CT_CTYPE1, Password->Buffer, cchPassword, CharType )) { for(i = 0 ; i < cchPassword ; i++) { // // keep track of what type of characters we have encountered // if(CharType[i] & C1_DIGIT) { dwNum = 1; continue; } if(CharType[i] & C1_UPPER) { dwUpper = 1; continue; } if(CharType[i] & C1_LOWER) { dwLower = 1; continue; } } // for // // Indicate whether we encountered enough password complexity // if( (dwNum + dwLower + dwUpper) < 2) { bComplex = FALSE ; goto end ; } else { // // now we resort to more complex checking // wcstombs(_password, Password->Buffer, PWLEN+1) ; wcstombs(_username, UserName->Buffer, UNLEN+1) ; wcstombs(_fullname, FullName->Buffer, 1+FullName->Length/sizeof(WCHAR)) ; _strupr(_password) ; _password[Password->Length/sizeof(WCHAR)] = '/0' ; _strupr(_username) ; _username[UserName->Length/sizeof(WCHAR)] = '/0' ; _strupr(_fullname) ; _fullname[FullName->Length/sizeof(WCHAR)] = '/0' ; if (strpbrk (_password, "(`[email C++ wcstring函数代码示例 C++ wcstol函数代码示例
|