2
* Copyright (C) 2005 The Android Open Source Project
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
// Handy utility functions and portability code.
20
#ifndef _LIBS_UTILS_MISC_H
21
#define _LIBS_UTILS_MISC_H
24
#include <utils/Endian.h>
28
/* get #of elements in a static array */
30
# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
34
* Make a copy of the string, using "new[]" instead of "malloc". Free the
35
* string with delete[].
37
* Returns NULL if "str" is NULL.
39
char* strdupNew(const char* str);
42
* Concatenate an argument vector into a single string. If argc is >= 0
43
* it will be used; if it's < 0 then the last element in the arg vector
46
* This inserts a space between each argument.
48
* This does not automatically add double quotes around arguments with
49
* spaces in them. This practice is necessary for Win32, because Win32's
50
* CreateProcess call is stupid.
52
* The caller should delete[] the returned string.
54
char* concatArgv(int argc, const char* const argv[]);
57
* Count up the number of arguments in "argv". The count does not include
58
* the final NULL entry.
60
int countArgv(const char* const argv[]);
63
* Some utility functions for working with files. These could be made
64
* part of a "File" class.
66
typedef enum FileType {
68
kFileTypeNonexistent, // i.e. ENOENT
77
/* get the file's type; follows symlinks */
78
FileType getFileType(const char* fileName);
79
/* get the file's modification date; returns -1 w/errno set on failure */
80
time_t getFileModDate(const char* fileName);
83
* Round up to the nearest power of 2. Handy for hash tables.
85
unsigned int roundUpPower2(unsigned int val);
87
void strreverse(char* begin, char* end);
88
void k_itoa(int value, char* str, int base);
89
char* itoa(int val, int base);
91
typedef void (*sysprop_change_callback)(void);
92
void add_sysprop_change_callback(sysprop_change_callback cb, int priority);
93
void report_sysprop_change();
95
}; // namespace android
97
#endif // _LIBS_UTILS_MISC_H