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 21
#define GLOG_NO_ABBREVIATED_SEVERITIES  // msvc conflict logging with windows.h
#include "glog/logging.h"

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

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

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

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

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

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

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

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

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

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

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

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