From 93ccf450f3fe7e1433426b6b17deebe1b22f396b Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Tue, 23 Dec 2014 14:01:22 -0500 Subject: [PATCH] windows fix main.cpp for windows chrome --- json_gssapi/main.cpp | 67 +++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 53 deletions(-) diff --git a/json_gssapi/main.cpp b/json_gssapi/main.cpp index 6db2850..fb7f28a 100644 --- a/json_gssapi/main.cpp +++ b/json_gssapi/main.cpp @@ -1,20 +1,13 @@ -#include -#include -#include -#include -#include +// #include -#include #ifdef WIN32 -#include -#include +#include #include -#include +#include #else #include #include #endif -#include #include @@ -22,13 +15,12 @@ using std::cin; using std::cout; using std::endl; using std::getline; -using std::string; int main(int argc, char **argv) { /* Variables */ - string output; char *input; - size_t len; + char *output; + int32_t len; /* Error checking */ @@ -36,37 +28,9 @@ int main(int argc, char **argv) { /* 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 readThisRound; - size_t readTotal, readRemaining; + _setmode(_fileno(stdin), _O_BINARY); +#endif + int readThisRound, readTotal, readRemaining; do { // Read 32 bit length @@ -74,7 +38,7 @@ int main(int argc, char **argv) { readThisRound = readTotal = 0; while(4 != readTotal) { - readThisRound = read(0, ((&len) + readTotal), 4 - readTotal); + readThisRound = _read(0, ((&len) + readTotal), 4 - readTotal); readTotal += readThisRound; } @@ -84,25 +48,22 @@ int main(int argc, char **argv) { while (readTotal < len) { readRemaining = len - readTotal; - readThisRound = read( 0, &(input[readTotal]), readRemaining); + readThisRound = _read( 0, &(input[readTotal]), readRemaining); if (-1 == readThisRound) break; else readTotal += readThisRound; } // ... and null-terminate it -#endif input[len] = '\0'; - char *out = gss_request(input); - len = strlen(out); + output = gss_request(input); + len = (int32_t )strlen(output); cout.write((char *)&len, 4); - cout << out; - deallocate_reply(out); + cout << output; + deallocate_reply(output); cout.flush(); -#ifndef WIN32 } while(1); -#endif return 0; } -- 2.1.4