2015-11-25 04:51:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Andrew Kelley
|
|
|
|
*
|
|
|
|
* This file is part of zig, which is MIT licensed.
|
|
|
|
* See http://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZIG_OS_HPP
|
|
|
|
#define ZIG_OS_HPP
|
|
|
|
|
|
|
|
#include "list.hpp"
|
|
|
|
#include "buffer.hpp"
|
2017-03-14 01:11:55 +08:00
|
|
|
#include "error.hpp"
|
2017-12-27 08:44:08 +08:00
|
|
|
#include "zig_llvm.h"
|
2018-07-21 11:37:37 +08:00
|
|
|
#include "windows_sdk.h"
|
2015-11-25 04:51:36 +08:00
|
|
|
|
2015-12-01 10:58:53 +08:00
|
|
|
#include <stdio.h>
|
2017-06-27 02:41:47 +08:00
|
|
|
#include <inttypes.h>
|
2015-12-01 10:58:53 +08:00
|
|
|
|
2017-10-02 13:37:05 +08:00
|
|
|
enum TermColor {
|
|
|
|
TermColorRed,
|
|
|
|
TermColorGreen,
|
|
|
|
TermColorCyan,
|
|
|
|
TermColorWhite,
|
2017-12-04 18:22:34 +08:00
|
|
|
TermColorBold,
|
2017-10-02 13:37:05 +08:00
|
|
|
TermColorReset,
|
|
|
|
};
|
|
|
|
|
2016-05-08 10:58:02 +08:00
|
|
|
enum TerminationId {
|
|
|
|
TerminationIdClean,
|
|
|
|
TerminationIdSignaled,
|
|
|
|
TerminationIdStopped,
|
|
|
|
TerminationIdUnknown,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Termination {
|
|
|
|
TerminationId how;
|
|
|
|
int code;
|
|
|
|
};
|
|
|
|
|
2017-08-27 12:11:09 +08:00
|
|
|
int os_init(void);
|
2016-05-08 10:58:02 +08:00
|
|
|
|
|
|
|
void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term);
|
2016-02-18 06:56:06 +08:00
|
|
|
int os_exec_process(const char *exe, ZigList<const char *> &args,
|
2016-05-08 10:58:02 +08:00
|
|
|
Termination *term, Buf *out_stderr, Buf *out_stdout);
|
2015-11-25 04:51:36 +08:00
|
|
|
|
2016-04-19 06:47:21 +08:00
|
|
|
void os_path_dirname(Buf *full_path, Buf *out_dirname);
|
2015-11-25 10:07:33 +08:00
|
|
|
void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);
|
2017-03-31 17:48:15 +08:00
|
|
|
void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);
|
2015-12-01 10:58:53 +08:00
|
|
|
void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);
|
2015-12-16 12:48:41 +08:00
|
|
|
int os_path_real(Buf *rel_path, Buf *out_abs_path);
|
2016-04-19 06:47:21 +08:00
|
|
|
void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path);
|
|
|
|
bool os_path_is_absolute(Buf *path);
|
2015-11-25 10:07:33 +08:00
|
|
|
|
2018-03-31 14:04:01 +08:00
|
|
|
int os_get_global_cache_directory(Buf *out_tmp_path);
|
|
|
|
|
2017-04-28 14:22:12 +08:00
|
|
|
int os_make_path(Buf *path);
|
|
|
|
int os_make_dir(Buf *path);
|
|
|
|
|
2015-11-26 16:29:52 +08:00
|
|
|
void os_write_file(Buf *full_path, Buf *contents);
|
2017-04-11 18:14:46 +08:00
|
|
|
int os_copy_file(Buf *src_path, Buf *dest_path);
|
2015-11-26 16:29:52 +08:00
|
|
|
|
2018-03-31 14:04:01 +08:00
|
|
|
int os_fetch_file(FILE *file, Buf *out_contents, bool skip_shebang);
|
|
|
|
int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang);
|
2015-12-01 10:58:53 +08:00
|
|
|
|
|
|
|
int os_get_cwd(Buf *out_cwd);
|
|
|
|
|
2015-12-01 15:50:11 +08:00
|
|
|
bool os_stderr_tty(void);
|
2017-10-02 13:37:05 +08:00
|
|
|
void os_stderr_set_color(TermColor color);
|
2015-12-01 15:50:11 +08:00
|
|
|
|
2016-01-27 15:01:49 +08:00
|
|
|
int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path);
|
|
|
|
int os_delete_file(Buf *path);
|
|
|
|
|
2017-03-14 01:11:55 +08:00
|
|
|
int os_file_exists(Buf *full_path, bool *result);
|
|
|
|
|
2017-04-20 02:00:12 +08:00
|
|
|
int os_rename(Buf *src_path, Buf *dest_path);
|
2017-04-26 00:29:25 +08:00
|
|
|
double os_get_time(void);
|
2017-04-20 02:00:12 +08:00
|
|
|
|
2017-05-23 12:26:12 +08:00
|
|
|
bool os_is_sep(uint8_t c);
|
|
|
|
|
2017-10-02 06:29:50 +08:00
|
|
|
int os_self_exe_path(Buf *out_path);
|
|
|
|
|
2017-11-02 03:33:14 +08:00
|
|
|
int os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf *output_buf);
|
|
|
|
int os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
|
|
|
|
int os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
|
2017-11-02 10:47:15 +08:00
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define ZIG_OS_DARWIN
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#define ZIG_OS_WINDOWS
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#define ZIG_OS_LINUX
|
|
|
|
#else
|
|
|
|
#define ZIG_OS_UNKNOWN
|
2017-11-02 03:33:14 +08:00
|
|
|
#endif
|
|
|
|
|
2017-04-05 19:46:50 +08:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
#define ZIG_ARCH_X86_64
|
|
|
|
#else
|
|
|
|
#define ZIG_ARCH_UNKNOWN
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 12:26:12 +08:00
|
|
|
#if defined(ZIG_OS_WINDOWS)
|
2017-09-24 06:46:03 +08:00
|
|
|
#define ZIG_PRI_usize "I64u"
|
2017-05-23 12:26:12 +08:00
|
|
|
#define ZIG_PRI_u64 "I64u"
|
|
|
|
#define ZIG_PRI_llu "I64u"
|
|
|
|
#define ZIG_PRI_x64 "I64x"
|
2017-10-01 02:07:26 +08:00
|
|
|
#define OS_SEP "\\"
|
2017-10-16 08:15:01 +08:00
|
|
|
#define ZIG_OS_SEP_CHAR '\\'
|
2017-05-23 12:26:12 +08:00
|
|
|
#else
|
|
|
|
#define ZIG_PRI_usize "zu"
|
|
|
|
#define ZIG_PRI_u64 PRIu64
|
|
|
|
#define ZIG_PRI_llu "llu"
|
|
|
|
#define ZIG_PRI_x64 PRIx64
|
2017-10-01 02:07:26 +08:00
|
|
|
#define OS_SEP "/"
|
2017-10-16 08:15:01 +08:00
|
|
|
#define ZIG_OS_SEP_CHAR '/'
|
2017-05-23 12:26:12 +08:00
|
|
|
#endif
|
|
|
|
|
2015-11-25 04:51:36 +08:00
|
|
|
#endif
|