xref: /trafficserver/plugins/prefetch/common.cc (revision ca2a233d)
1 /*
2   Licensed to the Apache Software Foundation (ASF) under one
3   or more contributor license agreements.  See the NOTICE file
4   distributed with this work for additional information
5   regarding copyright ownership.  The ASF licenses this file
6   to you under the Apache License, Version 2.0 (the
7   "License"); you may not use this file except in compliance
8   with the License.  You may obtain a copy of the License at
9 
10   http://www.apache.org/licenses/LICENSE-2.0
11 
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 */
18 
19 /**
20  * @file common.cc
21  * @brief Common declarations and definitions.
22  * @see common.h
23  */
24 
25 #include <cstring>
26 #include <cstdlib>
27 
28 #include "common.h"
29 
30 #ifdef PREFETCH_UNIT_TEST
31 
32 void
PrintToStdErr(const char * fmt,...)33 PrintToStdErr(const char *fmt, ...)
34 {
35   va_list args;
36   va_start(args, fmt);
37   vfprintf(stderr, fmt, args);
38   va_end(args);
39 }
40 
41 #endif /* PREFETCH_UNIT_TEST */
42 
43 size_t
getValue(const String & str)44 getValue(const String &str)
45 {
46   char buffer[str.length() + 1];
47   strncpy(buffer, str.c_str(), str.length());
48   buffer[str.length()] = 0;
49   return static_cast<size_t>(strtoul(buffer, nullptr, 10));
50 }
51 
52 size_t
getValue(const char * str,size_t len)53 getValue(const char *str, size_t len)
54 {
55   char buffer[len + 1];
56   strncpy(buffer, str, len);
57   buffer[len] = 0;
58   return static_cast<size_t>(strtoul(buffer, nullptr, 10));
59 }
60