vfs: check userland buffers before reading them.
[haiku.git] / src / bin / package_repo / package_repo.cpp
blob95b18e3fa7b6d482a51a4cf00cebb4f9f016b949
1 /*
2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
4 */
7 #include "package_repo.h"
9 #include <errno.h>
10 #include <getopt.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 extern const char* __progname;
16 const char* kCommandName = __progname;
19 static const char* kUsage =
20 "Usage: %s <command> <command args>\n"
21 "Creates or inspects a Haiku package repository file.\n"
22 "\n"
23 "Commands:\n"
24 " create [ <options> ] <repo-info> <package-file ...> \n"
25 " Creates a package repository from the information found in \n"
26 " <repo-info>, adding the given package files.\n"
27 "\n"
28 " -C <dir> - Change to directory <dir> before starting.\n"
29 " -q - be quiet (don't show any output except for errors).\n"
30 " -v - be verbose (list package attributes as encountered).\n"
31 "\n"
32 " list [ <options> ] <package-repo>\n"
33 " Lists the contents of package repository file <package-repo>.\n"
34 "\n"
35 " -v - be verbose (list attributes of all packages found).\n"
36 "\n"
37 " update [ <options> ] <source-repo> <new-repo> <package-list-file> \n"
38 " Creates package repository file <new-repo> with all the packages\n"
39 " contained in <package-list-file>. If possible, package-infos are\n"
40 " taken from <source-repo> to avoid the need for recomputing the\n"
41 " checksum of all packages.\n"
42 " <old-repo> and <new-repo> can be the same file.\n"
43 "\n"
44 " -C <dir> - Change to directory <dir> before starting.\n"
45 " -q - be quiet (don't show any output except for errors).\n"
46 " -v - be verbose (list package attributes as encountered).\n"
47 "\n"
48 "Common Options:\n"
49 " -h, --help - Print this usage info.\n"
53 void
54 print_usage_and_exit(bool error)
56 fprintf(error ? stderr : stdout, kUsage, kCommandName);
57 exit(error ? 1 : 0);
61 int
62 main(int argc, const char* const* argv)
64 if (argc < 2)
65 print_usage_and_exit(true);
67 const char* command = argv[1];
68 if (strcmp(command, "create") == 0)
69 return command_create(argc - 1, argv + 1);
71 if (strcmp(command, "list") == 0)
72 return command_list(argc - 1, argv + 1);
74 if (strcmp(command, "update") == 0)
75 return command_update(argc - 1, argv + 1);
77 if (strcmp(command, "help") == 0)
78 print_usage_and_exit(false);
79 else
80 print_usage_and_exit(true);
82 // never gets here
83 return 0;