Skip to content

Commit

Permalink
Ijar: extract [] to platform_utils
Browse files Browse the repository at this point in the history
zip_main.cc no longer needs <unistd.h>.
This change takes us closer to compiling ijar,
thus Bazel, with MSVC.

See #2157
See #2107

--
MOS_MIGRATED_REVID=140723658
  • Loading branch information
laszlocsomor authored and iirina committed Dec 1, 2016
1 parent 7ecf871 commit 8457f3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
19 changes: 19 additions & 0 deletions third_party/ijar/platform_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace devtools_ijar {

using std::string;

bool stat_file(const char* path, Stat* result) {
#ifdef COMPILER_MSVC
// TODO(laszlocsomor) 2016-12-01: implement this and other methods, in order
Expand Down Expand Up @@ -113,4 +115,21 @@ bool read_file(const char* path, void* buffer, size_t size) {
#endif // COMPILER_MSVC
}

string get_cwd() {
#ifdef COMPILER_MSVC
// TODO(laszlocsomor) 2016-12-01: implement this and other methods, in order
// to close https://github.com/bazelbuild/bazel/issues/2157.
fprintf(stderr, "Not yet implemented on Windows\n");
return "";
#else // not COMPILER_MSVC
char cwd[PATH_MAX];
if (getcwd(cwd, PATH_MAX) == NULL) {
fprintf(stderr, "getcwd() failed: %s\n", strerror(errno));
return "";
} else {
return string(cwd);
}
#endif // COMPILER_MSVC
}

} // namespace devtools_ijar
4 changes: 4 additions & 0 deletions third_party/ijar/platform_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ bool write_file(const char* path, mode_t perm, const void* data, size_t size);
// Returns false upon failure and reports the error to stderr.
bool read_file(const char* path, void* buffer, size_t size);

// Returns the current working directory.
// Returns the empty string upon failure and reports the error to stderr.
std::string get_cwd();

} // namespace devtools_ijar

#endif // THIRD_PARTY_IJAR_PLATFORM_UTILS_H_
10 changes: 4 additions & 6 deletions third_party/ijar/zip_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <memory>
#include <set>
Expand Down Expand Up @@ -161,17 +160,16 @@ void basename(const char *path, char *output, size_t output_size) {
// Execute the extraction (or just listing if just v is provided)
int extract(char *zipfile, char* exdir, char **files, bool verbose,
bool extract) {
char cwd[PATH_MAX];
if (getcwd(cwd, PATH_MAX) == NULL) {
fprintf(stderr, "getcwd() failed: %s.\n", strerror(errno));
std::string cwd = get_cwd();
if (cwd.empty()) {
return -1;
}

char output_root[PATH_MAX];
if (exdir != NULL) {
concat_path(output_root, PATH_MAX, cwd, exdir);
concat_path(output_root, PATH_MAX, cwd.c_str(), exdir);
} else {
strncpy(output_root, cwd, PATH_MAX);
strncpy(output_root, cwd.c_str(), PATH_MAX);
}

UnzipProcessor processor(output_root, files, verbose, extract);
Expand Down

0 comments on commit 8457f3f

Please sign in to comment.