port.h 1.8 KB
Newer Older
D
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <string>

D
dzhwinter 已提交
19 20
#define GLOG_NO_ABBREVIATED_SEVERITIES  // msvc conflict logging with windows.h

D
dzhwinter 已提交
21
#if !defined(_WIN32)
chen.zhiyu's avatar
chen.zhiyu 已提交
22
#include <dlfcn.h>  // dladdr
W
wopeizl 已提交
23
#include <sys/time.h>
24

D
dzhwinter 已提交
25
#else
26
#ifndef NOMINMAX
W
wopeizl 已提交
27
#define NOMINMAX  // msvc max/min macro conflict with std::min/max
28
#endif
W
wopeizl 已提交
29 30 31
// solve static linking error in windows
// https://github.com/google/glog/issues/301
#define GOOGLE_GLOG_DLL_DECL
P
peizhilin 已提交
32 33 34
#include <io.h>  // _popen, _pclose
#include <stdio.h>
#include <windows.h>
35
#include <winsock.h>
36

R
Ruibiao Chen 已提交
37
#ifndef S_ISDIR  // windows port for sys/stat.h
P
peizhilin 已提交
38 39 40
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif  // S_ISDIR

R
Ruibiao Chen 已提交
41
void *dlsym(void *handle, const char *symbol_name);
42

R
Ruibiao Chen 已提交
43
void *dlopen(const char *filename, int flag);
W
wopeizl 已提交
44

R
Ruibiao Chen 已提交
45
int gettimeofday(struct timeval *tp, void *tzp);
D
dzhwinter 已提交
46 47
#endif  // !_WIN32

R
Ruibiao Chen 已提交
48
void ExecShellCommand(const std::string &cmd, std::string *message);
D
dzhwinter 已提交
49

R
Ruibiao Chen 已提交
50
bool PathExists(const std::string &path);
D
dzhwinter 已提交
51 52 53

// TODO(yuyang18): If the functions below are needed by other files, move them
// to paddle::filesystem namespace.
R
Ruibiao Chen 已提交
54
bool FileExists(const std::string &filepath);
D
dzhwinter 已提交
55

R
Ruibiao Chen 已提交
56
std::string DirName(const std::string &filepath);
D
dzhwinter 已提交
57

R
Ruibiao Chen 已提交
58
void MkDir(const char *path);
D
dzhwinter 已提交
59

R
Ruibiao Chen 已提交
60
void MkDirRecursively(const char *fullpath);