• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Fuchsia 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.
4 
5 #include <stdlib.h>
6 
7 #include <atomic>
8 #include <cassert>
9 #include <cstdarg>
10 #include <cstdint>
11 #include <cstdio>
12 #include <thread>
13 #include <cstring>
14 
15 #if defined(__Fuchsia__)
16 #include <lib/syslog/global.h>
17 #else
18 #include <libgen.h>
19 #endif
20 
21 #include "cutils/log.h"
22 #include "cutils/properties.h"
23 
24 extern "C" {
25 
26 #if !defined(__Fuchsia__)
linux_log_prefix(const char * prefix,const char * file,int line,const char * format,va_list ap,...)27 static void linux_log_prefix(const char *prefix, const char *file, int line, const char *format,
28                              va_list ap, ...)
29 {
30   char buf[50];
31   char *dup = strdup(file);
32   if (!dup)
33     return;
34 
35   snprintf(buf, sizeof(buf), "[%s(%d)]", basename(dup), line);
36   fprintf(stderr, "%s\n", buf);
37   vfprintf(stderr, format, ap);
38 
39   free(dup);
40 }
41 #endif
42 
property_get(const char * key,char * value,const char * default_value)43 int property_get(const char* key, char* value, const char* default_value) {
44   return 0;
45 }
46 
__android_log_print(int priority,const char * tag,const char * file,int line,const char * format,...)47 int __android_log_print(int priority, const char* tag, const char* file,
48                         int line, const char* format, ...) {
49   const char* local_tag = tag;
50   if (!local_tag) {
51     local_tag = "<NO_TAG>";
52   }
53 
54   va_list ap;
55   va_start(ap, format);
56 #if defined(__Fuchsia__)
57   switch (priority) {
58     case ANDROID_LOG_VERBOSE:
59     case ANDROID_LOG_DEBUG:
60       FX_LOGVF(DEBUG, local_tag, file, line, format, ap);
61       break;
62     case ANDROID_LOG_WARN:
63       FX_LOGVF(WARNING, local_tag, file, line, format, ap);
64       break;
65     case ANDROID_LOG_ERROR:
66       FX_LOGVF(ERROR, local_tag, file, line, format, ap);
67       break;
68     case ANDROID_LOG_FATAL:
69       FX_LOGVF(FATAL, local_tag, file, line, format, ap);
70       break;
71     case ANDROID_LOG_INFO:
72     default:
73       FX_LOGVF(INFO, local_tag, file, line, format, ap);
74       break;
75   }
76 #else
77   linux_log_prefix(local_tag, file, line, format, ap);
78 #endif
79 
80   return 1;
81 }
82 
__android_log_assert(const char * condition,const char * tag,const char * file,int line,const char * format,...)83 void __android_log_assert(const char* condition, const char* tag,
84                           const char* file, int line, const char* format, ...) {
85   const char* local_tag = tag;
86   if (!local_tag) {
87     local_tag = "<NO_TAG>";
88   }
89   va_list ap;
90   va_start(ap, format);
91 #if defined(__Fuchsia__)
92   FX_LOGVF(ERROR, local_tag, file, line, format, ap);
93 #else
94   linux_log_prefix(local_tag, file, line, format, ap);
95 #endif
96 
97   va_end(ap);
98 
99   abort();
100 }
101 
sync_wait(int fd,int timeout)102 int sync_wait(int fd, int timeout) { return -1; }
103 }
104