From: Kevin Wasserman Date: Thu, 20 Nov 2014 14:30:35 +0000 (-0500) Subject: On windows, change json_gssapi.exe to take filepath as arg X-Git-Url: http://www.project-moonshot.org/gitweb/?p=gssweb.git;a=commitdiff_plain;h=b65362cdc721f13a8afc5bc556106d1af3bcaec5 On windows, change json_gssapi.exe to take filepath as arg Reads entire file as a single command --- diff --git a/json_gssapi/main.cpp b/json_gssapi/main.cpp index 0729b13..26c23e1 100644 --- a/json_gssapi/main.cpp +++ b/json_gssapi/main.cpp @@ -5,7 +5,12 @@ #include #include #include -#ifndef WIN32 +#ifdef WIN32 +#include +#include +#include +#include +#else #include #endif #include @@ -22,14 +27,44 @@ int main(int argc, char **argv) { /* Variables */ string output; char *input; - int len; - ssize_t readTotal, readThisRound, readRemaining; + size_t len; /* Error checking */ /* Setup */ /* Main processing */ +#ifdef WIN32 + if (argc < 2) { + return -1; + } + int fd; + if (_sopen_s(&fd, argv[1], _O_BINARY, _SH_DENYNO, _S_IREAD) != 0) + { + cout << "error :" << errno << " opening file: " << argv[1] << "\n"; + return -1; + } + struct _stat fs; + if (_fstat(fd, &fs) != 0) { + cout << "error: " << errno << " from _fstat.\n"; + return -1; + } + + FILE *f =_fdopen(fd, "rb"); + if (f == NULL) { + cout << "error: " << errno << " from _fdopen.\n"; + return -1; + } + len = fs.st_size; + input = new char[len+1]; + size_t count = fread(input, 1, len, f) ; + if (count != len) { + cout << "expected " << len << " bytes from fread; got " << count << ".\n"; + return -1; + } + fclose(f); +#else + ssize_t readTotal, readThisRound, readRemaining; do { // Read 32 bit length @@ -54,9 +89,9 @@ int main(int argc, char **argv) { readTotal += readThisRound; } // ... and null-terminate it +#endif input[len] = '\0'; - GSSRequest *req = new GSSRequest(string(input)); req->execute(); output = req->getResponse(); @@ -65,8 +100,8 @@ int main(int argc, char **argv) { cout.write((char *)&len, 4); cout << output; cout.flush(); - +#ifndef WIN32 } while(1); - +#endif return 0; }