Fixes for Android GN build input/outputs
[chromium-blink-merge.git] / third_party / hwcplus / src / hwcplus_util.c
blob1c7873af8e52e667a5ee2bc0d7dca57f87d75634
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <string.h>
9 #include <android/log.h>
10 #include <cutils/properties.h>
11 #include <hardware/hardware.h>
13 #define LOG_BUF_SIZE 1024
15 static int default_log_fn(int prio, const char* tag, const char* msg);
17 static hwcplus_log_fn_t hwcplus_log_fn = default_log_fn;
19 void hwcplus_set_log_fn(hwcplus_log_fn_t fn) {
20 hwcplus_log_fn = fn;
23 #ifndef HAVE_STRLCPY
24 size_t strlcpy(char* dst, const char* src, size_t siz) {
25 char* d = dst;
26 const char* s = src;
27 size_t n = siz;
29 /* Copy as many bytes as will fit */
30 if (n != 0) {
31 while (--n != 0) {
32 if ((*d++ = *s++) == '\0')
33 break;
37 /* Not enough room in dst, add NUL and traverse rest of src */
38 if (n == 0) {
39 if (siz != 0)
40 *d = '\0'; /* NUL-terminate dst */
41 while (*s++) {
45 return(s - src - 1); /* count does not include NUL */
47 #endif
49 static int default_log_fn(int prio, const char* tag, const char* msg) {
50 fprintf(stderr, "<%d> %s %s\n", prio, tag, msg);
53 int __android_log_write(int prio, const char* tag, const char* msg) {
54 hwcplus_log_fn(prio, tag, msg);
57 int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
58 va_list ap;
59 char buf[LOG_BUF_SIZE];
61 va_start(ap, fmt);
62 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
63 va_end(ap);
65 return __android_log_write(prio, tag, buf);
68 void __android_log_assert(const char* cond,
69 const char* tag,
70 const char* fmt,
71 ...) {
72 char buf[LOG_BUF_SIZE];
74 if (fmt) {
75 va_list ap;
76 va_start(ap, fmt);
77 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
78 va_end(ap);
79 } else {
80 /* Msg not provided, log condition. N.B. Do not use cond directly as
81 * format string as it could contain spurious '%' syntax (e.g.
82 * "%d" in "blocks%devs == 0").
84 if (cond)
85 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
86 else
87 snprintf(buf, LOG_BUF_SIZE, "Unspecified assertion failed");
90 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
92 __builtin_trap(); /* trap so we have a chance to debug the situation */
95 int property_get(const char* key, char* value, const char* default_value) {
96 printf("property_get %s\n", key);
97 const char* r = default_value;
98 if (!r)
99 r = "";
100 strncpy(value, r, PROPERTY_VALUE_MAX);
101 return strlen(r);