diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-08-28 16:07:06 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-05-19 03:43:20 +0200 |
commit | 4165dd4e465a86ba6abe9afb3abfda5ef72493ea (patch) | |
tree | 4eb9102a2832fd75f26b7805e69aa39e1701d61e /onlineupdate | |
parent | 1bff19a2c0de2825bec287ffd64bee6bace3f448 (diff) |
add a way to create mar file from file
We exceed the command line limit when we try to use the stuff directly
so storing it in a file seems like the best approach. Currently the
memory that we allocate in the new code path is leaked but as the
program ends a bit later anyway this is not too bad.
Change-Id: I87350c617e577a319ce4be37cbd707011c0bd502
Diffstat (limited to 'onlineupdate')
-rw-r--r-- | onlineupdate/source/libmar/tool/mar.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/onlineupdate/source/libmar/tool/mar.c b/onlineupdate/source/libmar/tool/mar.c index dba07ac10467..33159bd9655f 100644 --- a/onlineupdate/source/libmar/tool/mar.c +++ b/onlineupdate/source/libmar/tool/mar.c @@ -16,6 +16,7 @@ #define chdir _chdir #else #include <unistd.h> +#include <errno.h> #endif #define MOZ_APP_VERSION "5" /* Dummy value; replace or remove in the @@ -45,6 +46,8 @@ static void print_usage(void) { printf("Create a MAR file:\n"); printf(" mar [-H MARChannelID] [-V ProductVersion] [-C workingDir] " "-c archive.mar [files...]\n"); + printf(" mar [-H MARChannelID] [-V ProductVersion] [-C workingDir] " + "-c archive.mar -f input_file.txt\n"); printf("Extract a MAR file:\n"); printf(" mar [-C workingDir] -x archive.mar\n"); @@ -247,7 +250,39 @@ int main(int argc, char **argv) { struct ProductInformationBlock infoBlock; infoBlock.MARChannelID = MARChannelID; infoBlock.productVersion = productVersion; - return mar_create(argv[2], argc - 3, argv + 3, &infoBlock); + if (argv[argc - 2][0] == '-' && argv[argc - 2][1] == 'f') + { + char buf[1000]; + FILE* file; + char** files; + int num_files = 0; + + files = (char **)malloc(sizeof(char*)*10000); + errno = 0; + file = fopen(argv[argc - 1], "r"); + if (!file) + { + printf("%d %s", errno, strerror(errno)); + printf("Could not open file: %s", argv[argc - 1]); + exit(1); + } + + while(fgets(buf, 1000, file) != NULL) + { + int j; + for (j=strlen(buf)-1;j>=0 && (buf[j]=='\n' || buf[j]=='\r');j--) + ; + buf[j+1]='\0'; + size_t str_len = strlen(buf) + 1; + files[num_files] = (char*)malloc(sizeof(char)*str_len); + strcpy(files[num_files], buf); + ++num_files; + } + fclose(file); + return mar_create(argv[2], num_files, files, &infoBlock); + } + else + return mar_create(argv[2], argc - 3, argv + 3, &infoBlock); } case 'i': { struct ProductInformationBlock infoBlock; |