Ticket #8791: missing.patch
File missing.patch, 6.1 KB (added by , 17 years ago) |
---|
-
backends/platform/wince/missing/missing.cpp
40 40 41 41 void *bsearch(const void *key, const void *base, size_t nmemb, 42 42 size_t size, int (*compar)(const void *, const void *)) { 43 size_t i; 43 // Perform binary search 44 size_t lo = 0; 45 size_t hi = nmemb; 46 while (lo < hi) { 47 size_t mid = (lo + hi) / 2; 48 const void *p = ((const char *)base) + mid * size; 49 int tmp = (*compar)(key, p); 50 if (tmp < 0) 51 hi = mid; 52 else if (tmp > 0) 53 lo = mid + 1; 54 else 55 return (void *)p; 56 } 44 57 45 for (i=0; i<nmemb; i++)46 if (compar(key, (void*)((size_t)base + size * i)) == 0)47 return (void*)((size_t)base + size * i);48 58 return NULL; 49 59 } 50 60 … … 319 329 return 1; 320 330 } 321 331 322 /* in our case unlink is the same as remove */323 int unlink(const char* path)324 {325 return remove(path);326 }327 328 332 /* Make directory, Unix style */ 329 333 void mkdir(char* dirname, int mode) 330 334 { … … 349 353 CreateDirectory(pathUnc, 0); 350 354 } 351 355 352 /* Used in DEVICES.C and UI.C for some purpose. Not critical in this port */353 int system(const char* path) { return 0; }354 355 #if 0356 357 char *tmpnam(char *string)358 {359 TCHAR pTemp[MAX_PATH+1];360 static char buffer[MAX_PATH+1];361 GetTempFileName(TEXT("."), TEXT("A8_"), 0, pTemp);362 WideCharToMultiByte(CP_ACP, 0, pTemp, -1, buffer, MAX_PATH, NULL, NULL);363 364 if (string)365 {366 strcpy(string, buffer);367 return string;368 }369 else370 return buffer;371 }372 373 FILE *tmpfile()374 {375 TCHAR pTemp[MAX_PATH+1];376 if (!GetTempFileName(TEXT("."), TEXT("A8_"), 0, pTemp))377 return _wfopen(pTemp, TEXT("w+b"));378 else379 return 0;380 }381 382 #endif383 384 void rewind(FILE *stream)385 {386 fseek(stream, 0, SEEK_SET);387 }388 389 390 356 #if _WIN32_WCE < 300 391 357 392 int isalnum(int c) {393 return ((c >= 'A' && c <= 'Z') ||394 (c >= 'a' && c <= 'z') ||395 (c >= '0' && c <= '9'));396 }397 398 358 char *_strdup(const char *strSource) 399 359 #else 400 360 char *strdup(const char *strSource) 401 361 #endif 402 362 { 403 363 char* buffer; 404 buffer = (char*)malloc(strlen(strSource)+1); 364 size_z len = strlen(strSource)+1; 365 buffer = (char*)malloc(len); 405 366 if (buffer) 406 strcpy(buffer, strSource);367 memcpy(buffer, strSource, len); 407 368 return buffer; 408 369 } 409 410 /* Very limited implementation of sys/time.h */411 void gettimeofday(struct timeval* tp, void* dummy)412 {413 DWORD dt = GetTickCount();414 tp->tv_sec = dt/1000;415 tp->tv_usec = dt*1000;416 }417 418 void usleep(long usec)419 {420 long msec = usec/1000;421 if (msec <= 0)422 Sleep(0);423 else424 Sleep(msec);425 }426 427 /* This may provide for better sync mechanism */428 unsigned int clock()429 {430 return GetTickCount();431 }432 433 /* And why do people use this? */434 #if _WIN32_WCE >= 300435 void abort()436 {437 exit(1);438 }439 370 #endif 440 371 441 /*442 IMHO, no project should use this one, it is not portable at all. This implementation443 at least allows some projects to work.444 */445 char* getenv(char* name)446 {447 static char buffer[MAX_PATH+1];448 if (strcmp(name, "HOME") == 0 || strcmp(name, "HOMEDIR") == 0)449 {450 getcwd(buffer, MAX_PATH);451 return buffer;452 }453 else454 return "";455 }456 457 372 #if _WIN32_WCE < 300 || defined(_TEST_HPC_STDIO) 458 373 459 374 void *calloc(size_t n, size_t s) { … … 465 380 } 466 381 467 382 char *strpbrk(const char *s, const char *accept) { 468 int i;469 470 383 if (!s || !accept) 471 384 return NULL; 472 385 473 for ( i=0; i<strlen(s); i++) {474 int j;475 for (j=0; j<strlen(accept); j++)476 if (s[i] == accept[j])477 return (char*)&s[i];386 for (; *s != 0; ++s) { 387 for (const char *a = accept; *a != 0; ++a) { 388 if (*s == *a) 389 return (char *)s; 390 } 478 391 } 479 392 480 393 return NULL; … … 486 399 return (c >='0' && c <= '9'); 487 400 } 488 401 489 int isprint(int c) {490 return (c >= ' ' && c <= '~');491 }492 493 int isspace(int c) {494 return (c == ' ');495 }496 497 402 #endif 498 403 499 404 #ifndef WIN32_PLATFORM_HPCPRO … … 643 548 644 549 #endif 645 550 646 int stricmp( const char *string1, const char *string2 ) { 647 char src[4096]; 648 char dest[4096]; 649 int i; 650 651 for (i=0; i<strlen(string1); i++) 652 if (string1[i] >= 'A' && string1[i] <= 'Z') 653 src[i] = string1[i] + 32; 654 else 655 src[i] = string1[i]; 656 src[i] = 0; 657 658 for (i=0; i<strlen(string2); i++) 659 if (string2[i] >= 'A' && string2[i] <= 'Z') 660 dest[i] = string2[i] + 32; 661 else 662 dest[i] = string2[i]; 663 dest[i] = 0; 664 665 return strcmp(src, dest); 551 int stricmp(const char *s1, const char *s2) { 552 while (*s1 != 0 && tolower(*s1) == tolower(*s2)) { 553 s1++; 554 s2++; 555 } 556 return *(unsigned char *)s1 - *(unsigned char *)s2; 666 557 } 667 558 668 char *strrchr(const char *s, int c) { 669 int i; 559 /* Find the last occurrence of C in S. Code taken from glibc. */ 560 char * strrchr (const char *s, int c) { 561 const char *found, *p; 562 c = (unsigned char)c; 670 563 671 for (i = strlen(s) - 1; i > 0; i--)672 if (s[i] == c)673 return (char*)(s + i);564 /* Since strchr is fast, we use it rather than the obvious loop. */ 565 if (c == '\0') 566 return strchr (s, '\0'); 674 567 675 return NULL; 568 found = NULL; 569 while ((p = strchr(s, c)) != NULL) { 570 found = p; 571 s = p + 1; 572 } 573 return (char *) found; 676 574 } 677 575 678 576 long int strtol(const char *nptr, char **endptr, int base) { … … 691 589 #else // defined(__GNUC__) 692 590 693 591 #ifndef __MINGW32CE__ 694 int islower(int c) 695 { 592 int islower(int c) { 696 593 return (c>='a' && c<='z'); 697 594 } 698 595 699 int isspace(int c) 700 { 596 int isspace(int c) { 701 597 return (c==' ' || c=='\f' || c=='\n' || c=='\r' || c=='\t' || c=='\v'); 702 598 } 703 599 704 int isalpha(int c) 705 { 706 return (islower(c) || (c>='A' && c<='Z')); 600 int isalpha(int c) { 601 return ((c>='a' && c<='z') || (c>='A' && c<='Z')); 707 602 } 708 603 709 int isalnum(int c) 710 { 711 return (isalpha(c) || (c>='0' && c<='9')); 604 int isalnum(int c) { 605 return ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')); 712 606 } 713 607 714 int isprint(int c) 715 { 716 static char punct[] = "!\"#%&'();<=>?[\\]*+,-./:^_{|}~"; 717 int i = 0, flag = 0; 718 while ((punct[i] != 0) && (flag = (punct[i] != c))) 719 i++; 720 return (isalnum(c) || flag); 608 int isprint(int c) { 609 //static const char punct[] = "!\"#%&'();<=>?[\\]*+,-./:^_{|}~"; 610 //return (isalnum(c) || strchr(punct, c)); 611 return (32 <= c && c <= 126); // based on BSD manpage 721 612 } 722 723 extern "C" int atexit(void (*function)(void))724 {725 return 0;726 }727 613 #endif 728 614 729 615 #endif