BOOL IsUrlSchemeSupportedW(LPCWSTR pszUrl) { static const struct SCHEME { LPCWSTR pszPrefix; int iLen; } _aSchemes[] = { #define SCHEME_ENTRY(prefix) { prefix, ARRSIZE(prefix)-1 } SCHEME_ENTRY(L"ed2k://") #undef SCHEME_ENTRY }; for (int i = 0; i < ARRSIZE(_aSchemes); i++) { if (wcsncmp(pszUrl, _aSchemes[i].pszPrefix, _aSchemes[i].iLen) == 0) return TRUE; } return FALSE; }
int main(int argc, char *argv[]) { struct sigaction action; sigset_t s_set; int n; pagesize = sysconf(_SC_PAGESIZE); stacksize = default_stacksize; heapsize = default_heapsize; for (n = 1; n < argc; n++) if ((*argv[n] == '-') && (*(argv[n]+2) == 0)) switch (*(argv[n]+1)) { case 'h': /* heap size option */ argv[n] = (char *)NULL; if (++n == argc) usage_error(argv[0]); heapsize = atoi(argv[n]); if (heapsize <= 0) usage_error(argv[0]); break; case 's': /* stack size option */ argv[n] = (char *)NULL; if (++n == argc) usage_error(argv[0]); stacksize = atoi(argv[n]); if (stacksize <= 0) usage_error(argv[0]); break; default: usage_error(argv[0]); } else usage_error(argv[0]); /* round stack and heap sizes to even pages */ stacksize = ((stacksize + pagesize - 1) / pagesize) * pagesize; heapsize = ((heapsize + pagesize - 1) / pagesize) * pagesize; stack = guarded_area(stacksize); heap = guarded_area(heapsize); /* Set up segmentation fault signal handler to catch stack and heap * overflow and some memory faults */ sigemptyset(&s_set); #ifdef __linux__ action.sa_handler = (void *)segv_handler; action.sa_flags = SA_RESETHAND; #else action.sa_sigaction = segv_handler; action.sa_flags = SA_SIGINFO | SA_RESETHAND; #endif action.sa_mask = s_set; if (sigaction(SIGSEGV, &action, NULL)) { fprintf(stderr, "sigaction failed: %s\n", strerror(errno)); fprintf(stderr, " overflow checking may not work\n"); } /* Set up bus error signal handler to catch remaining memory faults */ sigemptyset(&s_set); action.sa_handler = bus_handler; action.sa_mask = s_set; action.sa_flags = SA_RESETHAND; if (sigaction(SIGBUS, &action, NULL)) { fprintf(stderr, "sigaction failed: %s\n", strerror(errno)); } /* run the Scheme program and print the result */ print(SCHEME_ENTRY(stack, heap)); printf("\n"); return 0; }