本文整理匯總了C++中ErrorAbort函數的典型用法代碼示例。如果您正苦於以下問題:C++ ErrorAbort函數的具體用法?C++ ErrorAbort怎麽用?C++ ErrorAbort使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ErrorAbort函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: VerifyTrustZoneFn
/* verify_trustzone("TZ_VERSION", "TZ_VERSION", ...) */
Value * VerifyTrustZoneFn(const char *name, State *state, int argc, Expr *argv[]) {
char current_tz_version[TZ_VER_BUF_LEN];
int i, ret;
ret = get_tz_version(current_tz_version, TZ_VER_BUF_LEN);
if (ret) {
return ErrorAbort(state, "%s() failed to read current TZ version: %d",
name, ret);
}
char** tz_version = ReadVarArgs(state, argc, argv);
if (tz_version == NULL) {
return ErrorAbort(state, "%s() error parsing arguments", name);
}
ret = 0;
for (i = 0; i < argc; i++) {
uiPrintf(state, "Comparing TZ version %s to %s",
tz_version[i], current_tz_version);
if (strncmp(tz_version[i], current_tz_version, strlen(tz_version[i])) == 0) {
ret = 1;
break;
}
}
for (i = 0; i < argc; i++) {
free(tz_version[i]);
}
free(tz_version);
return StringValue(strdup(ret ? "1" : "0"));
}
示例2: UpdateFn
Value* UpdateFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 1) {
return ErrorAbort(state, "%s() expects 6 args, got %d", name, argc);
}
char* type = strrchr(name, '_');
if (type == NULL || *(type+1) == '\0') {
return ErrorAbort(state, "%s() couldn't get type from function name",
name);
}
++type;
Value* image;
if (ReadValueArgs(state, argv, 1, &image) <0) {
return NULL;
}
if (image->type != VAL_BLOB) {
printf("image argument is not blob (is type %d)\n", image->type);
goto done;
}
install_firmware_update(type, image->data, image->size, "/tmp/recovery.log");
printf("%s: install_firmware_update returned!\n", name);
done:
FreeValue(image);
// install_firmware_update should reboot. If it returns, it failed.
return StringValue(strdup(""));
}
示例3: WriteBootloaderFn
Value* WriteBootloaderFn(const char* name, State* state, int argc, Expr* argv[])
{
int result = -1;
Value* img;
Value* xloader_loc;
Value* sbl_loc;
if (argc != 3) {
return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc);
}
if (ReadValueArgs(state, argv, 3, &img, &xloader_loc, &sbl_loc) < 0) {
return NULL;
}
if(img->type != VAL_BLOB ||
xloader_loc->type != VAL_STRING ||
sbl_loc->type != VAL_STRING) {
FreeValue(img);
FreeValue(xloader_loc);
FreeValue(sbl_loc);
return ErrorAbort(state, "%s(): argument types are incorrect", name);
}
result = update_bootloader(img->data, img->size,
xloader_loc->data, sbl_loc->data);
FreeValue(img);
FreeValue(xloader_loc);
FreeValue(sbl_loc);
return StringValue(strdup(result == 0 ? "t" : ""));
}
示例4: ReadFileFn
// Read a local file and return its contents (the Value* returned
// is actually a FileContents*).
Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 1) {
return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
}
char* filename;
if (ReadArgs(state, argv, 1, &filename) < 0) return NULL;
Value* v = malloc(sizeof(Value));
v->type = VAL_BLOB;
FileContents fc;
if (LoadFileContents(filename, &fc, RETOUCH_DONT_MASK) != 0) {
ErrorAbort(state, "%s() loading \"%s\" failed: %s",
name, filename, strerror(errno));
free(filename);
free(v);
free(fc.data);
return NULL;
}
v->size = fc.size;
v->data = (char*)fc.data;
free(filename);
return v;
}
示例5: ReadVarArgs
Value *CommandFunction(int (*fun) (int, char **), const char *name, State * state, int argc, Expr * argv[])
{
Value *ret = NULL;
char *argv_str[argc + 1];
int i;
char **argv_read = ReadVarArgs(state, argc, argv);
if (argv_read == NULL) {
ErrorAbort(state, "%s parameter parsing failed.", name);
goto done;
}
argv_str[0] = (char *)name;
for (i = 0; i < argc; i++)
argv_str[i + 1] = argv_read[i];
if (fun(sizeof(argv_str) / sizeof(char *), argv_str) != EXIT_SUCCESS) {
ErrorAbort(state, "%s failed.", name);
goto done;
}
for (i = 0; i < argc; i++)
free(argv_read[i]);
free(argv_read);
ret = StringValue(strdup("t"));
done:
return ret;
}
示例6: UnmountFn
Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) {
char* result = NULL;
if (argc != 1) {
return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
}
char* mount_point;
if (ReadArgs(state, argv, 1, &mount_point) < 0) {
return NULL;
}
if (strlen(mount_point) == 0) {
ErrorAbort(state, "mount_point argument to unmount() can't be empty");
goto done;
}
scan_mounted_volumes();
const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point);
if (vol == NULL) {
fprintf(stderr, "unmount of %s failed; no such volume\n", mount_point);
result = strdup("");
} else {
unmount_mounted_volume(vol);
result = mount_point;
}
done:
if (result != mount_point) free(mount_point);
return StringValue(result);
}
示例7: int
Value *ExecuteOsipFunction(const char *name, State * state, int argc, Expr * argv[], int (*action) (char *))
{
Value *ret = NULL;
char *destination = NULL;
if (ReadArgs(state, argv, 1, &destination) < 0) {
return NULL;
}
if (destination == NULL || strlen(destination) == 0) {
ErrorAbort(state, "destination argument to %s can't be empty", name);
goto done;
}
if (action(destination) == -1) {
ErrorAbort(state, "Error writing %s to OSIP", destination);
goto done;
}
ret = StringValue(strdup("t"));
done:
if (destination)
free(destination);
return ret;
}
示例8: UnloadWifiFn
char* UnloadWifiFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 0)
return ErrorAbort(state, "%s() expects 0 arg, got %d", name, argc);
if (wifi_unload_driver() != 0) {
return ErrorAbort(state, "Unable to unload wifi-driver: %s", strerror(errno));
}
return strdup("t");
}
示例9: WriteRawImageFn
// write_raw_image(file, partition)
Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
char* result = NULL;
char* partition;
char* filename;
if (ReadArgs(state, argv, 2, &filename, &partition) < 0) {
return NULL;
}
if (strlen(partition) == 0) {
ErrorAbort(state, "partition argument to %s can't be empty", name);
goto done;
}
if (strlen(filename) == 0) {
ErrorAbort(state, "file argument to %s can't be empty", name);
goto done;
}
mtd_scan_partitions();
const MtdPartition* mtd = mtd_find_partition_by_name(partition);
if (mtd == NULL) {
fprintf(stderr, "%s: no mtd partition named \"%s\"\n", name, partition);
result = strdup("");
goto done;
}
char mtddevname[32]="";
sprintf(mtddevname, "/dev/mtd/mtd%d", mtd_get_partition_index((MtdPartition*)mtd));
bool success;
FILE* f = fopen(filename, "rb");
if (f == NULL) {
fprintf(stderr, "%s: can't open %s: %s\n",
name, filename, strerror(errno));
result = strdup("");
goto done;
}
success = !write_recovery(filename, partition);
printf("%s %s partition from %s\n",
success ? "wrote" : "failed to write", partition, filename);
result = success ? partition : strdup("");
done:
if (result != partition) free(partition);
free(filename);
return StringValue(result);
}
示例10: RangeSha1Fn
Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) {
Value* blockdev_filename;
Value* ranges;
const uint8_t* digest = NULL;
if (ReadValueArgs(state, argv, 2, &blockdev_filename, &ranges) < 0) {
return NULL;
}
if (blockdev_filename->type != VAL_STRING) {
ErrorAbort(state, "blockdev_filename argument to %s must be string", name);
goto done;
}
if (ranges->type != VAL_STRING) {
ErrorAbort(state, "ranges argument to %s must be string", name);
goto done;
}
int fd = open(blockdev_filename->data, O_RDWR);
if (fd < 0) {
ErrorAbort(state, "failed to open %s: %s", blockdev_filename->data, strerror(errno));
goto done;
}
RangeSet* rs = parse_range(ranges->data);
uint8_t buffer[BLOCKSIZE];
SHA_CTX ctx;
SHA_init(&ctx);
int i, j;
for (i = 0; i < rs->count; ++i) {
check_lseek(fd, (off64_t)rs->pos[i*2] * BLOCKSIZE, SEEK_SET);
for (j = rs->pos[i*2]; j < rs->pos[i*2+1]; ++j) {
readblock(fd, buffer, BLOCKSIZE);
SHA_update(&ctx, buffer, BLOCKSIZE);
}
}
digest = SHA_final(&ctx);
close(fd);
done:
FreeValue(blockdev_filename);
FreeValue(ranges);
if (digest == NULL) {
return StringValue(strdup(""));
} else {
return StringValue(PrintSha1(digest));
}
}
示例11: UnloadWifiFn
char* UnloadWifiFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 0)
return ErrorAbort(state, "%s() expects 0 arg, got %d", name, argc);
void *h = dlopen("/system/lib/libhardware_legacy.so",RTLD_LAZY);
int (*wifi_unload_driver)() = dlsym(h,"wifi_unload_driver");
if (wifi_unload_driver) {
if (wifi_unload_driver() != 0) {
return ErrorAbort(state, "Unable to unload wifi-driver: %s", strerror(errno));
}
return strdup("t");
}
return ErrorAbort(state, "libhardware_legacy is not available.");
}
示例12: WipeCacheFn
Value* WipeCacheFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 0) {
return ErrorAbort(state, "%s() expects no args, got %d", name, argc);
}
fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, "wipe_cache\n");
return StringValue(strdup("t"));
}
示例13: WriteFileFn
char* WriteFileFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 2)
return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc);
char *filename;
char *line;
int retval;
if (ReadArgs(state, argv, 2, &filename, &line) < 0)
return NULL;
FILE *fd;
if (! (fd = fopen(filename, "w")) ) {
fprintf(stderr, "Can't open %s for write \n", filename);
free(filename);
free(line);
return strdup("");
}
if (fwrite(line, strlen(line), 1, fd) == 1) {
fclose(fd);
free(filename);
free(line);
return strdup("t");
} else {
fclose(fd);
free(filename);
free(line);
return strdup("");
}
}
示例14: ModuleLoadedFn
char* ModuleLoadedFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 1)
return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
char *module_name;
int retval;
if (ReadArgs(state, argv, 1, &module_name) < 0)
return NULL;
int module_found = -1;
FILE *modules;
char buffer[READ_BUF_SIZE];
char mname[READ_BUF_SIZE];
if (! (modules = fopen("/proc/modules", "r")) ) {
fprintf(stderr, "Can't open /proc/modules for read \n");
return strdup("");
}
while(fgets(buffer, sizeof(buffer), modules)) {
/* process the line */
sscanf(buffer, "%s %*s", mname);
if ((strstr(mname, module_name)) != NULL) {
module_found = 0;
}
}
fclose(modules);
free(module_name);
return (module_found == 0 ? strdup("t") : strdup(""));
}
示例15: PackageExtractDirFn
// package_extract_dir(package_path, destination_path)
Value *
PackageExtractDirFn (const char *name, State * state, int argc, Expr * argv[])
{
if (argc != 2)
{
return ErrorAbort (state, "%s() expects 2 args, got %d", name,
argc);
}
char *zip_path;
char *dest_path;
if (ReadArgs (state, argv, 2, &zip_path, &dest_path) < 0)
return NULL;
ZipArchive *za = ((UpdaterInfo *) (state->cookie))->package_zip;
// To create a consistent system image, never use the clock for timestamps.
struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
bool success = mzExtractRecursive (za, zip_path, dest_path,
MZ_EXTRACT_FILES_ONLY, ×tamp,
NULL, NULL);
free (zip_path);
free (dest_path);
return StringValue (strdup (success ? "t" : ""));
}