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.
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
) {
24 size_t strlcpy(char* dst
, const char* src
, size_t siz
) {
29 /* Copy as many bytes as will fit */
32 if ((*d
++ = *s
++) == '\0')
37 /* Not enough room in dst, add NUL and traverse rest of src */
40 *d
= '\0'; /* NUL-terminate dst */
45 return(s
- src
- 1); /* count does not include NUL */
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
, ...) {
59 char buf
[LOG_BUF_SIZE
];
62 vsnprintf(buf
, LOG_BUF_SIZE
, fmt
, ap
);
65 return __android_log_write(prio
, tag
, buf
);
68 void __android_log_assert(const char* cond
,
72 char buf
[LOG_BUF_SIZE
];
77 vsnprintf(buf
, LOG_BUF_SIZE
, fmt
, ap
);
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").
85 snprintf(buf
, LOG_BUF_SIZE
, "Assertion failed: %s", cond
);
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
;
100 strncpy(value
, r
, PROPERTY_VALUE_MAX
);