Home | History | Annotate | Download | only in lib
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/stream_executor/lib/process_state.h"
     17 
     18 #if defined(PLATFORM_WINDOWS)
     19 #include <direct.h>
     20 #include <stdlib.h>
     21 #include <WinSock2.h>
     22 #pragma comment(lib, "Ws2_32.lib")
     23 #else
     24 #include <unistd.h>
     25 #endif
     26 #include <memory>
     27 
     28 namespace perftools {
     29 namespace gputools {
     30 namespace port {
     31 
     32 string Hostname() {
     33   char hostname[1024];
     34   gethostname(hostname, sizeof hostname);
     35   hostname[sizeof hostname - 1] = 0;
     36   return std::string(hostname);
     37 }
     38 
     39 bool GetCurrentDirectory(string* dir) {
     40   size_t len = 128;
     41   std::unique_ptr<char[]> a(new char[len]);
     42   for (;;) {
     43     char* p = getcwd(a.get(), len);
     44     if (p != nullptr) {
     45       *dir = p;
     46       return true;
     47     } else if (errno == ERANGE) {
     48       len += len;
     49       a.reset(new char[len]);
     50     } else {
     51       return false;
     52     }
     53   }
     54 }
     55 
     56 }  // namespace port
     57 }  // namespace gputools
     58 }  // namespace perftools
     59