int numxcmp(const number * lhs,const number * rhs){ if(!lhs && !rhs) return 0; if(!lhs) return -1; if(!rhs) return 1; int c = ncmp(lhs->lx,rhs->lx); if(c == 0) c = ncmp(lhs->rx,rhs->rx); return c; }
static Bool StrUtilHasListItem(char const *list, // IN: char delim, // IN: char const *item, // IN: int (*ncmp)(char const *, char const*, size_t)) // IN: { char *foundDelim; int itemLen = strlen(item); if (list == NULL) { return FALSE; } do { int tokenLen; foundDelim = strchr(list, delim); if (foundDelim == NULL) { // either single or last element tokenLen = strlen(list); } else { // ! last element tokenLen = foundDelim - list; } if (itemLen == tokenLen && ncmp(item, list, itemLen) == 0) { return TRUE; } else if (foundDelim != NULL) { // ! last element list = foundDelim + 1; } } while (foundDelim != NULL); return FALSE; }
static int field_cmp(Field *f1, Field *f2) { size_t n = Min(f1->n, f2->n); int c1 = memcmp(f1->data, f2->data, n); if (c1 == 0) return ncmp(f1->n, f2->n); return c1; }
static void getnexp(ul_number n, ul_number *mantissa, int *exp) { bool neg = false; if (n < 0) { neg = true; n = -n; } if ((ncmp(n, 10.0) == -1) && (ncmp(n, 1.0) == 1)) { *mantissa = neg ? -n : n; *exp = 0; return; } else if (ncmp(n, 10.0) > -1) { int e = 0; do { e++; n /= 10; } while (ncmp(n, 10.0) == 1); *exp = e; *mantissa = neg ? -n : n; } else if (ncmp(n, 1.0) < 1) { int e = 0; while (ncmp(n, 1.0) == -1) { e--; n *= 10; } *exp = e; *mantissa = neg ? -n : n; } }
UL_API ul_cmpres_t ul_cmp(const unit_t *a, const unit_t *b) { if (!a || !b) { ERROR("Invalid parameters"); return UL_ERROR; } int res = UL_SAME_UNIT; for (int i=0; i < NUM_BASE_UNITS; ++i) { if (a->exps[i] != b->exps[i]) { res = 0; break; } } if (ncmp(a->factor, b->factor) == 0) { res |= UL_SAME_FACTOR; } return res; }
/** * Validate and establish the destination name of an incoming file. * Returns 0 if the file was rejected for some reason, 1 otherwise. */ int setup_dest_file(struct group_list_t *group) { int found_dest_dir, len, i; int (*cmp)(const char *, const char *); int (*ncmp)(const char *, const char *, size_t); #if PATH_SEP != '/' // First translate any '/' in the sent file name to PATH_SEP { char *p; while ((p = strchr(group->fileinfo.name, '/')) != NULL) { *p = PATH_SEP; } } #endif #ifdef WINDOWS cmp = stricmp; ncmp = strnicmp; #else cmp = strcmp; ncmp = strncmp; #endif if (isfullpath(group->fileinfo.name)) { if (strcmp(tempdir, "")) { glog1(group, "Rejecting file with absolute pathname: " "temp directory is in use"); early_complete(group, COMP_STAT_REJECTED, 0); return 0; } for (found_dest_dir = 0, i = 0; i < destdircnt; i++) { if (!ncmp(group->fileinfo.name, destdir[i], strlen(destdir[i]))) { if (!cmp(group->fileinfo.name, destdir[i])) { glog1(group, "Rejecting file with absolute pathname: " "can't have the same name as a dest directory"); early_complete(group, COMP_STAT_REJECTED, 0); return 0; } else { found_dest_dir = 1; break; } } } if (!found_dest_dir) { glog1(group, "Rejecting file with absolute pathname: " "doesn't match any dest directory"); early_complete(group, COMP_STAT_REJECTED, 0); return 0; } group->fileinfo.destdiridx = i; snprintf(group->fileinfo.filepath, sizeof(group->fileinfo.filepath), "%s", group->fileinfo.name); } else { if (!strcmp(tempdir, "")) { len = snprintf(group->fileinfo.filepath, sizeof(group->fileinfo.filepath), "%s%c%s", destdir[0], PATH_SEP, group->fileinfo.name); } else { len = snprintf(group->fileinfo.filepath, sizeof(group->fileinfo.filepath), "%s%c_group_%08X%c%s", tempdir, PATH_SEP, group->group_id, PATH_SEP, group->fileinfo.name); } if (len >= sizeof(group->fileinfo.filepath)) { glog1(group, "Rejecting file: max pathname length exceeded"); early_complete(group, COMP_STAT_REJECTED, 0); return 0; } } len = snprintf(group->fileinfo.temppath, sizeof(group->fileinfo.temppath), "%s.~uftp-%08X-%04X", group->fileinfo.filepath, group->group_id, group->file_id); if (len >= sizeof(group->fileinfo.temppath)) { glog1(group, "Rejecting file: max pathname length exceeded"); early_complete(group, COMP_STAT_REJECTED, 0); return 0; } return 1; }
int a_max(int i,int j){ return ncmp(a[i],a[j]) >= 0?i:j; }
bool startswithex(const _TCHAR *s, const _TCHAR *s2, size_t count) { assert(count <= _tcslen(s2)); return ncmp(s, s2, count) == 0; }
inline bool GBString::compareToCharString( const GBStringconst_iterator & iter, const char * aCharString,int len) const { return ncmp(_string.chars()+iter.place(), len,aCharString,slen(aCharString))==0; };
inline bool GBString::compareToCharString(const char * aCharString,int len) const { return ncmp(_string.chars(),len, aCharString,slen(aCharString))==0; };