Changeset 773 for branches/samba-3.5.x/lib/replace
- Timestamp:
- Jul 2, 2013, 7:27:06 PM (12 years ago)
- Location:
- branches/samba-3.5.x/lib/replace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.5.x/lib/replace/libreplace.m4
r414 r773 109 109 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename) 110 110 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup) 111 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 )111 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf) 112 112 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath) 113 113 AC_HAVE_DECL(setresuid, [#include <unistd.h>]) … … 229 229 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq) 230 230 231 AC_CHECK_FUNCS(memmem) 232 231 233 # this test disabled as we don't actually need __VA_ARGS__ yet 232 234 AC_TRY_CPP([ -
branches/samba-3.5.x/lib/replace/replace.c
r414 r773 682 682 } 683 683 #endif 684 685 686 #ifndef HAVE_MEMMEM 687 void *rep_memmem(const void *haystack, size_t haystacklen, 688 const void *needle, size_t needlelen) 689 { 690 if (needlelen == 0) { 691 return discard_const(haystack); 692 } 693 while (haystacklen >= needlelen) { 694 char *p = memchr(haystack, *(const char *)needle, 695 haystacklen-(needlelen-1)); 696 if (!p) return NULL; 697 if (memcmp(p, needle, needlelen) == 0) { 698 return p; 699 } 700 haystack = p+1; 701 haystacklen -= (p - (const char *)haystack) + 1; 702 } 703 return NULL; 704 } 705 #endif 706 707 #if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF) 708 int rep_vdprintf(int fd, const char *format, va_list ap) 709 { 710 char *s = NULL; 711 int ret; 712 713 vasprintf(&s, format, ap); 714 if (s == NULL) { 715 errno = ENOMEM; 716 return -1; 717 } 718 ret = write(fd, s, strlen(s)); 719 free(s); 720 return ret; 721 } 722 #endif 723 724 #if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF) 725 int rep_dprintf(int fd, const char *format, ...) 726 { 727 int ret; 728 va_list ap; 729 730 va_start(ap, format); 731 ret = vdprintf(fd, format, ap); 732 va_end(ap); 733 734 return ret; 735 } 736 #endif 737 -
branches/samba-3.5.x/lib/replace/replace.h
r414 r773 141 141 #endif 142 142 143 #ifndef HAVE_MEMMEM 144 #define memmem rep_memmem 145 void *rep_memmem(const void *haystack, size_t haystacklen, 146 const void *needle, size_t needlelen); 147 #endif 148 143 149 #ifndef HAVE_MKTIME 144 150 #define mktime rep_mktime … … 351 357 #endif 352 358 353 #ifndef HAVE_VASPRINTF 359 #if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF) 360 #define vdprintf rep_vdprintf 361 int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); 362 #endif 363 364 #if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF) 365 #define dprintf rep_dprintf 366 int rep_dprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3); 367 #endif 368 369 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF) 354 370 #define vasprintf rep_vasprintf 355 371 int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); … … 366 382 #endif 367 383 368 #if ndef HAVE_ASPRINTF384 #if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF) 369 385 #define asprintf rep_asprintf 370 386 int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3); 387 #endif 388 389 #if !defined(HAVE_C99_VSNPRINTF) 390 #ifdef REPLACE_BROKEN_PRINTF 391 /* 392 * We do not redefine printf by default 393 * as it breaks the build if system headers 394 * use __attribute__((format(printf, 3, 0))) 395 * instead of __attribute__((format(__printf__, 3, 0))) 396 */ 397 #define printf rep_printf 398 #endif 399 int rep_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2); 400 #endif 401 402 #if !defined(HAVE_C99_VSNPRINTF) 403 #define fprintf rep_fprintf 404 int rep_fprintf(FILE *stream, const char *, ...) PRINTF_ATTRIBUTE(2,3); 371 405 #endif 372 406 -
branches/samba-3.5.x/lib/replace/snprintf.c
r414 r773 1188 1188 } 1189 1189 1190 int vsnprintf (char *str, size_t count, const char *fmt, va_list args)1190 int rep_vsnprintf (char *str, size_t count, const char *fmt, va_list args) 1191 1191 { 1192 1192 return dopr(str, count, fmt, args); … … 1201 1201 */ 1202 1202 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) 1203 int snprintf(char *str,size_t count,const char *fmt,...)1203 int rep_snprintf(char *str,size_t count,const char *fmt,...) 1204 1204 { 1205 1205 size_t ret; … … 1214 1214 1215 1215 #ifndef HAVE_C99_VSNPRINTF 1216 int printf(const char *fmt, ...)1216 int rep_printf(const char *fmt, ...) 1217 1217 { 1218 1218 va_list ap; … … 1235 1235 1236 1236 #ifndef HAVE_C99_VSNPRINTF 1237 int fprintf(FILE *stream, const char *fmt, ...)1237 int rep_fprintf(FILE *stream, const char *fmt, ...) 1238 1238 { 1239 1239 va_list ap; … … 1257 1257 #endif 1258 1258 1259 #if ndef HAVE_VASPRINTF1260 int vasprintf(char **ptr, const char *format, va_list ap)1259 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF) 1260 int rep_vasprintf(char **ptr, const char *format, va_list ap) 1261 1261 { 1262 1262 int ret; … … 1279 1279 #endif 1280 1280 1281 1282 #ifndef HAVE_ASPRINTF 1283 int asprintf(char **ptr, const char *format, ...) 1281 #if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF) 1282 int rep_asprintf(char **ptr, const char *format, ...) 1284 1283 { 1285 1284 va_list ap; -
branches/samba-3.5.x/lib/replace/test/testsuite.c
r414 r773 1015 1015 return true; 1016 1016 } 1017 1018 static int test_memmem(void) 1019 { 1020 char *s; 1021 1022 printf("test: memmem\n"); 1023 1024 s = memmem("foo", 3, "fo", 2); 1025 if (strcmp(s, "foo") != 0) { 1026 printf(__location__ ": Failed memmem\n"); 1027 return false; 1028 } 1029 1030 s = memmem("foo", 3, "", 0); 1031 if (strcmp(s, "foo") != 0) { 1032 printf(__location__ ": Failed memmem\n"); 1033 return false; 1034 } 1035 1036 s = memmem("foo", 4, "o", 1); 1037 if (strcmp(s, "oo") != 0) { 1038 printf(__location__ ": Failed memmem\n"); 1039 return false; 1040 } 1041 1042 s = memmem("foobarfodx", 11, "fod", 3); 1043 if (strcmp(s, "fodx") != 0) { 1044 printf(__location__ ": Failed memmem\n"); 1045 return false; 1046 } 1047 1048 printf("success: memmem\n"); 1049 1050 return true; 1051 } 1052 1017 1053 1018 1054 struct torture_context; … … 1066 1102 ret &= test_utime(); 1067 1103 ret &= test_utimes(); 1104 ret &= test_memmem(); 1068 1105 1069 1106 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.