Changeset 740 for vendor/current/lib/replace/replace.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/replace/replace.c
r414 r740 4 4 Copyright (C) Andrew Tridgell 1992-1998 5 5 Copyright (C) Jelmer Vernooij 2005-2008 6 Copyright (C) Matthieu Patou 2010 6 7 7 8 ** NOTE! The following LGPL license applies to the replace … … 410 411 { 411 412 /* have a reasonable go at emulating it. Hope that 412 the system mktemp() isn't complet ly hopeless */413 the system mktemp() isn't completely hopeless */ 413 414 char *p = mktemp(template); 414 415 if (!p) … … 503 504 #endif 504 505 506 505 507 #ifndef HAVE_STRTOLL 506 508 long long int rep_strtoll(const char *str, char **endptr, int base) … … 516 518 #endif 517 519 } 518 #endif 520 #else 521 #ifdef HAVE_BSD_STRTOLL 522 #ifdef HAVE_STRTOQ 523 long long int rep_strtoll(const char *str, char **endptr, int base) 524 { 525 long long int nb = strtoq(str, endptr, base); 526 /* In linux EINVAL is only returned if base is not ok */ 527 if (errno == EINVAL) { 528 if (base == 0 || (base >1 && base <37)) { 529 /* Base was ok so it's because we were not 530 * able to make the convertion. 531 * Let's reset errno. 532 */ 533 errno = 0; 534 } 535 } 536 return nb; 537 } 538 #else 539 #error "You need the strtoq function" 540 #endif /* HAVE_STRTOQ */ 541 #endif /* HAVE_BSD_STRTOLL */ 542 #endif /* HAVE_STRTOLL */ 519 543 520 544 … … 532 556 #endif 533 557 } 534 #endif 558 #else 559 #ifdef HAVE_BSD_STRTOLL 560 #ifdef HAVE_STRTOUQ 561 unsigned long long int rep_strtoull(const char *str, char **endptr, int base) 562 { 563 unsigned long long int nb = strtouq(str, endptr, base); 564 /* In linux EINVAL is only returned if base is not ok */ 565 if (errno == EINVAL) { 566 if (base == 0 || (base >1 && base <37)) { 567 /* Base was ok so it's because we were not 568 * able to make the convertion. 569 * Let's reset errno. 570 */ 571 errno = 0; 572 } 573 } 574 return nb; 575 } 576 #else 577 #error "You need the strtouq function" 578 #endif /* HAVE_STRTOUQ */ 579 #endif /* HAVE_BSD_STRTOLL */ 580 #endif /* HAVE_STRTOULL */ 535 581 536 582 #ifndef HAVE_SETENV … … 682 728 } 683 729 #endif 730 731 732 #ifndef HAVE_MEMMEM 733 void *rep_memmem(const void *haystack, size_t haystacklen, 734 const void *needle, size_t needlelen) 735 { 736 if (needlelen == 0) { 737 return discard_const(haystack); 738 } 739 while (haystacklen >= needlelen) { 740 char *p = (char *)memchr(haystack, *(const char *)needle, 741 haystacklen-(needlelen-1)); 742 if (!p) return NULL; 743 if (memcmp(p, needle, needlelen) == 0) { 744 return p; 745 } 746 haystack = p+1; 747 haystacklen -= (p - (const char *)haystack) + 1; 748 } 749 return NULL; 750 } 751 #endif 752 753 #ifndef HAVE_VDPRINTF 754 int rep_vdprintf(int fd, const char *format, va_list ap) 755 { 756 char *s = NULL; 757 int ret; 758 759 vasprintf(&s, format, ap); 760 if (s == NULL) { 761 errno = ENOMEM; 762 return -1; 763 } 764 ret = write(fd, s, strlen(s)); 765 free(s); 766 return ret; 767 } 768 #endif 769 770 #ifndef HAVE_DPRINTF 771 int rep_dprintf(int fd, const char *format, ...) 772 { 773 int ret; 774 va_list ap; 775 776 va_start(ap, format); 777 ret = vdprintf(fd, format, ap); 778 va_end(ap); 779 780 return ret; 781 } 782 #endif 783 784 #ifndef HAVE_GET_CURRENT_DIR_NAME 785 char *rep_get_current_dir_name(void) 786 { 787 char buf[PATH_MAX+1]; 788 char *p; 789 p = getcwd(buf, sizeof(buf)); 790 if (p == NULL) { 791 return NULL; 792 } 793 return strdup(p); 794 } 795 #endif 796 797 #if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE) 798 int rep_strerror_r(int errnum, char *buf, size_t buflen) 799 { 800 char *s = strerror(errnum); 801 if (strlen(s)+1 > buflen) { 802 errno = ERANGE; 803 return -1; 804 } 805 strncpy(buf, s, buflen); 806 return 0; 807 } 808 #endif 809 810 #ifndef HAVE_CLOCK_GETTIME 811 int rep_clock_gettime(clockid_t clk_id, struct timespec *tp) 812 { 813 struct timeval tval; 814 switch (clk_id) { 815 case 0: /* CLOCK_REALTIME :*/ 816 #ifdef HAVE_GETTIMEOFDAY_TZ 817 gettimeofday(&tval,NULL); 818 #else 819 gettimeofday(&tval); 820 #endif 821 tp->tv_sec = tval.tv_sec; 822 tp->tv_nsec = tval.tv_usec * 1000; 823 break; 824 default: 825 errno = EINVAL; 826 return -1; 827 } 828 return 0; 829 } 830 #endif
Note:
See TracChangeset
for help on using the changeset viewer.