123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include "rsUtils.h"
- #include "rsCppUtils.h"
- #include <errno.h>
- #include <string.h>
- #include <unistd.h>
- #include <string>
- #ifndef RS_COMPATIBILITY_LIB
- #include <sys/wait.h>
- #endif
- namespace android {
- namespace renderscript {
- const char * rsuCopyString(const char *name) {
- return rsuCopyString(name, strlen(name));
- }
- const char * rsuCopyString(const char *name, size_t len) {
- char *n = new char[len+1];
- memcpy(n, name, len);
- n[len] = 0;
- return n;
- }
- const char* rsuJoinStrings(int n, const char* const* strs) {
- std::string tmp;
- for (int i = 0; i < n; i++) {
- if (i > 0) {
- tmp.append(" ");
- }
- tmp.append(strs[i]);
- }
- return strndup(tmp.c_str(), tmp.size());
- }
- #ifndef RS_COMPATIBILITY_LIB
- bool rsuExecuteCommand(const char *exe, int nArgs, const char * const *args) {
- std::unique_ptr<const char> joined(rsuJoinStrings(nArgs, args));
- ALOGV("Invoking %s with args '%s'", exe, joined.get());
- pid_t pid = fork();
- switch (pid) {
- case -1: {
- ALOGE("Fork of \"%s\" failed with error %s", exe, strerror(errno));
- return false;
- }
- case 0: {
-
-
-
-
-
-
- setpgid(0, 0);
- execv(exe, (char * const *)args);
- ALOGE("execv() failed: %s", strerror(errno));
- abort();
- return false;
- }
- default: {
-
- int status = 0;
- pid_t w = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
- if (w == -1) {
- ALOGE("Waitpid of \"%s\" failed with error %s", exe,
- strerror(errno));
- return false;
- }
- if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
- return true;
- }
- ALOGE("Child process \"%s\" terminated with status %d", exe, status);
- return false;
- }
- }
- }
- #endif
- int property_get(const char *key, char *value, const char *default_value) {
- int len;
- len = __system_property_get(key, value);
- if (len > 0) {
- return len;
- }
- if (default_value) {
- len = strlen(default_value);
- memcpy(value, default_value, len + 1);
- }
- return len;
- }
- }
- }
|