• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 2016-2017 Intel Corporation
3   #
4   # Licensed under the Apache License, Version 2.0 (the "License");
5   # you may not use this file except in compliance with the License.
6   # You may obtain a copy of the License at
7   #
8   #     http://www.apache.org/licenses/LICENSE-2.0
9   #
10   # Unless required by applicable law or agreed to in writing, software
11   # distributed under the License is distributed on an "AS IS" BASIS,
12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   # See the License for the specific language governing permissions and
14   # limitations under the License.
15   ############################################################################*/
16 
17 /*!
18  * \file
19  * \brief Environment utilities implementation.
20  */
21 
22 #include "util/envutil.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 
26 static char const* prog_name = NULL;
27 
set_prog_name(char const * name)28 void set_prog_name(char const* name) { prog_name = name; }
29 
get_prog_name()30 char const* get_prog_name() { return prog_name; }
31 
log_error(char const * msg,...)32 int log_error(char const* msg, ...) {
33   int result = 0;
34   int local_result = 0;
35   va_list args;
36   va_start(args, msg);
37   do {
38     local_result = fprintf(stderr, "%s: ", prog_name);
39     if (local_result < 0) {
40       result = local_result;
41       break;
42     }
43     result += local_result;
44     local_result = vfprintf(stderr, msg, args);
45     if (local_result < 0) {
46       result = local_result;
47       break;
48     }
49     result += local_result;
50     local_result = fprintf(stderr, "\n");
51     if (local_result < 0) {
52       result = local_result;
53       break;
54     }
55     result += local_result;
56   } while (0);
57   va_end(args);
58   return result;
59 }
60 
log_msg(char const * msg,...)61 int log_msg(char const* msg, ...) {
62   int result = 0;
63   int local_result = 0;
64   va_list args;
65   va_start(args, msg);
66   do {
67     local_result = vfprintf(stdout, msg, args);
68     if (local_result < 0) {
69       result = local_result;
70       break;
71     }
72     result += local_result;
73     local_result = fprintf(stdout, "\n");
74     if (local_result < 0) {
75       result = local_result;
76       break;
77     }
78     result += local_result;
79   } while (0);
80   va_end(args);
81   return result;
82 }
83 
log_fmt(char const * msg,...)84 int log_fmt(char const* msg, ...) {
85   int result = 0;
86   va_list args;
87   va_start(args, msg);
88   result = vfprintf(stdout, msg, args);
89   va_end(args);
90   return result;
91 }
92