Skip to content

Instantly share code, notes, and snippets.

@sunwayforever
Created July 19, 2017 08:12
Show Gist options
  • Save sunwayforever/6d785755bdf7c0c175f1128be16435fa to your computer and use it in GitHub Desktop.
Save sunwayforever/6d785755bdf7c0c175f1128be16435fa to your computer and use it in GitHub Desktop.
android liblog and getopt example
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libgen.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#if defined TARGET
#include "android/log.h"
#endif
int main(int argc, char *argv[]) {
static struct option long_options[] = {
{"input-file-name" , required_argument, 0, 0 },
{"output-file-name", required_argument, 0, 0 },
{"input-fd" , required_argument, 0, 0 },
{"output-fd" , required_argument, 0, 0 },
{"apk" , required_argument, 0, 0 },
};
int opt_index = 0;
char *salsa_file_name = 0;
while (getopt_long(argc, argv, "", long_options, &opt_index) == 0) {
if (opt_index == 1) {
salsa_file_name = optarg;
}
}
int fd = open(salsa_file_name, O_CREAT | O_TRUNC, 0755);
#if defined TARGET
if (fd == -1) {
__android_log_print(ANDROID_LOG_INFO, "salsa_pretranslator", "salsa_pretranslator: create for %s failed, error: %s\n", salsa_file_name, strerror(errno));
} else {
__android_log_print(ANDROID_LOG_INFO, "salsa_pretranslator", "salsa_pretranslator: %s created\n", salsa_file_name);
}
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment