This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +147
-0
lines changed Expand file tree Collapse file tree 4 files changed +147
-0
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 2.8.12 )
2
+ project (CoreFX )
3
+
4
+ set (CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir} )
5
+ set (CMAKE_INCLUDE_CURRENT_DIR ON )
6
+ set (CMAKE_C_FLAGS "-std=c11" )
7
+ set (CMAKE_CXX_FLAGS "-std=c++11" )
8
+ set (CMAKE_SHARED_LIBRARY_PREFIX "" )
9
+ add_compile_options (-Wall -Werror -fPIC )
10
+
11
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64 )
12
+ add_definitions (-DBIT64=1 )
13
+ endif ()
14
+
15
+ string (TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE )
16
+ if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG )
17
+ add_compile_options (-g -O0 )
18
+ add_definitions (-DDEBUG )
19
+ elseif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE )
20
+ add_compile_options (-O3 )
21
+ add_definitions (-DNDEBUG )
22
+ else ()
23
+ message (FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE." )
24
+ endif ()
25
+
26
+ add_subdirectory (System .IO.Native )
Original file line number Diff line number Diff line change
1
+
2
+ project (System .IO.Native )
3
+
4
+ set (NATIVEIO_SOURCES
5
+ nativeio.h
6
+ nativeio.cpp
7
+ )
8
+
9
+ add_library (System .IO.Native
10
+ SHARED
11
+ ${NATIVEIO_SOURCES}
12
+ )
13
+
14
+ install (TARGETS System .IO.Native DESTINATION . )
15
+
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright (c) Microsoft. All rights reserved.
3
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
+ //
5
+
6
+ #include " nativeio.h"
7
+ #include < sys/stat.h>
8
+
9
+ #if HAVE_STAT64 && !(defined(__APPLE__) && defined(_AMD64_))
10
+ # define stat_ stat64
11
+ # define fstat_ fstat64
12
+ #else
13
+ # define stat_ stat
14
+ # define fstat_ fstat
15
+ #endif
16
+
17
+ static void ConvertFileStats (const struct stat_ & src, FileStats* dst)
18
+ {
19
+ dst->Flags = FILESTATS_FLAGS_NONE;
20
+ dst->Mode = src.st_mode ;
21
+ dst->Uid = src.st_uid ;
22
+ dst->Gid = src.st_gid ;
23
+ dst->Size = src.st_size ;
24
+ dst->AccessTime = src.st_atime ;
25
+ dst->ModificationTime = src.st_mtime ;
26
+ dst->StatusChangeTime = src.st_ctime ;
27
+
28
+ #if HAVE_STAT_BIRTHTIME
29
+ dst->CreationTime = src->st_birthtime ;
30
+ dst->Flags |= FILESTATS_FLAGS_HAS_CREATION_TIME;
31
+ #endif
32
+ }
33
+
34
+ extern " C"
35
+ {
36
+ int32_t GetFileStatsFromPath (const char * path, struct FileStats * output)
37
+ {
38
+ struct stat_ result;
39
+ int ret = stat_ (path, &result);
40
+
41
+ if (ret == 0 )
42
+ {
43
+ ConvertFileStats (result, output);
44
+ }
45
+
46
+ return ret;
47
+ }
48
+
49
+ int32_t GetFileStatsFromDescriptor (int32_t fileDescriptor, FileStats* output)
50
+ {
51
+ struct stat_ result;
52
+ int ret = fstat_ (fileDescriptor, &result);
53
+
54
+ if (ret == 0 )
55
+ {
56
+ ConvertFileStats (result, output);
57
+ }
58
+
59
+ return ret;
60
+ }
61
+ }
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright (c) Microsoft. All rights reserved.
3
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
+ //
5
+
6
+ #pragma once
7
+
8
+ #include <stdint.h>
9
+
10
+ extern "C"
11
+ {
12
+ struct FileStats
13
+ {
14
+ int32_t Flags ; // flags for testing if some members are present (see values below)
15
+ int32_t Mode ; // protection
16
+ int32_t Uid ; // user ID of owner
17
+ int32_t Gid ; // group ID of owner
18
+ int64_t Size ; // total size, in bytes
19
+ int64_t AccessTime ; // time of last access (atime)
20
+ int64_t ModificationTime ; // time of last modification (mtime)
21
+ int64_t StatusChangeTime ; // time of last status change (ctime)
22
+ int64_t CreationTime ; // time the file was created (birthtime)
23
+ };
24
+
25
+ enum
26
+ {
27
+ FILESTATS_FLAGS_NONE = 0 ,
28
+ FILESTATS_FLAGS_HAS_CREATION_TIME = 1 ,
29
+ };
30
+
31
+ /**
32
+ * Get file stats from a decriptor. Implemented as shim to fstat(2).
33
+ *
34
+ * Returns 0 for success, -1 for failure. Sets errno on failure.
35
+ */
36
+ int32_t GetFileStatsFromDescriptor (int32_t fileDescriptor , FileStats * output );
37
+
38
+ /**
39
+ * Get file stats from a full path. Implemented as shim to stat(2).
40
+ *
41
+ * Returns 0 for success, -1 for failure. Sets errno on failure.
42
+ */
43
+ int32_t GetFileStatsFromPath (const char * path , FileStats * output );
44
+ }
45
+
You can’t perform that action at this time.
0 commit comments