Index: third_party/grpc/src/core/support/string_posix.c |
diff --git a/third_party/WebKit/Source/build/win/Precompile.h b/third_party/grpc/src/core/support/string_posix.c |
similarity index 57% |
copy from third_party/WebKit/Source/build/win/Precompile.h |
copy to third_party/grpc/src/core/support/string_posix.c |
index 8a0ff29c353fc1d30c92d27f369d7c422a579bc8..25c333db4edf0dce28ddc5f7401fd2008bf55830 100644 |
--- a/third_party/WebKit/Source/build/win/Precompile.h |
+++ b/third_party/grpc/src/core/support/string_posix.c |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2012 Google Inc. All rights reserved. |
+ * |
+ * Copyright 2015, Google Inc. |
+ * All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -26,43 +28,59 @@ |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- */ |
- |
-/* |
- * Precompiled header for WebKit when built on Windows using |
- * GYP-generated project files. Not used by other build |
- * configurations. |
* |
- * Using precompiled headers speeds the build up significantly. On a |
- * fast machine (HP Z600, 12 GB of RAM), an ~18% decrease in full |
- * build time was measured. |
*/ |
-#if defined(WinPrecompile_h_) |
-#error You shouldn't include the precompiled header file more than once. |
-#endif |
+#include <grpc/support/port_platform.h> |
-#define WinPrecompile_h_ |
+#ifdef GPR_POSIX_STRING |
-#define _USE_MATH_DEFINES // Make math.h behave like other platforms. |
- |
-#include <Windows.h> |
- |
-#include <errno.h> |
-#include <fcntl.h> |
-#include <limits.h> |
-#include <math.h> |
-#include <stdarg.h> |
-#include <stddef.h> |
#include <stdio.h> |
-#include <stdlib.h> |
+#include <stdarg.h> |
#include <string.h> |
-#include <time.h> |
-#include <algorithm> |
-#include <ciso646> |
-#include <cmath> |
-#include <cstddef> |
-#include <limits> |
-#include <string> |
-#include <utility> |
+#include <grpc/support/alloc.h> |
+ |
+int gpr_asprintf(char **strp, const char *format, ...) { |
+ va_list args; |
+ int ret; |
+ char buf[64]; |
+ size_t strp_buflen; |
+ |
+ /* Use a constant-sized buffer to determine the length. */ |
+ va_start(args, format); |
+ ret = vsnprintf(buf, sizeof(buf), format, args); |
+ va_end(args); |
+ if (ret < 0) { |
+ *strp = NULL; |
+ return -1; |
+ } |
+ |
+ /* Allocate a new buffer, with space for the NUL terminator. */ |
+ strp_buflen = (size_t)ret + 1; |
+ if ((*strp = gpr_malloc(strp_buflen)) == NULL) { |
+ /* This shouldn't happen, because gpr_malloc() calls abort(). */ |
+ return -1; |
+ } |
+ |
+ /* Return early if we have all the bytes. */ |
+ if (strp_buflen <= sizeof(buf)) { |
+ memcpy(*strp, buf, strp_buflen); |
+ return ret; |
+ } |
+ |
+ /* Try again using the larger buffer. */ |
+ va_start(args, format); |
+ ret = vsnprintf(*strp, strp_buflen, format, args); |
+ va_end(args); |
+ if ((size_t)ret == strp_buflen - 1) { |
+ return ret; |
+ } |
+ |
+ /* This should never happen. */ |
+ gpr_free(*strp); |
+ *strp = NULL; |
+ return -1; |
+} |
+ |
+#endif /* GPR_POSIX_STRING */ |