ATF_TC_BODY(wcscasecmp_equal, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"abc", L"abc") == 0); ATF_CHECK(wcscasecmp(L"ABC", L"ABC") == 0); ATF_CHECK(wcscasecmp(L"abc", L"ABC") == 0); ATF_CHECK(wcscasecmp(L"ABC", L"abc") == 0); }
ATF_TC_BODY(wcscasecmp_mismatched_len_buffers, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"abc", L"ABCD") < 0); ATF_CHECK(wcscasecmp(L"ABC", L"abcd") < 0); ATF_CHECK(wcscasecmp(L"abcd", L"ABC") > 0); ATF_CHECK(wcscasecmp(L"ABCD", L"abc") > 0); }
/* * stress_wcscasecmp() * stress on wcscasecmp */ static void stress_wcscasecmp( const char *name, wchar_t *str1, const size_t len1, wchar_t *str2, const size_t len2) { register size_t i; (void)len2; for (i = 1; i < len1; i++) { WCSCHK(name, 0 == wcscasecmp(str1, str1)); WCSCHK(name, 0 == wcscasecmp(str2, str2)); WCSCHK(name, 0 != wcscasecmp(str2, str1)); WCSCHK(name, 0 != wcscasecmp(str1, str2)); WCSCHK(name, 0 != wcscasecmp(str1 + i, str1)); WCSCHK(name, 0 != wcscasecmp(str1, str1 + i)); WCSCHK(name, 0 == wcscasecmp(str1 + i, str1 + i)); WCSCHK(name, 0 != wcscasecmp(str1 + i, str2)); WCSCHK(name, 0 != wcscasecmp(str2, str1 + i)); } }
ATF_TC_BODY(wcscasecmp_greek, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"λ", L"Λ") != 0); ATF_REQUIRE(setlocale(LC_CTYPE, "el_GR.UTF-8") != NULL); ATF_CHECK(wcscasecmp(L"λ", L"Λ") == 0); ATF_CHECK(wcscasecmp(L"λ", L"Ω") < 0); ATF_CHECK(wcscasecmp(L"Ω", L"λ") > 0); }
bool rgb_color_t::try_parse_special(const wcstring &special) { bzero(&data, sizeof data); const wchar_t *name = special.c_str(); if (! wcscasecmp(name, L"normal")) { this->type = type_normal; } else if (! wcscasecmp(name, L"reset")) { this->type = type_reset; } else if (! wcscasecmp(name, L"ignore")) { this->type = type_ignore; } else { this->type = type_none; } return this->type != type_none; }
IAPEDecompress * __stdcall CreateIAPEDecompress(const str_utf16 * pFilename, int * pErrorCode) { // error check the parameters if ((pFilename == NULL) || (wcslen(pFilename) == 0)) { if (pErrorCode) *pErrorCode = ERROR_BAD_PARAMETER; return NULL; } // variables int nErrorCode = ERROR_UNDEFINED; CAPEInfo * pAPEInfo = NULL; int nStartBlock = -1; int nFinishBlock = -1; // get the extension const str_utf16 * pExtension = &pFilename[wcslen(pFilename)]; while ((pExtension > pFilename) && (*pExtension != '.')) pExtension--; // take the appropriate action (based on the extension) if (wcscasecmp(pExtension, L".apl") == 0) { // "link" file (.apl linked large APE file) CAPELink APELink(pFilename); if (APELink.GetIsLinkFile()) { pAPEInfo = new CAPEInfo(&nErrorCode, APELink.GetImageFilename(), new CAPETag(pFilename, TRUE)); nStartBlock = APELink.GetStartBlock(); nFinishBlock = APELink.GetFinishBlock(); } } else if ((wcscasecmp(pExtension, L".mac") == 0) || (wcscasecmp(pExtension, L".ape") == 0)) { // plain .ape file pAPEInfo = new CAPEInfo(&nErrorCode, pFilename); } // fail if we couldn't get the file information if (pAPEInfo == NULL) { if (pErrorCode) *pErrorCode = ERROR_INVALID_INPUT_FILE; return NULL; } // create and return IAPEDecompress * pAPEDecompress = CreateIAPEDecompressCore(pAPEInfo, nStartBlock, nFinishBlock, &nErrorCode); if (pErrorCode) *pErrorCode = nErrorCode; return pAPEDecompress; }
static TACommandVerdict wcscasecmp_cmd(TAThread thread,TAInputStream stream) { int res; wchar_t *s1; wchar_t *s2; // Prepare s1 = ta_wcsalign(readWString(&stream)); //align on copy s2 = ta_wcsalign(readWString(&stream)); //align on copy START_TARGET_OPERATION(thread); res = wcscasecmp(s1, s2); END_TARGET_OPERATION(thread); // Response writeInt(thread,res); sendResponse(thread); ta_dealloc_memory(s1); ta_dealloc_memory(s2); return taDefaultVerdict; }
bool is_process_running(WCHAR * process_name) { DWORD *pid_list, pid_list_size; DWORD index; BOOL found_process = FALSE; pid_list = enumerate_processes(&pid_list_size); if (!pid_list) { return FALSE; } for (index = 0; index < pid_list_size; index++) { WCHAR process_name2[MAX_PATH]; if (get_process_name_from_pid (pid_list[index], process_name2, MAX_PATH) == TRUE && !wcscasecmp(process_name2, process_name)) { struct pid_close_info info = { pid_list[index] }; found_process = TRUE; EnumWindows(pid_enum_proc, (LPARAM) & info); } } return found_process; }
int FdoCommonOSUtil::wcsicmp(const wchar_t *s1, const wchar_t *s2) { #ifdef _WIN32 return _wcsicmp(s1, s2); #else return wcscasecmp(s1, s2); #endif }
ATF_TC_BODY(nul, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"", L"") == 0); ATF_CHECK(wcsncasecmp(L"", L"", 50) == 0); ATF_CHECK(wcsncasecmp(L"", L"", 0) == 0); }
int CUIString::CompareNoCase(LPCWSTR lpsz) const { #ifndef WIN32 return wcscasecmp(m_pstr, lpsz); #else return wcsicmp(m_pstr, lpsz); #endif // WIN32 }
CSqlField* COracleRecordset::operator[](const char *item) const { cvs::wide _item(item); CServerIo::trace(1,"Return an array [char *]"); for(size_t n=0; n<(size_t)m_num_fields; n++) if(!wcscasecmp(m_sqlfields[n].name.c_str(),_item)) return (CSqlField*)&m_sqlfields[n]; CServerIo::error("Database error - field '%s' not found in recordset.",item); return NULL; }
tb_long_t tb_wcsicmp(tb_wchar_t const* s1, tb_wchar_t const* s2) { // check tb_assert_and_check_return_val(s1 && s2, 0); # ifdef TB_COMPILER_IS_MSVC return _wcsicmp(s1, s2); # else return wcscasecmp(s1, s2); # endif }
bool rgb_color_t::try_parse_named(const wcstring &str) { bzero(&data, sizeof data); size_t max = sizeof named_colors / sizeof *named_colors; for (size_t idx=0; idx < max; idx++) { if (0 == wcscasecmp(str.c_str(), named_colors[idx].name)) { data.name_idx = named_colors[idx].idx; this->type = type_named; return true; } } return false; }
ATF_TC_BODY(wcscasecmp_same_len_buffers, tc) { ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); ATF_CHECK(wcscasecmp(L"abc", L"xyz") < 0); ATF_CHECK(wcscasecmp(L"ABC", L"xyz") < 0); ATF_CHECK(wcscasecmp(L"abc", L"XYZ") < 0); ATF_CHECK(wcscasecmp(L"ABC", L"XYZ") < 0); ATF_CHECK(wcscasecmp(L"xyz", L"abc") > 0); ATF_CHECK(wcscasecmp(L"XYZ", L"abc") > 0); ATF_CHECK(wcscasecmp(L"xyz", L"ABC") > 0); ATF_CHECK(wcscasecmp(L"XYZ", L"ABC") > 0); }
BOOL IsMMFile(const wchar_t* fname) { wchar_t extlist[1024], *ext; if(!wcscasecmp(fname,L"cdaudio") || !ext_cmp(fname,L"pcb")) return 1; GetProfileString(L"mci extensions", NULL, L"", extlist, _countof(extlist)); for(ext=extlist; *ext; ++ext) { if(!ext_cmp(fname,ext)) return 1; while(*++ext); } return 0; }
int CAPETag::GetTagFieldIndex(const str_utf16 * pFieldName) { if (m_bAnalyzed == FALSE) { Analyze(); } if (pFieldName == NULL) return -1; for (int z = 0; z < m_nFields; z++) { if (wcscasecmp(m_aryFields[z]->GetFieldName(), pFieldName) == 0) return z; } return -1; }
int CAPETag::CreateID3Tag(ID3_TAG * pID3Tag) { // error check if (pID3Tag == NULL) { return -1; } if (m_bAnalyzed == FALSE) { Analyze(); } if (m_nFields == 0) { return -1; } // empty ZeroMemory(pID3Tag, ID3_TAG_BYTES); // header pID3Tag->Header[0] = 'T'; pID3Tag->Header[1] = 'A'; pID3Tag->Header[2] = 'G'; // standard fields GetFieldID3String(APE_TAG_FIELD_ARTIST, pID3Tag->Artist, 30); GetFieldID3String(APE_TAG_FIELD_ALBUM, pID3Tag->Album, 30); GetFieldID3String(APE_TAG_FIELD_TITLE, pID3Tag->Title, 30); GetFieldID3String(APE_TAG_FIELD_COMMENT, pID3Tag->Comment, 28); GetFieldID3String(APE_TAG_FIELD_YEAR, pID3Tag->Year, 4); // track number str_utf16 cBuffer[256] = { 0 }; int nBufferCharacters = 255; GetFieldString(APE_TAG_FIELD_TRACK, cBuffer, &nBufferCharacters); pID3Tag->Track = (unsigned char) wcstol(cBuffer,NULL,0); // genre cBuffer[0] = 0; nBufferCharacters = 255; GetFieldString(APE_TAG_FIELD_GENRE, cBuffer, &nBufferCharacters); // convert the genre string to an index pID3Tag->Genre = 255; int nGenreIndex = 0; BOOL bFound = FALSE; while ((nGenreIndex < GENRE_COUNT) && (bFound == FALSE)) { if (wcscasecmp(cBuffer, g_ID3Genre[nGenreIndex]) == 0) { pID3Tag->Genre = nGenreIndex; bFound = TRUE; } nGenreIndex++; } return ERROR_SUCCESS; }
/* --------------------------------------------------------------------- * ExpGetEntry * Searches the list for an entry with the name 'name'. If the entry * can't be found, NULL is returned. * --------------------------------------------------------------------- */ static EXPENTRY* ExpGetEntry (EXPFILE* expfile, const wchar_t* name) { EXPENTRY* workptr = expfile->FirstExp; const wchar_t* cmpname = name; if (wcsstr(name, _T("WARN_")) == name) cmpname += 5; /* ignore "WARN_" prefix */ while (workptr) { if (wcscasecmp(workptr->Name, cmpname) == 0) { return workptr; } workptr = (EXPENTRY*) workptr->Next; } return NULL; }
int wcsicmp(const wchar_t *s1, const wchar_t *s2) { //#ifdef __APPLE__ // enable this workaround on all platforms, instead of // specifying which platforms don't have wcscasecmp #if 1 int i; for (i = 0; s1[i] != L'\0' && s2[i] != L'\0'; i++) { wint_t x = towlower(s1[i]); wint_t y = towlower(s2[i]); if (x != y) return x - y; } return towlower(s1[i]) - towlower(s2[i]); #else return(wcscasecmp(s1, s2)); #endif }
/// Test if \c name is a string describing the signal named \c canonical. static int match_signal_name(const wchar_t *canonical, const wchar_t *name) { if (wcsncasecmp(name, L"sig", 3) == 0) name += 3; return wcscasecmp(canonical + 3, name) == 0; }
static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { const wchar_t *cmd = L"function"; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'd': { opts.description = w.woptarg; break; } case 's': { int sig = wcs2sig(w.woptarg); if (sig == -1) { streams.err.append_format(_(L"%ls: Unknown signal '%ls'"), cmd, w.woptarg); return STATUS_INVALID_ARGS; } opts.events.push_back(event_t::signal_event(sig)); break; } case 'v': { if (!valid_var_name(w.woptarg)) { streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, w.woptarg); return STATUS_INVALID_ARGS; } opts.events.push_back(event_t::variable_event(w.woptarg)); break; } case 'e': { opts.events.push_back(event_t::generic_event(w.woptarg)); break; } case 'j': case 'p': { pid_t pid; event_t e(EVENT_ANY); if ((opt == 'j') && (wcscasecmp(w.woptarg, L"caller") == 0)) { job_id_t job_id = -1; if (is_subshell) { size_t block_idx = 0; // Find the outermost substitution block. for (block_idx = 0;; block_idx++) { const block_t *b = parser.block_at_index(block_idx); if (b == NULL || b->type() == SUBST) break; } // Go one step beyond that, to get to the caller. const block_t *caller_block = parser.block_at_index(block_idx + 1); if (caller_block != NULL && caller_block->job != NULL) { job_id = caller_block->job->job_id; } } if (job_id == -1) { streams.err.append_format( _(L"%ls: Cannot find calling job for event handler"), cmd); return STATUS_INVALID_ARGS; } e.type = EVENT_JOB_ID; e.param1.job_id = job_id; } else { pid = fish_wcstoi(w.woptarg); if (errno || pid < 0) { streams.err.append_format(_(L"%ls: Invalid process id '%ls'"), cmd, w.woptarg); return STATUS_INVALID_ARGS; } e.type = EVENT_EXIT; e.param1.pid = (opt == 'j' ? -1 : 1) * abs(pid); } opts.events.push_back(e); break; } case 'a': { opts.named_arguments.push_back(w.woptarg); break; } case 'S': { opts.shadow_scope = false; break; } case 'w': { opts.wrap_targets.push_back(w.woptarg); break; } case 'V': { if (!valid_var_name(w.woptarg)) { streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, w.woptarg); return STATUS_INVALID_ARGS; } opts.inherit_vars.push_back(w.woptarg); break; } case 'h': { opts.print_help = true; break; } case ':': { builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { DIE("unexpected retval from wgetopt_long"); break; } } } *optind = w.woptind; return STATUS_CMD_OK; }
int main(int argc, char *argv[]) { printf("1..6\n"); setlocale(LC_CTYPE, "C"); assert(wcscasecmp(L"", L"") == 0); assert(wcsncasecmp(L"", L"", 50) == 0); assert(wcsncasecmp(L"", L"", 0) == 0); printf("ok 1 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"abc") == 0); assert(wcscasecmp(L"ABC", L"ABC") == 0); assert(wcscasecmp(L"abc", L"ABC") == 0); assert(wcscasecmp(L"ABC", L"abc") == 0); printf("ok 2 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"xyz") < 0); assert(wcscasecmp(L"ABC", L"xyz") < 0); assert(wcscasecmp(L"abc", L"XYZ") < 0); assert(wcscasecmp(L"ABC", L"XYZ") < 0); assert(wcscasecmp(L"xyz", L"abc") > 0); assert(wcscasecmp(L"XYZ", L"abc") > 0); assert(wcscasecmp(L"xyz", L"ABC") > 0); assert(wcscasecmp(L"XYZ", L"ABC") > 0); printf("ok 3 - wcscasecmp\n"); assert(wcscasecmp(L"abc", L"ABCD") < 0); assert(wcscasecmp(L"ABC", L"abcd") < 0); assert(wcscasecmp(L"abcd", L"ABC") > 0); assert(wcscasecmp(L"ABCD", L"abc") > 0); printf("ok 4 - wcscasecmp\n"); assert(wcsncasecmp(L"abc", L"ABCD", 4) < 0); assert(wcsncasecmp(L"ABC", L"abcd", 4) < 0); assert(wcsncasecmp(L"abcd", L"ABC", 4) > 0); assert(wcsncasecmp(L"ABCD", L"abc", 4) > 0); assert(wcsncasecmp(L"abc", L"ABCD", 3) == 0); assert(wcsncasecmp(L"ABC", L"abcd", 3) == 0); printf("ok 5 - wcsncasecmp\n"); assert(wcscasecmp(L"λ", L"Λ") != 0); setlocale(LC_CTYPE, "el_GR.UTF-8"); assert(wcscasecmp(L"λ", L"Λ") == 0); assert(wcscasecmp(L"λ", L"Ω") < 0); assert(wcscasecmp(L"Ω", L"λ") > 0); printf("ok 6 - greek\n"); exit(0); }
int test_implicit_compare_with_functions() { if (memcmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memcmp' is called without explicitly comparing result // CHECK-FIXES: memcmp(A, "a", 1) != 0) if (wmemcmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wmemcmp' is called without explicitly comparing result // CHECK-FIXES: wmemcmp(W, L"a", 1) != 0) if (memicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memicmp' is called without explicitly comparing result // CHECK-FIXES: memicmp(A, "a", 1) != 0) if (_memicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp' is called without explicitly comparing result // CHECK-FIXES: _memicmp(A, "a", 1) != 0) if (_memicmp_l(A, "a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp_l' is called without explicitly comparing result // CHECK-FIXES: _memicmp_l(A, "a", 1, locale) != 0) if (strcmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmp' is called without explicitly comparing result // CHECK-FIXES: strcmp(A, "a") != 0) if (strncmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncmp' is called without explicitly comparing result // CHECK-FIXES: strncmp(A, "a", 1) != 0) if (strcasecmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcasecmp' is called without explicitly comparing result // CHECK-FIXES: strcasecmp(A, "a") != 0) if (strncasecmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncasecmp' is called without explicitly comparing result // CHECK-FIXES: strncasecmp(A, "a", 1) != 0) if (stricmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'stricmp' is called without explicitly comparing result // CHECK-FIXES: stricmp(A, "a") != 0) if (strcmpi(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmpi' is called without explicitly comparing result // CHECK-FIXES: strcmpi(A, "a") != 0) if (_stricmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp' is called without explicitly comparing result // CHECK-FIXES: _stricmp(A, "a") != 0) if (strnicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strnicmp' is called without explicitly comparing result // CHECK-FIXES: strnicmp(A, "a", 1) != 0) if (_strnicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp' is called without explicitly comparing result // CHECK-FIXES: _strnicmp(A, "a", 1) != 0) if (_stricmp_l(A, "a", locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp_l' is called without explicitly comparing result // CHECK-FIXES: _stricmp_l(A, "a", locale) != 0) if (_strnicmp_l(A, "a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp_l' is called without explicitly comparing result // CHECK-FIXES: _strnicmp_l(A, "a", 1, locale) != 0) if (wcscmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscmp' is called without explicitly comparing result // CHECK-FIXES: wcscmp(W, L"a") != 0) if (wcsncmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsncmp' is called without explicitly comparing result // CHECK-FIXES: wcsncmp(W, L"a", 1) != 0) if (wcscasecmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscasecmp' is called without explicitly comparing result // CHECK-FIXES: wcscasecmp(W, L"a") != 0) if (wcsicmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsicmp' is called without explicitly comparing result // CHECK-FIXES: wcsicmp(W, L"a") != 0) if (_wcsicmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp' is called without explicitly comparing result // CHECK-FIXES: _wcsicmp(W, L"a") != 0) if (_wcsicmp_l(W, L"a", locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp_l' is called without explicitly comparing result // CHECK-FIXES: _wcsicmp_l(W, L"a", locale) != 0) if (wcsnicmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsnicmp' is called without explicitly comparing result // CHECK-FIXES: wcsnicmp(W, L"a", 1) != 0) if (_wcsnicmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp' is called without explicitly comparing result // CHECK-FIXES: _wcsnicmp(W, L"a", 1) != 0) if (_wcsnicmp_l(W, L"a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp_l' is called without explicitly comparing result // CHECK-FIXES: _wcsnicmp_l(W, L"a", 1, locale) != 0) if (_mbscmp(U, V)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp' is called without explicitly comparing result // CHECK-FIXES: _mbscmp(U, V) != 0) if (_mbsncmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp' is called without explicitly comparing result // CHECK-FIXES: _mbsncmp(U, V, 1) != 0) if (_mbsnbcmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp' is called without explicitly comparing result // CHECK-FIXES: _mbsnbcmp(U, V, 1) != 0) if (_mbsnbicmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp' is called without explicitly comparing result // CHECK-FIXES: _mbsnbicmp(U, V, 1) != 0) if (_mbsicmp(U, V)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp' is called without explicitly comparing result // CHECK-FIXES: _mbsicmp(U, V) != 0) if (_mbsnicmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp' is called without explicitly comparing result // CHECK-FIXES: _mbsnicmp(U, V, 1) != 0) if (_mbscmp_l(U, V, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbscmp_l(U, V, locale) != 0) if (_mbsncmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbsncmp_l(U, V, 1, locale) != 0) if (_mbsicmp_l(U, V, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbsicmp_l(U, V, locale) != 0) if (_mbsnicmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbsnicmp_l(U, V, 1, locale) != 0) if (_mbsnbcmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbsnbcmp_l(U, V, 1, locale) != 0) if (_mbsnbicmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp_l' is called without explicitly comparing result // CHECK-FIXES: _mbsnbicmp_l(U, V, 1, locale) != 0) return 1; }
/// The ulimit builtin, used for setting resource limits. int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); bool report_all = false; bool hard = false; bool soft = false; int what = RLIMIT_FSIZE; const wchar_t *short_options = L":HSacdflmnstuvh"; const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, {L"hard", no_argument, NULL, 'H'}, {L"soft", no_argument, NULL, 'S'}, {L"core-size", no_argument, NULL, 'c'}, {L"data-size", no_argument, NULL, 'd'}, {L"file-size", no_argument, NULL, 'f'}, {L"lock-size", no_argument, NULL, 'l'}, {L"resident-set-size", no_argument, NULL, 'm'}, {L"file-descriptor-count", no_argument, NULL, 'n'}, {L"stack-size", no_argument, NULL, 's'}, {L"cpu-time", no_argument, NULL, 't'}, {L"process-count", no_argument, NULL, 'u'}, {L"virtual-memory-size", no_argument, NULL, 'v'}, {L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'a': { report_all = true; break; } case 'H': { hard = true; break; } case 'S': { soft = true; break; } case 'c': { what = RLIMIT_CORE; break; } case 'd': { what = RLIMIT_DATA; break; } case 'f': { what = RLIMIT_FSIZE; break; } #ifdef RLIMIT_MEMLOCK case 'l': { what = RLIMIT_MEMLOCK; break; } #endif #ifdef RLIMIT_RSS case 'm': { what = RLIMIT_RSS; break; } #endif case 'n': { what = RLIMIT_NOFILE; break; } case 's': { what = RLIMIT_STACK; break; } case 't': { what = RLIMIT_CPU; break; } #ifdef RLIMIT_NPROC case 'u': { what = RLIMIT_NPROC; break; } #endif #ifdef RLIMIT_AS case 'v': { what = RLIMIT_AS; break; } #endif case 'h': { builtin_print_help(parser, streams, cmd, streams.out); return 0; } case ':': { streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); return STATUS_BUILTIN_ERROR; } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_BUILTIN_ERROR; } default: { DIE("unexpected retval from wgetopt_long"); break; } } } if (report_all) { print_all(hard, streams); return STATUS_BUILTIN_OK; } int arg_count = argc - w.woptind; if (arg_count == 0) { // Show current limit value. print(what, hard, streams); return STATUS_BUILTIN_OK; } else if (arg_count != 1) { streams.err.append_format(BUILTIN_ERR_TOO_MANY_ARGUMENTS, cmd); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_BUILTIN_ERROR; } // Change current limit value. if (!hard && !soft) { // Set both hard and soft limits if neither was specified. hard = soft = true; } rlim_t new_limit; if (*argv[w.woptind] == L'\0') { streams.err.append_format(_(L"%ls: New limit cannot be an empty string\n"), cmd); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_BUILTIN_ERROR; } else if (wcscasecmp(argv[w.woptind], L"unlimited") == 0) { new_limit = RLIM_INFINITY; } else if (wcscasecmp(argv[w.woptind], L"hard") == 0) { new_limit = get(what, 1); } else if (wcscasecmp(argv[w.woptind], L"soft") == 0) { new_limit = get(what, soft); } else { new_limit = fish_wcstol(argv[w.woptind]); if (errno) { streams.err.append_format(_(L"%ls: Invalid limit '%ls'\n"), cmd, argv[w.woptind]); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_BUILTIN_ERROR; } new_limit *= get_multiplier(what); } return set_limit(what, hard, soft, new_limit, streams); }
/// The ulimit builtin, used for setting resource limits. int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wgetopter_t w; int hard = 0; int soft = 0; int what = RLIMIT_FSIZE; int report_all = 0; int argc = builtin_count_args(argv); w.woptind = 0; while (1) { static const struct woption long_options[] = { {L"all", no_argument, 0, 'a'}, {L"hard", no_argument, 0, 'H'}, {L"soft", no_argument, 0, 'S'}, {L"core-size", no_argument, 0, 'c'}, {L"data-size", no_argument, 0, 'd'}, {L"file-size", no_argument, 0, 'f'}, {L"lock-size", no_argument, 0, 'l'}, {L"resident-set-size", no_argument, 0, 'm'}, {L"file-descriptor-count", no_argument, 0, 'n'}, {L"stack-size", no_argument, 0, 's'}, {L"cpu-time", no_argument, 0, 't'}, {L"process-count", no_argument, 0, 'u'}, {L"virtual-memory-size", no_argument, 0, 'v'}, {L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; int opt_index = 0; int opt = w.wgetopt_long(argc, argv, L"aHScdflmnstuvh", long_options, &opt_index); if (opt == -1) break; switch (opt) { case 0: { if (long_options[opt_index].flag != 0) break; streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0], long_options[opt_index].name); builtin_print_help(parser, streams, argv[0], streams.err); return 1; } case L'a': { report_all = 1; break; } case L'H': { hard = 1; break; } case L'S': { soft = 1; break; } case L'c': { what = RLIMIT_CORE; break; } case L'd': { what = RLIMIT_DATA; break; } case L'f': { what = RLIMIT_FSIZE; break; } #ifdef RLIMIT_MEMLOCK case L'l': { what = RLIMIT_MEMLOCK; break; } #endif #ifdef RLIMIT_RSS case L'm': { what = RLIMIT_RSS; break; } #endif case L'n': { what = RLIMIT_NOFILE; break; } case L's': { what = RLIMIT_STACK; break; } case L't': { what = RLIMIT_CPU; break; } #ifdef RLIMIT_NPROC case L'u': { what = RLIMIT_NPROC; break; } #endif #ifdef RLIMIT_AS case L'v': { what = RLIMIT_AS; break; } #endif case L'h': { builtin_print_help(parser, streams, argv[0], streams.out); return 0; } case L'?': { builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); return 1; } } } if (report_all) { if (argc - w.woptind == 0) { print_all(hard, streams); } else { streams.err.append(argv[0]); streams.err.append(L": Too many arguments\n"); builtin_print_help(parser, streams, argv[0], streams.err); return 1; } return 0; } switch (argc - w.woptind) { case 0: { // show current limit value print(what, hard, streams); break; } case 1: { // change current limit value rlim_t new_limit; wchar_t *end; // Set both hard and soft limits if nothing else was specified. if (!(hard + soft)) { hard = soft = 1; } if (wcscasecmp(argv[w.woptind], L"unlimited") == 0) { new_limit = RLIM_INFINITY; } else if (wcscasecmp(argv[w.woptind], L"hard") == 0) { new_limit = get(what, 1); } else if (wcscasecmp(argv[w.woptind], L"soft") == 0) { new_limit = get(what, soft); } else { errno = 0; new_limit = wcstol(argv[w.woptind], &end, 10); if (errno || *end) { streams.err.append_format(L"%ls: Invalid limit '%ls'\n", argv[0], argv[w.woptind]); builtin_print_help(parser, streams, argv[0], streams.err); return 1; } new_limit *= get_multiplier(what); } return set(what, hard, soft, new_limit, streams); } default: { streams.err.append(argv[0]); streams.err.append(L": Too many arguments\n"); builtin_print_help(parser, streams, argv[0], streams.err); return 1; } } return 0; }
int wcscasecmp_l(const wchar_t* ws1, const wchar_t* ws2, locale_t) { return wcscasecmp(ws1, ws2); }