├── LICENSE ├── README.md ├── cpp_path ├── cpp_path.cpp └── cpp_path.hpp ├── kcpplib.cpp ├── kcpplib.h ├── kcpplib.sln ├── kcpplib.vcxproj ├── kcpplib.vcxproj.filters ├── kcrt ├── err.c ├── fltintrn.c ├── invargc.c ├── kcrt.h ├── kcrtc.c ├── kcrtfs.c ├── strtod.c └── strtoll.c └── kstl ├── Singleton.h ├── kernel_stl.cpp ├── kernel_stl.h ├── kstl.h ├── kstl_stdint.h ├── kstlhead.h ├── scope.h ├── stdcpp.cpp └── typeinfo.cpp /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 gmh5225 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kcpplib 2 | The driver STL library used by myself 3 | 4 | ## Note 5 | You should link " 6 | bufferoverflowK.lib 7 | libcntpr.lib 8 | wdm.lib 9 | wdmsec.lib 10 | aux_klib.lib 11 | Ntstrsafe.lib 12 | Netio.lib 13 | tdi.lib 14 | fltMgr.lib 15 | Ntoskrnl.lib " 16 | 17 | to your project. 18 | 19 | ## Compile 20 | llvm-msvc [[link]](https://github.com/NewWorldComingSoon/llvm-msvc-build) 21 | -------------------------------------------------------------------------------- /cpp_path/cpp_path.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/cpp_path/cpp_path.cpp -------------------------------------------------------------------------------- /cpp_path/cpp_path.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../kstl\kstl.h" 3 | 4 | #ifndef _APATHY_PATH_HPP_ 5 | # define _APATHY_PATH_HPP_ 6 | 7 | /* C++ includes */ 8 | 9 | # ifndef _EASTL 10 | # include 11 | # include 12 | # else 13 | # include 14 | # include 15 | # endif // _EASTL 16 | 17 | /* A class for path manipulation */ 18 | namespace apathy { 19 | 20 | namespace stlx { 21 | # ifndef _EASTL 22 | using string = std::string; 23 | template 24 | using vector = std::vector; 25 | # else 26 | using string = eastl::string; 27 | template 28 | using vector = eastl::vector; 29 | # endif // _EASTL 30 | } // namespace stlx 31 | 32 | class Path 33 | { 34 | public: 35 | /* This is the separator used on this particular system */ 36 | # ifdef __MSDOS__ 37 | # error "Platforms using backslashes not yet supported" 38 | # else 39 | static const char separator = '/'; 40 | # endif 41 | /* A class meant to contain path segments */ 42 | struct Segment 43 | { 44 | /* The actual string segment */ 45 | stlx::string segment; 46 | 47 | Segment(stlx::string s = "") : segment(s) {} 48 | }; 49 | 50 | /********************************************************************** 51 | * Constructors 52 | *********************************************************************/ 53 | 54 | /* Default constructor 55 | * 56 | * Points to current directory */ 57 | Path(const stlx::string &path = "") : path(path) {} 58 | 59 | /* Our generalized constructor. 60 | * 61 | * This enables all sorts of type promotion (like int -> Path) for 62 | * arguments into all the functions below. Anything that 63 | * std::stringstream can support is implicitly supported as well 64 | * 65 | * @param p - path to construct */ 66 | Path(const char *str); 67 | 68 | /********************************************************************** 69 | * Operators 70 | *********************************************************************/ 71 | /* Checks if the paths are exactly the same */ 72 | bool operator==(const Path &other) { return path == other.path; } 73 | 74 | /* Check if the paths are not exactly the same */ 75 | bool operator!=(const Path &other) { return !(*this == other); } 76 | 77 | /* Append the provided segment to the path as a directory. This is the 78 | * same as append(segment) 79 | * 80 | * @param segment - path segment to add to this path */ 81 | Path &operator<<(const Path &segment); 82 | 83 | /* Append the provided segment to the path as a directory. This is the 84 | * same as append(segment). Returns a /new/ path object rather than a 85 | * reference. 86 | * 87 | * @param segment - path segment to add to this path */ 88 | Path operator+(const Path &segment) const; 89 | 90 | /* Check if the two paths are equivalent 91 | * 92 | * Two paths are equivalent if they point to the same resource, even if 93 | * they are not exact string matches 94 | * 95 | * @param other - path to compare to */ 96 | bool equivalent(const Path &other); 97 | 98 | /* Return a string version of this path */ 99 | stlx::string string() const { return path; } 100 | 101 | /* Return the name of the file */ 102 | stlx::string filename() const; 103 | 104 | /* Return the extension of the file */ 105 | stlx::string extension() const; 106 | 107 | /* Return a path object without the extension */ 108 | Path stem() const; 109 | 110 | /********************************************************************** 111 | * Manipulations 112 | *********************************************************************/ 113 | 114 | /* Append the provided segment to the path as a directory. Alias for 115 | * `operator<<` 116 | * 117 | * @param segment - path segment to add to this path */ 118 | Path &append(const Path &segment); 119 | 120 | /* Evaluate the provided path relative to this path. If the second path 121 | * is absolute, then return the second path. 122 | * 123 | * @param rel - path relative to this path to evaluate */ 124 | Path &relative(const Path &rel); 125 | 126 | /* Move up one level in the directory structure */ 127 | Path &up(); 128 | 129 | /* Turn this into an absolute path 130 | * 131 | * If the path is already absolute, it has no effect. Otherwise, it is 132 | * evaluated relative to the current working directory */ 133 | Path &absolute(); 134 | 135 | /* Sanitize this path 136 | * 137 | * This... 138 | * 139 | * 1) replaces runs of consecutive separators with a single separator 140 | * 2) evaluates '..' to refer to the parent directory, and 141 | * 3) strips out '/./' as referring to the current directory 142 | * 143 | * If the path was absolute to begin with, it will be absolute 144 | * afterwards. If it was a relative path to begin with, it will only be 145 | * converted to an absolute path if it uses enough '..'s to refer to 146 | * directories above the current working directory */ 147 | Path &sanitize(); 148 | 149 | /* Make this path a directory 150 | * 151 | * If this path does not have a trailing directory separator, add one. 152 | * If it already does, this does not affect the path */ 153 | Path &directory(); 154 | 155 | /* Trim this path of trailing separators, up to the leading separator. 156 | * For example, on *nix systems: 157 | * 158 | * assert(Path("///").trim() == "/"); 159 | * assert(Path("/foo//").trim() == "/foo"); 160 | */ 161 | Path &trim(); 162 | 163 | /********************************************************************** 164 | * Copiers 165 | *********************************************************************/ 166 | 167 | /* Return parent path 168 | * 169 | * Returns a new Path object referring to the parent directory. To 170 | * move _this_ path to the parent directory, use the `up` function */ 171 | Path parent() const { return Path(Path(*this).up()); } 172 | 173 | /********************************************************************** 174 | * Member Utility Methods 175 | *********************************************************************/ 176 | 177 | /* Returns a vector of each of the path segments in this path */ 178 | stlx::vector split() const; 179 | 180 | /********************************************************************** 181 | * Type Tests 182 | *********************************************************************/ 183 | /* Is the path an absolute path? */ 184 | bool is_absolute() const; 185 | 186 | /* Does the path have a trailing slash? */ 187 | bool trailing_slash() const; 188 | 189 | /********************************************************************** 190 | * Static Utility Methods 191 | *********************************************************************/ 192 | 193 | /* Return a brand new path as the concatenation of the two provided 194 | * paths 195 | * 196 | * @param a - first part of the path to join 197 | * @param b - second part of the path to join 198 | */ 199 | static Path join(const Path &a, const Path &b); 200 | 201 | /* Return a branch new path as the concatenation of each segments 202 | * 203 | * @param segments - the path segments to concatenate 204 | */ 205 | static Path join(const stlx::vector &segments); 206 | 207 | /* Current working directory */ 208 | static Path cwd(); 209 | 210 | private: 211 | /* Our current path */ 212 | stlx::string path; 213 | }; 214 | 215 | /* Constructor */ 216 | Path::Path(const char *str) : path(str) {} 217 | 218 | /************************************************************************** 219 | * Operators 220 | *************************************************************************/ 221 | Path & 222 | Path::operator<<(const Path &segment) 223 | { 224 | return append(segment); 225 | } 226 | 227 | Path 228 | Path::operator+(const Path &segment) const 229 | { 230 | Path result(path); 231 | result.append(segment); 232 | return result; 233 | } 234 | 235 | bool 236 | Path::equivalent(const Path &other) 237 | { 238 | /* Make copies of both paths, sanitize, and ensure they're equal */ 239 | return Path(path).absolute().sanitize() == Path(other).absolute().sanitize(); 240 | } 241 | 242 | stlx::string 243 | Path::filename() const 244 | { 245 | size_t pos = path.rfind(separator); 246 | if (pos != stlx::string::npos) 247 | { 248 | return path.substr(pos + 1); 249 | } 250 | return ""; 251 | } 252 | 253 | stlx::string 254 | Path::extension() const 255 | { 256 | /* Make sure we only look in the filename, and not the path */ 257 | stlx::string name = filename(); 258 | size_t pos = name.rfind('.'); 259 | if (pos != stlx::string::npos) 260 | { 261 | return name.substr(pos + 1); 262 | } 263 | return ""; 264 | } 265 | 266 | Path 267 | Path::stem() const 268 | { 269 | size_t sep_pos = path.rfind(separator); 270 | size_t dot_pos = path.rfind('.'); 271 | if (dot_pos == stlx::string::npos) 272 | { 273 | return Path(*this); 274 | } 275 | 276 | if (sep_pos == stlx::string::npos || sep_pos < dot_pos) 277 | { 278 | return Path(path.substr(0, dot_pos)); 279 | } 280 | else 281 | { 282 | return Path(*this); 283 | } 284 | } 285 | 286 | /************************************************************************** 287 | * Manipulators 288 | *************************************************************************/ 289 | Path & 290 | Path::append(const Path &segment) 291 | { 292 | /* First, check if the last character is the separator character. 293 | * If not, then append one and then the segment. Otherwise, just 294 | * the segment */ 295 | if (!trailing_slash()) 296 | { 297 | path.push_back(separator); 298 | } 299 | path.append(segment.path); 300 | return *this; 301 | } 302 | 303 | Path & 304 | Path::relative(const Path &rel) 305 | { 306 | if (!rel.is_absolute()) 307 | { 308 | return append(rel); 309 | } 310 | else 311 | { 312 | operator=(rel); 313 | return *this; 314 | } 315 | } 316 | 317 | Path & 318 | Path::up() 319 | { 320 | /* Make sure we turn this into an absolute url if it's not already 321 | * one */ 322 | if (path.size() == 0) 323 | { 324 | path = ".."; 325 | return directory(); 326 | } 327 | 328 | append("..").sanitize(); 329 | if (path.size() == 0) 330 | { 331 | return *this; 332 | } 333 | return directory(); 334 | } 335 | 336 | Path & 337 | Path::absolute() 338 | { 339 | /* If the path doesn't begin with our separator, then it's not an 340 | * absolute path, and should be appended to the current working 341 | * directory */ 342 | if (!is_absolute()) 343 | { 344 | /* Join our current working directory with the path */ 345 | operator=(join(cwd(), path)); 346 | } 347 | return *this; 348 | } 349 | 350 | Path & 351 | Path::sanitize() 352 | { 353 | /* Split the path up into segments */ 354 | stlx::vector segments(split()); 355 | /* We may have to test this repeatedly, so let's check once */ 356 | bool is_relative = !is_absolute(); 357 | 358 | /* Now, we'll create a new set of segments */ 359 | stlx::vector pruned; 360 | for (size_t pos = 0; pos < segments.size(); ++pos) 361 | { 362 | /* Skip over empty segments and '.' */ 363 | if (segments[pos].segment.size() == 0 || segments[pos].segment == ".") 364 | { 365 | continue; 366 | } 367 | 368 | /* If there is a '..', then pop off a parent directory. However, if 369 | * the path was relative to begin with, if the '..'s exceed the 370 | * stack depth, then they should be appended to our path. If it was 371 | * absolute to begin with, and we reach root, then '..' has no 372 | * effect */ 373 | if (segments[pos].segment == "..") 374 | { 375 | if (is_relative) 376 | { 377 | if (pruned.size() && pruned.back().segment != "..") 378 | { 379 | pruned.pop_back(); 380 | } 381 | else 382 | { 383 | pruned.push_back(segments[pos]); 384 | } 385 | } 386 | else if (pruned.size()) 387 | { 388 | pruned.pop_back(); 389 | } 390 | continue; 391 | } 392 | 393 | pruned.push_back(segments[pos]); 394 | } 395 | 396 | bool was_directory = trailing_slash(); 397 | if (!is_relative) 398 | { 399 | path = stlx::string(1, separator) + Path::join(pruned).path; 400 | if (was_directory) 401 | { 402 | return directory(); 403 | } 404 | return *this; 405 | } 406 | 407 | /* It was a relative path */ 408 | path = Path::join(pruned).path; 409 | if (path.length() && was_directory) 410 | { 411 | return directory(); 412 | } 413 | return *this; 414 | } 415 | 416 | Path & 417 | Path::directory() 418 | { 419 | trim(); 420 | path.push_back(separator); 421 | return *this; 422 | } 423 | 424 | Path & 425 | Path::trim() 426 | { 427 | if (path.length() == 0) 428 | { 429 | return *this; 430 | } 431 | 432 | size_t p = path.find_last_not_of(separator); 433 | if (p != stlx::string::npos) 434 | { 435 | path.erase(p + 1, path.size()); 436 | } 437 | else 438 | { 439 | path = ""; 440 | } 441 | return *this; 442 | } 443 | 444 | /************************************************************************** 445 | * Member Utility Methods 446 | *************************************************************************/ 447 | 448 | /* Returns a vector of each of the path segments in this path */ 449 | stlx::vector 450 | Path::split() const 451 | { 452 | stlx::string t; 453 | stlx::vector results; 454 | 455 | for (char c : path) 456 | { 457 | if (c == separator) 458 | { 459 | results.push_back(t); 460 | t.clear(); 461 | } 462 | else 463 | { 464 | t.append(1, c); 465 | } 466 | } 467 | if (!t.empty()) 468 | results.push_back(t); 469 | 470 | if (trailing_slash()) 471 | { 472 | results.push_back(Path::Segment("")); 473 | } 474 | return results; 475 | } 476 | 477 | /************************************************************************** 478 | * Tests 479 | *************************************************************************/ 480 | bool 481 | Path::is_absolute() const 482 | { 483 | return path.size() && path[0] == separator; 484 | } 485 | 486 | bool 487 | Path::trailing_slash() const 488 | { 489 | return path.size() && path[path.length() - 1] == separator; 490 | } 491 | 492 | /************************************************************************** 493 | * Static Utility Methods 494 | *************************************************************************/ 495 | Path 496 | Path::join(const Path &a, const Path &b) 497 | { 498 | Path p(a); 499 | p.append(b); 500 | return p; 501 | } 502 | 503 | Path 504 | Path::join(const stlx::vector &segments) 505 | { 506 | stlx::string path; 507 | /* Now, we'll go through the segments, and join them with 508 | * separator */ 509 | stlx::vector::const_iterator it(segments.begin()); 510 | for (; it != segments.end(); ++it) 511 | { 512 | path += it->segment; 513 | if (it + 1 != segments.end()) 514 | { 515 | path += stlx::string(1, separator); 516 | } 517 | } 518 | return Path(path); 519 | } 520 | 521 | Path 522 | Path::cwd() 523 | { 524 | Path p("/"); 525 | 526 | /* Ensure this is a directory */ 527 | p.directory(); 528 | return p; 529 | } 530 | } // namespace apathy 531 | 532 | #endif 533 | -------------------------------------------------------------------------------- /kcpplib.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kcpplib.cpp -------------------------------------------------------------------------------- /kcpplib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kcpplib.h -------------------------------------------------------------------------------- /kcpplib.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31613.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kcpplib", "kcpplib.vcxproj", "{93EC3005-E0F9-4327-9B54-57F74EA4B09D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Release|x64 = Release|x64 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {93EC3005-E0F9-4327-9B54-57F74EA4B09D}.Release|x64.ActiveCfg = Release|x64 14 | {93EC3005-E0F9-4327-9B54-57F74EA4B09D}.Release|x64.Build.0 = Release|x64 15 | {93EC3005-E0F9-4327-9B54-57F74EA4B09D}.Release|x64.Deploy.0 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {A2F23FB9-6EEE-42D8-A29C-4C9B5FD1F2D1} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /kcpplib.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Release 6 | x64 7 | 8 | 9 | 10 | {93EC3005-E0F9-4327-9B54-57F74EA4B09D} 11 | {1bc93793-694f-48fe-9372-81e2b05556fd} 12 | v4.5 13 | 12.0 14 | Debug 15 | Win32 16 | kcpplib 17 | $(LatestTargetPlatformVersion) 18 | 19 | 20 | 21 | Windows10 22 | false 23 | LLVM-MSVC_v143_KernelMode 24 | StaticLibrary 25 | KMDF 26 | 27 | 28 | false 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | DbgengKernelDebugger 41 | $(SolutionDir)Output 42 | $(VC_IncludePath);$(ProjectDir)../;$(IncludePath) 43 | 44 | 45 | 46 | false 47 | DriverEntry 48 | true 49 | 50 | 51 | Level3 52 | 53 | 54 | false 55 | false 56 | false 57 | -cbstring %(ClCompile.AdditionalOptions) 58 | false 59 | stdcpp17 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /kcpplib.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {a23e8903-ccfc-4f57-b56c-329d9765917b} 6 | 7 | 8 | {c3996a20-23c2-464c-adc3-4367af8f0744} 9 | 10 | 11 | {1bba55f9-bb52-4d18-b189-ec084c9a272b} 12 | 13 | 14 | 15 | 16 | kcrt 17 | 18 | 19 | kcrt 20 | 21 | 22 | kcrt 23 | 24 | 25 | kcrt 26 | 27 | 28 | kcrt 29 | 30 | 31 | kcrt 32 | 33 | 34 | kcrt 35 | 36 | 37 | cpp_path 38 | 39 | 40 | kstl 41 | 42 | 43 | kstl 44 | 45 | 46 | kstl 47 | 48 | 49 | 50 | 51 | 52 | kcrt 53 | 54 | 55 | cpp_path 56 | 57 | 58 | kstl 59 | 60 | 61 | kstl 62 | 63 | 64 | kstl 65 | 66 | 67 | kstl 68 | 69 | 70 | kstl 71 | 72 | 73 | kstl 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /kcrt/err.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // char *_sys_errlist[] = 4 | //{ 5 | // /* 0 */ "No error", 6 | // /* 1 EPERM */ "Operation not permitted", 7 | // /* 2 ENOENT */ "No such file or directory", 8 | // /* 3 ESRCH */ "No such process", 9 | // /* 4 EINTR */ "Interrupted function call", 10 | // /* 5 EIO */ "Input/output error", 11 | // /* 6 ENXIO */ "No such device or address", 12 | // /* 7 E2BIG */ "Arg list too long", 13 | // /* 8 ENOEXEC */ "Exec format error", 14 | // /* 9 EBADF */ "Bad file descriptor", 15 | // /* 10 ECHILD */ "No child processes", 16 | // /* 11 EAGAIN */ "Resource temporarily unavailable", 17 | // /* 12 ENOMEM */ "Not enough space", 18 | // /* 13 EACCES */ "Permission denied", 19 | // /* 14 EFAULT */ "Bad address", 20 | // /* 15 ENOTBLK */ "Unknown error", /* not POSIX */ 21 | // /* 16 EBUSY */ "Resource device", 22 | // /* 17 EEXIST */ "File exists", 23 | // /* 18 EXDEV */ "Improper link", 24 | // /* 19 ENODEV */ "No such device", 25 | // /* 20 ENOTDIR */ "Not a directory", 26 | // /* 21 EISDIR */ "Is a directory", 27 | // /* 22 EINVAL */ "Invalid argument", 28 | // /* 23 ENFILE */ "Too many open files in system", 29 | // /* 24 EMFILE */ "Too many open files", 30 | // /* 25 ENOTTY */ "Inappropriate I/O control operation", 31 | // /* 26 ETXTBSY */ "Unknown error", /* not POSIX */ 32 | // /* 27 EFBIG */ "File too large", 33 | // /* 28 ENOSPC */ "No space left on device", 34 | // /* 29 ESPIPE */ "Invalid seek", 35 | // /* 30 EROFS */ "Read-only file system", 36 | // /* 31 EMLINK */ "Too many links", 37 | // /* 32 EPIPE */ "Broken pipe", 38 | // /* 33 EDOM */ "Domain error", 39 | // /* 34 ERANGE */ "Result too large", 40 | // /* 35 EUCLEAN */ "Unknown error", /* not POSIX */ 41 | // /* 36 EDEADLK */ "Resource deadlock avoided", 42 | // /* 37 UNKNOWN */ "Unknown error", 43 | // /* 38 ENAMETOOLONG */ "Filename too long", 44 | // /* 39 ENOLCK */ "No locks available", 45 | // /* 40 ENOSYS */ "Function not implemented", 46 | // /* 41 ENOTEMPTY */ "Directory not empty", 47 | // /* 42 EILSEQ */ "Illegal byte sequence", 48 | // /* 43 */ "Unknown error" 49 | //}; 50 | 51 | char *_sys_errlist[] = { 52 | /* 0 */ "0", 53 | /* 1 EPERM */ "1", 54 | /* 2 ENOENT */ "2", 55 | /* 3 ESRCH */ "3", 56 | /* 4 EINTR */ "4", 57 | /* 5 EIO */ "5", 58 | /* 6 ENXIO */ "6", 59 | /* 7 E2BIG */ "7", 60 | /* 8 ENOEXEC */ "8", 61 | /* 9 EBADF */ "9", 62 | /* 10 ECHILD */ "10", 63 | /* 11 EAGAIN */ "11", 64 | /* 12 ENOMEM */ "12", 65 | /* 13 EACCES */ "13", 66 | /* 14 EFAULT */ "14", 67 | /* 15 ENOTBLK */ "15", /* not POSIX */ 68 | /* 16 EBUSY */ "16", 69 | /* 17 EEXIST */ "17", 70 | /* 18 EXDEV */ "18", 71 | /* 19 ENODEV */ "19", 72 | /* 20 ENOTDIR */ "20", 73 | /* 21 EISDIR */ "21", 74 | /* 22 EINVAL */ "22", 75 | /* 23 ENFILE */ "23", 76 | /* 24 EMFILE */ "24", 77 | /* 25 ENOTTY */ "25", 78 | /* 26 ETXTBSY */ "26", /* not POSIX */ 79 | /* 27 EFBIG */ "27", 80 | /* 28 ENOSPC */ "28", 81 | /* 29 ESPIPE */ "29", 82 | /* 30 EROFS */ "30", 83 | /* 31 EMLINK */ "31", 84 | /* 32 EPIPE */ "32", 85 | /* 33 EDOM */ "33", 86 | /* 34 ERANGE */ "34", 87 | /* 35 EUCLEAN */ "35", /* not POSIX */ 88 | /* 36 EDEADLK */ "36", 89 | /* 37 UNKNOWN */ "37", 90 | /* 38 ENAMETOOLONG */ "38", 91 | /* 39 ENOLCK */ "39", 92 | /* 40 ENOSYS */ "40", 93 | /* 41 ENOTEMPTY */ "41", 94 | /* 42 EILSEQ */ "42", 95 | /* 43 */ "43"}; 96 | 97 | int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]) - 1; 98 | 99 | #define _sys_err_msg(m) _sys_errlist[(((m) < 0) || ((m) >= _sys_nerr) ? _sys_nerr : (m))] 100 | 101 | const char * 102 | _get_sys_err_msg(int m) 103 | { 104 | return _sys_err_msg(m); 105 | } 106 | 107 | #define _SYS_MSGMAX 38 108 | #define _ERRMSGLEN_ (94 + _SYS_MSGMAX + 2) 109 | 110 | char *__cdecl strerror(int errnum) 111 | { 112 | static char errmsg[_ERRMSGLEN_ + 1]; 113 | RtlSecureZeroMemory(errmsg, sizeof(errmsg)); 114 | 115 | //暂时不实现,直接返回空 116 | // mycrt_strncpy_a(errmsg, _ERRMSGLEN_, _get_sys_err_msg(errnum),); 117 | 118 | return (errmsg); 119 | } 120 | 121 | int _kerrno = 0; 122 | 123 | int *__cdecl _errno(void) 124 | { 125 | return &_kerrno; 126 | } 127 | -------------------------------------------------------------------------------- /kcrt/fltintrn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct _flt 6 | { 7 | int flags; 8 | int nbytes; /* number of characters read */ 9 | long lval; 10 | double dval; /* the returned floating point number */ 11 | } * FLT; 12 | 13 | #ifndef MTHREAD 14 | static struct _flt ret; 15 | static FLT flt = &ret; 16 | #endif 17 | 18 | typedef ULONG *intrnman; 19 | 20 | /* The only three conditions that this routine detects */ 21 | #define CFIN_NODIGITS 512 22 | #define CFIN_OVERFLOW 128 23 | #define CFIN_UNDERFLOW 256 24 | 25 | #define SLD_UNDERFLOW 1 26 | #define SLD_OVERFLOW 2 27 | #define SLD_NODIGITS 4 28 | 29 | #define MAX_MAN_DIGITS 21 30 | 31 | #define TMAX10 5200 /* maximum temporary decimal exponent */ 32 | #define TMIN10 -5200 /* minimum temporary decimal exponent */ 33 | #define LD_MAX_EXP_LEN 4 /* maximum number of decimal exponent digits */ 34 | #define LD_MAX_MAN_LEN 24 /* maximum length of mantissa (decimal)*/ 35 | #define LD_MAX_MAN_LEN1 25 /* MAX_MAN_LEN+1 */ 36 | 37 | #define INTRNMAN_LEN 3 /* internal mantissa length in int's */ 38 | 39 | #define PTR_12(x) ((UCHAR *)(&(x)->ld12)) 40 | 41 | /* a pointer to the exponent/sign portion */ 42 | #define U_EXP_12(p) ((USHORT *)(PTR_12(p) + 10)) 43 | 44 | /* a pointer to the 4 hi-order bytes of the mantissa */ 45 | #define UL_MANHI_12(p) ((ULONG *)(PTR_12(p) + 6)) 46 | 47 | /* a pointer to the 4 lo-order bytes of the ordinary (8-byte) mantissa */ 48 | #define UL_MANLO_12(p) ((ULONG *)(PTR_12(p) + 2)) 49 | 50 | /* a pointer to the 2 extra bytes of the mantissa */ 51 | #define U_XT_12(p) ((USHORT *)PTR_12(p)) 52 | 53 | /* a pointer to the 4 lo-order bytes of the extended (10-byte) mantissa */ 54 | #define UL_LO_12(p) ((ULONG *)PTR_12(p)) 55 | 56 | /* a pointer to the 4 mid-order bytes of the extended (10-byte) mantissa */ 57 | #define UL_MED_12(p) ((ULONG *)(PTR_12(p) + 4)) 58 | 59 | /* a pointer to the 4 hi-order bytes of the extended long double */ 60 | #define UL_HI_12(p) ((ULONG *)(PTR_12(p) + 8)) 61 | 62 | /* a pointer to the byte of order i (LSB=0, MSB=9)*/ 63 | #define UCHAR_12(p, i) ((UCHAR *)PTR_12(p) + (i)) 64 | 65 | /* a pointer to a u_short with offset i */ 66 | #define USHORT_12(p, i) ((USHORT *)((UCHAR *)PTR_12(p) + (i))) 67 | 68 | /* a pointer to a u_long with offset i */ 69 | #define ULONG_12(p, i) ((ULONG *)((UCHAR *)PTR_12(p) + (i))) 70 | 71 | /* a pointer to the 10 MSBytes of a 12-byte long double */ 72 | #define TEN_BYTE_PART(p) ((UCHAR *)PTR_12(p) + 2) 73 | 74 | #define UL_HI_D(p) ((ULONG *)(p) + 1) 75 | #define UL_HI_D(p) ((ULONG *)(p) + 1) 76 | #define UL_LO_D(p) ((ULONG *)(p)) 77 | #define UL_LO_D(p) ((ULONG *)(p)) 78 | 79 | #define EOF 0x1A 80 | #define ISEOL(c) ((c) == '\n' || (c) == '\r' || (c) == '\0' || (c) == EOF) 81 | #define ISSEP(c) ((c) == '=' || (c) == ',') 82 | #define ISWHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r') 83 | #define ISNOISE(c) ((c) == '"') 84 | 85 | #define ISADIGIT(x) ((x) >= '0' && (x) <= '9') 86 | #define ISNZDIGIT(x) ((x) >= '1' && (x) <= '9') 87 | 88 | #define MSB_USHORT ((USHORT)0x8000) 89 | #define MAX_ULONG ((ULONG)0xffffffff) 90 | #define MSB_ULONG ((ULONG)0x80000000) 91 | 92 | #define MAX_USHORT ((USHORT)0xffff) 93 | #define MSB_USHORT ((USHORT)0x8000) 94 | 95 | #define LD_BIAS 0x3fff /* exponent bias for long double */ 96 | #define LD_BIASM1 0x3ffe /* LD_BIAS - 1 */ 97 | #define LD_MAXEXP 0x7fff /* maximum biased exponent */ 98 | 99 | #define PUT_INF_12(p, sign) \ 100 | *UL_HI_12(p) = (sign) ? 0xffff8000 : 0x7fff8000; \ 101 | *UL_MED_12(p) = 0; \ 102 | *UL_LO_12(p) = 0; 103 | 104 | #define PUT_ZERO_12(p) \ 105 | *UL_HI_12(p) = 0; \ 106 | *UL_MED_12(p) = 0; \ 107 | *UL_LO_12(p) = 0; 108 | 109 | #define ISZERO_12(p) ((*UL_HI_12(p) & 0x7fffffff) == 0 && *UL_MED_12(p) == 0 && *UL_LO_12(p) == 0) 110 | 111 | #pragma pack(4) 112 | typedef struct 113 | { 114 | UCHAR ld12[12]; 115 | } _ULDBL12; 116 | #pragma pack() 117 | 118 | typedef struct 119 | { 120 | int max_exp; // maximum base 2 exponent (reserved for special values) 121 | int min_exp; // minimum base 2 exponent (reserved for denormals) 122 | int precision; // bits of precision carried in the mantissa 123 | int exp_width; // number of bits for exponent 124 | int format_width; // format width in bits 125 | int bias; // exponent bias 126 | } FpFormatDescriptor; 127 | 128 | typedef enum 129 | { 130 | INTRNCVT_OK, 131 | INTRNCVT_OVERFLOW, 132 | INTRNCVT_UNDERFLOW 133 | } INTRNCVT_STATUS; 134 | 135 | _ULDBL12 _pow10pos_my[] = { 136 | /*P0001*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x02, 0x40}}, 137 | /*P0002*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC8, 0x05, 0x40}}, 138 | /*P0003*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFA, 0x08, 0x40}}, 139 | /*P0004*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x9C, 0x0C, 0x40}}, 140 | /*P0005*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0xC3, 0x0F, 0x40}}, 141 | /*P0006*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xF4, 0x12, 0x40}}, 142 | /*P0007*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x16, 0x40}}, 143 | /*P0008*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xBC, 0xBE, 0x19, 0x40}}, 144 | /*P0016*/ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xBF, 0xC9, 0x1B, 0x8E, 0x34, 0x40}}, 145 | /*P0024*/ {{0x00, 0x00, 0x00, 0xA1, 0xED, 0xCC, 0xCE, 0x1B, 0xC2, 0xD3, 0x4E, 0x40}}, 146 | /*P0032*/ {{0x20, 0xF0, 0x9E, 0xB5, 0x70, 0x2B, 0xA8, 0xAD, 0xC5, 0x9D, 0x69, 0x40}}, 147 | /*P0040*/ {{0xD0, 0x5D, 0xFD, 0x25, 0xE5, 0x1A, 0x8E, 0x4F, 0x19, 0xEB, 0x83, 0x40}}, 148 | /*P0048*/ {{0x71, 0x96, 0xD7, 0x95, 0x43, 0x0E, 0x05, 0x8D, 0x29, 0xAF, 0x9E, 0x40}}, 149 | /*P0056*/ {{0xF9, 0xBF, 0xA0, 0x44, 0xED, 0x81, 0x12, 0x8F, 0x81, 0x82, 0xB9, 0x40}}, 150 | /*P0064*/ {{0xBF, 0x3C, 0xD5, 0xA6, 0xCF, 0xFF, 0x49, 0x1F, 0x78, 0xC2, 0xD3, 0x40}}, 151 | /*P0128*/ {{0x6F, 0xC6, 0xE0, 0x8C, 0xE9, 0x80, 0xC9, 0x47, 0xBA, 0x93, 0xA8, 0x41}}, 152 | /*P0192*/ {{0xBC, 0x85, 0x6B, 0x55, 0x27, 0x39, 0x8D, 0xF7, 0x70, 0xE0, 0x7C, 0x42}}, 153 | /*P0256*/ {{0xBC, 0xDD, 0x8E, 0xDE, 0xF9, 0x9D, 0xFB, 0xEB, 0x7E, 0xAA, 0x51, 0x43}}, 154 | /*P0320*/ {{0xA1, 0xE6, 0x76, 0xE3, 0xCC, 0xF2, 0x29, 0x2F, 0x84, 0x81, 0x26, 0x44}}, 155 | /*P0384*/ {{0x28, 0x10, 0x17, 0xAA, 0xF8, 0xAE, 0x10, 0xE3, 0xC5, 0xC4, 0xFA, 0x44}}, 156 | /*P0448*/ {{0xEB, 0xA7, 0xD4, 0xF3, 0xF7, 0xEB, 0xE1, 0x4A, 0x7A, 0x95, 0xCF, 0x45}}, 157 | /*P0512*/ {{0x65, 0xCC, 0xC7, 0x91, 0x0E, 0xA6, 0xAE, 0xA0, 0x19, 0xE3, 0xA3, 0x46}}, 158 | /*P1024*/ {{0x0D, 0x65, 0x17, 0x0C, 0x75, 0x81, 0x86, 0x75, 0x76, 0xC9, 0x48, 0x4D}}, 159 | /*P1536*/ {{0x58, 0x42, 0xE4, 0xA7, 0x93, 0x39, 0x3B, 0x35, 0xB8, 0xB2, 0xED, 0x53}}, 160 | /*P2048*/ {{0x4D, 0xA7, 0xE5, 0x5D, 0x3D, 0xC5, 0x5D, 0x3B, 0x8B, 0x9E, 0x92, 0x5A}}, 161 | /*P2560*/ {{0xFF, 0x5D, 0xA6, 0xF0, 0xA1, 0x20, 0xC0, 0x54, 0xA5, 0x8C, 0x37, 0x61}}, 162 | /*P3072*/ {{0xD1, 0xFD, 0x8B, 0x5A, 0x8B, 0xD8, 0x25, 0x5D, 0x89, 0xF9, 0xDB, 0x67}}, 163 | /*P3584*/ {{0xAA, 0x95, 0xF8, 0xF3, 0x27, 0xBF, 0xA2, 0xC8, 0x5D, 0xDD, 0x80, 0x6E}}, 164 | /*P4096*/ {{0x4C, 0xC9, 0x9B, 0x97, 0x20, 0x8A, 0x02, 0x52, 0x60, 0xC4, 0x25, 0x75}}}; 165 | 166 | _ULDBL12 _pow10neg_my[] = { 167 | /*N0001*/ {{0xCD, 0xCC, 0xCD, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFB, 0x3F}}, 168 | /*N0002*/ {{0x71, 0x3D, 0x0A, 0xD7, 0xA3, 0x70, 0x3D, 0x0A, 0xD7, 0xA3, 0xF8, 0x3F}}, 169 | /*N0003*/ {{0x5A, 0x64, 0x3B, 0xDF, 0x4F, 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xF5, 0x3F}}, 170 | /*N0004*/ {{0xC3, 0xD3, 0x2C, 0x65, 0x19, 0xE2, 0x58, 0x17, 0xB7, 0xD1, 0xF1, 0x3F}}, 171 | /*N0005*/ {{0xD0, 0x0F, 0x23, 0x84, 0x47, 0x1B, 0x47, 0xAC, 0xC5, 0xA7, 0xEE, 0x3F}}, 172 | /*N0006*/ {{0x40, 0xA6, 0xB6, 0x69, 0x6C, 0xAF, 0x05, 0xBD, 0x37, 0x86, 0xEB, 0x3F}}, 173 | /*N0007*/ {{0x33, 0x3D, 0xBC, 0x42, 0x7A, 0xE5, 0xD5, 0x94, 0xBF, 0xD6, 0xE7, 0x3F}}, 174 | /*N0008*/ {{0xC2, 0xFD, 0xFD, 0xCE, 0x61, 0x84, 0x11, 0x77, 0xCC, 0xAB, 0xE4, 0x3F}}, 175 | /*N0016*/ {{0x2F, 0x4C, 0x5B, 0xE1, 0x4D, 0xC4, 0xBE, 0x94, 0x95, 0xE6, 0xC9, 0x3F}}, 176 | /*N0024*/ {{0x92, 0xC4, 0x53, 0x3B, 0x75, 0x44, 0xCD, 0x14, 0xBE, 0x9A, 0xAF, 0x3F}}, 177 | /*N0032*/ {{0xDE, 0x67, 0xBA, 0x94, 0x39, 0x45, 0xAD, 0x1E, 0xB1, 0xCF, 0x94, 0x3F}}, 178 | /*N0040*/ {{0x24, 0x23, 0xC6, 0xE2, 0xBC, 0xBA, 0x3B, 0x31, 0x61, 0x8B, 0x7A, 0x3F}}, 179 | /*N0048*/ {{0x61, 0x55, 0x59, 0xC1, 0x7E, 0xB1, 0x53, 0x7C, 0x12, 0xBB, 0x5F, 0x3F}}, 180 | /*N0056*/ {{0xD7, 0xEE, 0x2F, 0x8D, 0x06, 0xBE, 0x92, 0x85, 0x15, 0xFB, 0x44, 0x3F}}, 181 | /*N0064*/ {{0x24, 0x3F, 0xA5, 0xE9, 0x39, 0xA5, 0x27, 0xEA, 0x7F, 0xA8, 0x2A, 0x3F}}, 182 | /*N0128*/ {{0x7D, 0xAC, 0xA1, 0xE4, 0xBC, 0x64, 0x7C, 0x46, 0xD0, 0xDD, 0x55, 0x3E}}, 183 | /*N0192*/ {{0x63, 0x7B, 0x06, 0xCC, 0x23, 0x54, 0x77, 0x83, 0xFF, 0x91, 0x81, 0x3D}}, 184 | /*N0256*/ {{0x91, 0xFA, 0x3A, 0x19, 0x7A, 0x63, 0x25, 0x43, 0x31, 0xC0, 0xAC, 0x3C}}, 185 | /*N0320*/ {{0x21, 0x89, 0xD1, 0x38, 0x82, 0x47, 0x97, 0xB8, 0x00, 0xFD, 0xD7, 0x3B}}, 186 | /*N0384*/ {{0xDC, 0x88, 0x58, 0x08, 0x1B, 0xB1, 0xE8, 0xE3, 0x86, 0xA6, 0x03, 0x3B}}, 187 | /*N0448*/ {{0xC6, 0x84, 0x45, 0x42, 0x07, 0xB6, 0x99, 0x75, 0x37, 0xDB, 0x2E, 0x3A}}, 188 | /*N0512*/ {{0x33, 0x71, 0x1C, 0xD2, 0x23, 0xDB, 0x32, 0xEE, 0x49, 0x90, 0x5A, 0x39}}, 189 | /*N1024*/ {{0xA6, 0x87, 0xBE, 0xC0, 0x57, 0xDA, 0xA5, 0x82, 0xA6, 0xA2, 0xB5, 0x32}}, 190 | /*N1536*/ {{0xE2, 0x68, 0xB2, 0x11, 0xA7, 0x52, 0x9F, 0x44, 0x59, 0xB7, 0x10, 0x2C}}, 191 | /*N2048*/ {{0x25, 0x49, 0xE4, 0x2D, 0x36, 0x34, 0x4F, 0x53, 0xAE, 0xCE, 0x6B, 0x25}}, 192 | /*N2560*/ {{0x8F, 0x59, 0x04, 0xA4, 0xC0, 0xDE, 0xC2, 0x7D, 0xFB, 0xE8, 0xC6, 0x1E}}, 193 | /*N3072*/ {{0x9E, 0xE7, 0x88, 0x5A, 0x57, 0x91, 0x3C, 0xBF, 0x50, 0x83, 0x22, 0x18}}, 194 | /*N3584*/ {{0x4E, 0x4B, 0x65, 0x62, 0xFD, 0x83, 0x8F, 0xAF, 0x06, 0x94, 0x7D, 0x11}}, 195 | /*N4096*/ {{0xE4, 0x2D, 0xDE, 0x9F, 0xCE, 0xD2, 0xC8, 0x04, 0xDD, 0xA6, 0xD8, 0x0A}}}; 196 | 197 | static FpFormatDescriptor DoubleFormat = { 198 | 0x7ff - 0x3ff, // 1024, maximum base 2 exponent (reserved for special values) 199 | 0x0 - 0x3ff, // -1023, minimum base 2 exponent (reserved for denormals) 200 | 53, // bits of precision carried in the mantissa 201 | 11, // number of bits for exponent 202 | 64, // format width in bits 203 | 0x3ff, // exponent bias 204 | }; 205 | 206 | /*** 207 | *int __addl(u_long x, u_long y, u_long *sum) - u_long addition 208 | * 209 | *Purpose: add two u_long numbers and return carry 210 | * 211 | *Entry: u_long x, u_long y : the numbers to be added 212 | * u_long *sum : where to store the result 213 | * 214 | *Exit: *sum receives the value of x+y 215 | * the value of the carry is returned 216 | * 217 | *Exceptions: 218 | * 219 | *******************************************************************************/ 220 | 221 | int 222 | __addl(ULONG x, ULONG y, ULONG *sum) 223 | { 224 | ULONG r; 225 | int carry = 0; 226 | r = x + y; 227 | if (r < x || r < y) 228 | carry++; 229 | *sum = r; 230 | return carry; 231 | } 232 | 233 | /*** 234 | *void __add_12(_ULDBL12 *x, _ULDBL12 *y) - _ULDBL12 addition 235 | * 236 | *Purpose: add two _ULDBL12 numbers. The numbers are added 237 | * as 12-byte integers. Overflow is ignored. 238 | * 239 | *Entry: x,y: pointers to the operands 240 | * 241 | *Exit: *x receives the sum 242 | * 243 | *Exceptions: 244 | * 245 | *******************************************************************************/ 246 | 247 | void 248 | __add_12(_ULDBL12 *x, _ULDBL12 *y) 249 | { 250 | int c0, c1, c2; 251 | c0 = __addl(*UL_LO_12(x), *UL_LO_12(y), UL_LO_12(x)); 252 | if (c0) 253 | { 254 | c1 = __addl(*UL_MED_12(x), (ULONG)1, UL_MED_12(x)); 255 | if (c1) 256 | { 257 | (*UL_HI_12(x))++; 258 | } 259 | } 260 | c2 = __addl(*UL_MED_12(x), *UL_MED_12(y), UL_MED_12(x)); 261 | if (c2) 262 | { 263 | (*UL_HI_12(x))++; 264 | } 265 | /* ignore next carry -- assume no overflow will occur */ 266 | (void)__addl(*UL_HI_12(x), *UL_HI_12(y), UL_HI_12(x)); 267 | } 268 | 269 | /*** 270 | *void __shl_12(_ULDBL12 *x) - _ULDBL12 shift left 271 | *void __shr_12(_ULDBL12 *x) - _ULDBL12 shift right 272 | * 273 | *Purpose: Shift a _ULDBL12 number one bit to the left (right). The number 274 | * is shifted as a 12-byte integer. The MSB is lost. 275 | * 276 | *Entry: x: a pointer to the operand 277 | * 278 | *Exit: *x is shifted one bit to the left (or right) 279 | * 280 | *Exceptions: 281 | * 282 | *******************************************************************************/ 283 | 284 | void 285 | __shl_12(_ULDBL12 *p) 286 | { 287 | ULONG c0, c1; 288 | 289 | c0 = *UL_LO_12(p) & MSB_ULONG ? 1 : 0; 290 | c1 = *UL_MED_12(p) & MSB_ULONG ? 1 : 0; 291 | *UL_LO_12(p) <<= 1; 292 | *UL_MED_12(p) = *UL_MED_12(p) << 1 | c0; 293 | *UL_HI_12(p) = *UL_HI_12(p) << 1 | c1; 294 | } 295 | 296 | void 297 | __shr_12(_ULDBL12 *p) 298 | { 299 | ULONG c2, c1; 300 | c2 = *UL_HI_12(p) & 0x1 ? MSB_ULONG : 0; 301 | c1 = *UL_MED_12(p) & 0x1 ? MSB_ULONG : 0; 302 | *UL_HI_12(p) >>= 1; 303 | *UL_MED_12(p) = *UL_MED_12(p) >> 1 | c2; 304 | *UL_LO_12(p) = *UL_LO_12(p) >> 1 | c1; 305 | } 306 | 307 | void 308 | __mtold12_my(char *manptr, unsigned manlen, _ULDBL12 *ld12) 309 | { 310 | _ULDBL12 tmp; 311 | USHORT expn = LD_BIASM1 + 80; 312 | 313 | *UL_LO_12(ld12) = 0; 314 | *UL_MED_12(ld12) = 0; 315 | *UL_HI_12(ld12) = 0; 316 | for (; manlen > 0; manlen--, manptr++) 317 | { 318 | tmp = *ld12; 319 | __shl_12(ld12); 320 | __shl_12(ld12); 321 | __add_12(ld12, &tmp); 322 | __shl_12(ld12); /* multiply by 10 */ 323 | *UL_LO_12(&tmp) = (ULONG)*manptr; 324 | *UL_MED_12(&tmp) = 0; 325 | *UL_HI_12(&tmp) = 0; 326 | __add_12(ld12, &tmp); 327 | } 328 | 329 | /* normalize mantissa -- first shift word by word */ 330 | while (*UL_HI_12(ld12) == 0) 331 | { 332 | *UL_HI_12(ld12) = *UL_MED_12(ld12) >> 16; 333 | *UL_MED_12(ld12) = *UL_MED_12(ld12) << 16 | *UL_LO_12(ld12) >> 16; 334 | (*UL_LO_12(ld12)) <<= 16; 335 | expn -= 16; 336 | } 337 | while ((*UL_HI_12(ld12) & 0x8000) == 0) 338 | { 339 | __shl_12(ld12); 340 | expn--; 341 | } 342 | *U_EXP_12(ld12) = expn; 343 | } 344 | 345 | void 346 | __ld12mul_my(_ULDBL12 *px, _ULDBL12 *py) 347 | { 348 | USHORT sign = 0; 349 | USHORT sticky_bits = 0; 350 | _ULDBL12 tempman; /*this is actually a 12-byte mantissa, 351 | not a 12-byte long double */ 352 | int i; 353 | USHORT expx, expy, expsum; 354 | int roffs, poffs, qoffs; 355 | int sticky; 356 | 357 | *UL_LO_12(&tempman) = 0; 358 | *UL_MED_12(&tempman) = 0; 359 | *UL_HI_12(&tempman) = 0; 360 | 361 | expx = *U_EXP_12(px); 362 | expy = *U_EXP_12(py); 363 | 364 | sign = (expx ^ expy) & (USHORT)0x8000; 365 | expx &= 0x7fff; 366 | expy &= 0x7fff; 367 | expsum = expx + expy; 368 | if (expx >= LD_MAXEXP || expy >= LD_MAXEXP || expsum > LD_MAXEXP + LD_BIASM1) 369 | { 370 | /* overflow to infinity */ 371 | PUT_INF_12(px, sign); 372 | return; 373 | } 374 | if (expsum <= LD_BIASM1 - 63) 375 | { 376 | /* underflow to zero */ 377 | PUT_ZERO_12(px); 378 | return; 379 | } 380 | if (expx == 0) 381 | { 382 | /* 383 | * If this is a denormal temp real then the mantissa 384 | * was shifted right once to set bit 63 to zero. 385 | */ 386 | expsum++; /* Correct for this */ 387 | if (ISZERO_12(px)) 388 | { 389 | /* put positive sign */ 390 | *U_EXP_12(px) = 0; 391 | return; 392 | } 393 | } 394 | if (expy == 0) 395 | { 396 | expsum++; /* because arg2 is denormal */ 397 | if (ISZERO_12(py)) 398 | { 399 | PUT_ZERO_12(px); 400 | return; 401 | } 402 | } 403 | 404 | roffs = 0; 405 | for (i = 0; i < 5; i++) 406 | { 407 | int j; 408 | poffs = i << 1; 409 | qoffs = 8; 410 | for (j = 5 - i; j > 0; j--) 411 | { 412 | ULONG prod; 413 | #ifdef MIPS 414 | /* a variable to hold temprary sums */ 415 | u_long sum; 416 | #endif 417 | int carry; 418 | USHORT *p, *q; 419 | ULONG *r; 420 | p = USHORT_12(px, poffs); 421 | q = USHORT_12(py, qoffs); 422 | r = ULONG_12(&tempman, roffs); 423 | prod = (ULONG)*p * (ULONG)*q; 424 | #ifdef MIPS 425 | /* handle misalignment problems */ 426 | if (i & 0x1) 427 | { /* i is odd */ 428 | carry = __addl(*MIPSALIGN(r), prod, &sum); 429 | *MIPSALIGN(r) = sum; 430 | } 431 | else /* i is even */ 432 | carry = __addl(*r, prod, r); 433 | #else 434 | carry = __addl(*r, prod, r); 435 | #endif 436 | if (carry) 437 | { 438 | /* roffs should be less than 8 in this case */ 439 | (*USHORT_12(&tempman, roffs + 4))++; 440 | } 441 | poffs += 2; 442 | qoffs -= 2; 443 | } 444 | roffs += 2; 445 | } 446 | 447 | expsum -= LD_BIASM1; 448 | 449 | /* normalize */ 450 | while ((SHORT)expsum > 0 && ((*UL_HI_12(&tempman) & MSB_ULONG) == 0)) 451 | { 452 | __shl_12(&tempman); 453 | expsum--; 454 | } 455 | 456 | if ((SHORT)expsum <= 0) 457 | { 458 | expsum--; 459 | sticky = 0; 460 | while ((SHORT)expsum < 0) 461 | { 462 | if (*U_XT_12(&tempman) & 0x1) 463 | sticky++; 464 | __shr_12(&tempman); 465 | expsum++; 466 | } 467 | if (sticky) 468 | *U_XT_12(&tempman) |= 0x1; 469 | } 470 | 471 | if (*U_XT_12(&tempman) > 0x8000 || ((*UL_LO_12(&tempman) & 0x1ffff) == 0x18000)) 472 | { 473 | /* round up */ 474 | if (*UL_MANLO_12(&tempman) == MAX_ULONG) 475 | { 476 | *UL_MANLO_12(&tempman) = 0; 477 | if (*UL_MANHI_12(&tempman) == MAX_ULONG) 478 | { 479 | *UL_MANHI_12(&tempman) = 0; 480 | if (*U_EXP_12(&tempman) == MAX_USHORT) 481 | { 482 | /* 12-byte mantissa overflow */ 483 | *U_EXP_12(&tempman) = MSB_USHORT; 484 | expsum++; 485 | } 486 | else 487 | (*U_EXP_12(&tempman))++; 488 | } 489 | else 490 | (*UL_MANHI_12(&tempman))++; 491 | } 492 | else 493 | (*UL_MANLO_12(&tempman))++; 494 | } 495 | 496 | /* check for exponent overflow */ 497 | if (expsum >= 0x7fff) 498 | { 499 | PUT_INF_12(px, sign); 500 | return; 501 | } 502 | 503 | /* put result in px */ 504 | *U_XT_12(px) = *USHORT_12(&tempman, 2); 505 | *UL_MANLO_12(px) = *UL_MED_12(&tempman); 506 | *UL_MANHI_12(px) = *UL_HI_12(&tempman); 507 | *U_EXP_12(px) = expsum | sign; 508 | } 509 | 510 | void 511 | __multtenpow12_my(_ULDBL12 *pld12, int pow, unsigned mult12) 512 | { 513 | _ULDBL12 *pow_10p = _pow10pos_my - 8; 514 | if (pow == 0) 515 | return; 516 | if (pow < 0) 517 | { 518 | pow = -pow; 519 | pow_10p = _pow10neg_my - 8; 520 | } 521 | 522 | if (!mult12) 523 | *U_XT_12(pld12) = 0; 524 | 525 | while (pow) 526 | { 527 | int last3; /* the 3 LSBits of pow */ 528 | _ULDBL12 unround; 529 | _ULDBL12 *py; 530 | 531 | pow_10p += 7; 532 | last3 = pow & 0x7; 533 | pow >>= 3; 534 | if (last3 == 0) 535 | continue; 536 | py = pow_10p + last3; 537 | 538 | #ifdef _ULDSUPPORT 539 | if (mult12) 540 | { 541 | #endif 542 | /* do an exact 12byte multiplication */ 543 | if (*U_XT_12(py) >= 0x8000) 544 | { 545 | /* copy number */ 546 | unround = *py; 547 | /* unround adjacent byte */ 548 | (*UL_MANLO_12(&unround))--; 549 | /* point to new operand */ 550 | py = &unround; 551 | } 552 | __ld12mul_my(pld12, py); 553 | #ifdef _ULDSUPPORT 554 | } 555 | else 556 | { 557 | /* do a 10byte multiplication */ 558 | py = (_ULDBL12 *)TEN_BYTE_PART(py); 559 | *(long double *)TEN_BYTE_PART(pld12) *= *(long double *)py; 560 | } 561 | #endif 562 | } 563 | } 564 | 565 | unsigned int 566 | __strgtold12_my(_ULDBL12 *pld12, char **p_end_ptr, char *str, int mult12) 567 | { 568 | typedef enum 569 | { 570 | S_INIT, /* initial state */ 571 | S_EAT0L, /* eat 0's at the left of mantissa */ 572 | S_SIGNM, /* just read sign of mantissa */ 573 | S_GETL, /* get integer part of mantissa */ 574 | S_GETR, /* get decimal part of mantissa */ 575 | S_POINT, /* just found decimal point */ 576 | S_E, /* just found 'E', or 'e', etc */ 577 | S_SIGNE, /* just read sign of exponent */ 578 | S_EAT0E, /* eat 0's at the left of exponent */ 579 | S_GETE, /* get exponent */ 580 | S_END /* final state */ 581 | } state_t; 582 | 583 | /* this will accomodate the digits of the mantissa in BCD form*/ 584 | static char buf[LD_MAX_MAN_LEN1]; 585 | char *manp = buf; 586 | 587 | /* a temporary _ULDBL12 */ 588 | _ULDBL12 tmpld12; 589 | 590 | USHORT man_sign = 0; /* to be ORed with result */ 591 | int exp_sign = 1; /* default sign of exponent (values: +1 or -1)*/ 592 | /* number of decimal significant mantissa digits so far*/ 593 | unsigned manlen = 0; 594 | int found_digit = 0; 595 | int overflow = 0; 596 | int underflow = 0; 597 | int pow = 0; 598 | int exp_adj = 0; /* exponent adjustment */ 599 | ULONG ul0, ul1; 600 | USHORT u, uexp; 601 | 602 | unsigned int result_flags = 0; 603 | 604 | state_t state = S_INIT; 605 | 606 | char c; /* the current input symbol */ 607 | char *p; /* a pointer to the next input symbol */ 608 | char *savedp; 609 | 610 | for (savedp = p = str; ISWHITE(*p); p++) 611 | ; /* eat up white space */ 612 | 613 | while (state != S_END) 614 | { 615 | c = *p++; 616 | switch (state) 617 | { 618 | case S_INIT: 619 | if (ISNZDIGIT(c)) 620 | { 621 | state = S_GETL; 622 | p--; 623 | } 624 | else 625 | switch (c) 626 | { 627 | case '0': 628 | state = S_EAT0L; 629 | break; 630 | case '+': 631 | state = S_SIGNM; 632 | man_sign = 0x0000; 633 | break; 634 | case '-': 635 | state = S_SIGNM; 636 | man_sign = 0x8000; 637 | break; 638 | case '.': 639 | state = S_POINT; 640 | break; 641 | default: 642 | state = S_END; 643 | p--; 644 | break; 645 | } 646 | break; 647 | case S_EAT0L: 648 | found_digit = 1; 649 | if (ISNZDIGIT(c)) 650 | { 651 | state = S_GETL; 652 | p--; 653 | } 654 | else 655 | switch (c) 656 | { 657 | case '0': 658 | state = S_EAT0L; 659 | break; 660 | case 'E': 661 | case 'e': 662 | case 'D': 663 | case 'd': 664 | state = S_E; 665 | break; 666 | case '.': 667 | state = S_GETR; 668 | break; 669 | default: 670 | state = S_END; 671 | p--; 672 | } 673 | break; 674 | case S_SIGNM: 675 | if (ISNZDIGIT(c)) 676 | { 677 | state = S_GETL; 678 | p--; 679 | } 680 | else 681 | switch (c) 682 | { 683 | case '0': 684 | state = S_EAT0L; 685 | break; 686 | case '.': 687 | state = S_POINT; 688 | break; 689 | default: 690 | state = S_END; 691 | p = savedp; 692 | } 693 | break; 694 | case S_GETL: 695 | found_digit = 1; 696 | for (; ISADIGIT(c); c = *p++) 697 | { 698 | if (manlen < LD_MAX_MAN_LEN + 1) 699 | { 700 | manlen++; 701 | *manp++ = c - (char)'0'; 702 | } 703 | else 704 | exp_adj++; 705 | } 706 | switch (c) 707 | { 708 | case '.': 709 | state = S_GETR; 710 | break; 711 | case 'E': 712 | case 'e': 713 | case 'D': 714 | case 'd': 715 | state = S_E; 716 | break; 717 | default: 718 | state = S_END; 719 | p--; 720 | } 721 | break; 722 | case S_GETR: 723 | found_digit = 1; 724 | if (manlen == 0) 725 | for (; c == '0'; c = *p++) 726 | exp_adj--; 727 | for (; ISADIGIT(c); c = *p++) 728 | { 729 | if (manlen < LD_MAX_MAN_LEN + 1) 730 | { 731 | manlen++; 732 | *manp++ = c - (char)'0'; 733 | exp_adj--; 734 | } 735 | } 736 | switch (c) 737 | { 738 | case 'E': 739 | case 'e': 740 | case 'D': 741 | case 'd': 742 | state = S_E; 743 | break; 744 | default: 745 | state = S_END; 746 | p--; 747 | } 748 | break; 749 | case S_POINT: 750 | if (ISADIGIT(c)) 751 | { 752 | state = S_GETR; 753 | p--; 754 | } 755 | else 756 | { 757 | state = S_END; 758 | p = savedp; 759 | } 760 | break; 761 | case S_E: 762 | savedp = p - 2; /* savedp points to 'E' */ 763 | if (ISNZDIGIT(c)) 764 | { 765 | state = S_GETE; 766 | p--; 767 | } 768 | else 769 | switch (c) 770 | { 771 | case '0': 772 | state = S_EAT0E; 773 | break; 774 | case '-': 775 | state = S_SIGNE; 776 | exp_sign = -1; 777 | break; 778 | case '+': 779 | state = S_SIGNE; 780 | break; 781 | default: 782 | state = S_END; 783 | p = savedp; 784 | } 785 | break; 786 | case S_EAT0E: 787 | for (; c == '0'; c = *p++) 788 | ; 789 | if (ISNZDIGIT(c)) 790 | { 791 | state = S_GETE; 792 | p--; 793 | } 794 | else 795 | { 796 | state = S_END; 797 | p--; 798 | } 799 | break; 800 | case S_SIGNE: 801 | if (ISNZDIGIT(c)) 802 | { 803 | state = S_GETE; 804 | p--; 805 | } 806 | else 807 | switch (c) 808 | { 809 | case '0': 810 | state = S_EAT0E; 811 | break; 812 | default: 813 | state = S_END; 814 | p = savedp; 815 | } 816 | break; 817 | case S_GETE: { 818 | long longpow = 0; /* TMAX10*10 should fit in a long */ 819 | for (; ISADIGIT(c); c = *p++) 820 | { 821 | longpow = longpow * 10 + (c - '0'); 822 | if (longpow > TMAX10) 823 | { 824 | longpow = TMAX10 + 1; /* will force overflow */ 825 | break; 826 | } 827 | } 828 | pow = (int)longpow; 829 | } 830 | for (; ISADIGIT(c); c = *p++) 831 | ; /* eat up remaining digits */ 832 | state = S_END; 833 | p--; 834 | break; 835 | } /* switch */ 836 | } /* while */ 837 | 838 | *p_end_ptr = p; /* set end pointer */ 839 | 840 | /* 841 | * Compute result 842 | */ 843 | 844 | if (found_digit && !overflow && !underflow) 845 | { 846 | if (manlen > LD_MAX_MAN_LEN) 847 | { 848 | if (buf[LD_MAX_MAN_LEN - 1] >= 5) 849 | { 850 | /* 851 | * Round mantissa to MAX_MAN_LEN digits 852 | * It's ok to round 9 to 0ah 853 | */ 854 | buf[LD_MAX_MAN_LEN - 1]++; 855 | } 856 | manlen = LD_MAX_MAN_LEN; 857 | manp--; 858 | exp_adj++; 859 | } 860 | if (manlen > 0) 861 | { 862 | /* 863 | * Remove trailing zero's from mantissa 864 | */ 865 | for (manp--; *manp == 0; manp--) 866 | { 867 | /* there is at least one non-zero digit */ 868 | manlen--; 869 | exp_adj++; 870 | } 871 | __mtold12_my(buf, manlen, &tmpld12); 872 | 873 | if (exp_sign < 0) 874 | pow = -pow; 875 | pow += exp_adj; 876 | if (pow > TMAX10) 877 | overflow = 1; 878 | else if (pow < TMIN10) 879 | underflow = 1; 880 | else 881 | { 882 | __multtenpow12_my(&tmpld12, pow, mult12); 883 | 884 | u = *U_XT_12(&tmpld12); 885 | ul0 = *UL_MANLO_12(&tmpld12); 886 | ul1 = *UL_MANHI_12(&tmpld12); 887 | uexp = *U_EXP_12(&tmpld12); 888 | } 889 | } 890 | else 891 | { 892 | /* manlen == 0, so return 0 */ 893 | u = (USHORT)0; 894 | ul0 = ul1 = uexp = 0; 895 | } 896 | } 897 | 898 | if (!found_digit) 899 | { 900 | /* return 0 */ 901 | u = (USHORT)0; 902 | ul0 = ul1 = uexp = 0; 903 | result_flags |= SLD_NODIGITS; 904 | } 905 | else if (overflow) 906 | { 907 | /* return +inf or -inf */ 908 | uexp = (USHORT)0x7fff; 909 | ul1 = 0x80000000; 910 | ul0 = 0; 911 | u = (USHORT)0; 912 | result_flags |= SLD_OVERFLOW; 913 | } 914 | else if (underflow) 915 | { 916 | /* return 0 */ 917 | u = (USHORT)0; 918 | ul0 = ul1 = uexp = 0; 919 | result_flags |= SLD_UNDERFLOW; 920 | } 921 | 922 | /* 923 | * Assemble result 924 | */ 925 | 926 | *U_XT_12(pld12) = u; 927 | *UL_MANLO_12(pld12) = ul0; 928 | *UL_MANHI_12(pld12) = ul1; 929 | *U_EXP_12(pld12) = uexp | man_sign; 930 | 931 | return result_flags; 932 | } 933 | 934 | int 935 | _IsZeroMan(intrnman man) 936 | { 937 | int i; 938 | for (i = 0; i < INTRNMAN_LEN; i++) 939 | if (man[i]) 940 | return 0; 941 | 942 | return 1; 943 | } 944 | 945 | void 946 | _FillZeroMan(intrnman man) 947 | { 948 | int i; 949 | for (i = 0; i < INTRNMAN_LEN; i++) 950 | man[i] = (ULONG)0; 951 | } 952 | 953 | void 954 | _CopyMan(intrnman dest, intrnman src) 955 | { 956 | ULONG *p, *q; 957 | int i; 958 | 959 | p = src; 960 | q = dest; 961 | 962 | for (i = 0; i < INTRNMAN_LEN; i++) 963 | { 964 | *q++ = *p++; 965 | } 966 | } 967 | 968 | int 969 | _ZeroTail(intrnman man, int nbit) 970 | { 971 | int nl = nbit / 32; 972 | int nb = 31 - nbit % 32; 973 | 974 | // 975 | // |<---- tail to be checked ---> 976 | // 977 | // -- ------------------------ ---- 978 | // |... | | ... | 979 | // -- ------------------------ ---- 980 | // ^ ^ ^ 981 | // | | |<----nb-----> 982 | // man nl nbit 983 | // 984 | 985 | ULONG bitmask = ~(MAX_ULONG << nb); 986 | 987 | if (man[nl] & bitmask) 988 | return 0; 989 | 990 | nl++; 991 | 992 | for (; nl < INTRNMAN_LEN; nl++) 993 | if (man[nl]) 994 | return 0; 995 | 996 | return 1; 997 | } 998 | 999 | int 1000 | _IncMan(intrnman man, int nbit) 1001 | { 1002 | int nl = nbit / 32; 1003 | int nb = 31 - nbit % 32; 1004 | 1005 | // 1006 | // |<--- part to be incremented -->| 1007 | // 1008 | // -- --------------------------- ---- 1009 | // |... | | ... | 1010 | // -- --------------------------- ---- 1011 | // ^ ^ ^ 1012 | // | | |<--nb--> 1013 | // man nl nbit 1014 | // 1015 | 1016 | ULONG one = (ULONG)1 << nb; 1017 | int carry; 1018 | 1019 | carry = __addl(man[nl], one, &man[nl]); 1020 | 1021 | nl--; 1022 | 1023 | for (; nl >= 0 && carry; nl--) 1024 | { 1025 | carry = (ULONG)__addl(man[nl], (ULONG)1, &man[nl]); 1026 | } 1027 | 1028 | return carry; 1029 | } 1030 | 1031 | int 1032 | _RoundMan(intrnman man, int precision) 1033 | { 1034 | int i, rndbit, nl, nb; 1035 | ULONG rndmask; 1036 | int nbit; 1037 | int retval = 0; 1038 | 1039 | // 1040 | // The order of the n'th bit is n-1, since the first bit is bit 0 1041 | // therefore decrement precision to get the order of the last bit 1042 | // to be kept 1043 | // 1044 | nbit = precision - 1; 1045 | 1046 | rndbit = nbit + 1; 1047 | 1048 | nl = rndbit / 32; 1049 | nb = 31 - rndbit % 32; 1050 | 1051 | // 1052 | // Get value of round bit 1053 | // 1054 | 1055 | rndmask = (ULONG)1 << nb; 1056 | 1057 | if ((man[nl] & rndmask) && !_ZeroTail(man, rndbit + 1)) 1058 | { 1059 | // 1060 | // round up 1061 | // 1062 | 1063 | retval = _IncMan(man, nbit); 1064 | } 1065 | 1066 | // 1067 | // fill rest of mantissa with zeroes 1068 | // 1069 | 1070 | man[nl] &= MAX_ULONG << nb; 1071 | for (i = nl + 1; i < INTRNMAN_LEN; i++) 1072 | { 1073 | man[i] = (ULONG)0; 1074 | } 1075 | 1076 | return retval; 1077 | } 1078 | 1079 | void 1080 | _ShrMan(intrnman man, int n) 1081 | { 1082 | int i, n1, n2, mask; 1083 | int carry_from_left; 1084 | 1085 | // 1086 | // declare this as volatile in order to work around a C8 1087 | // optimization bug 1088 | // 1089 | 1090 | volatile int carry_to_right; 1091 | 1092 | n1 = n / 32; 1093 | n2 = n % 32; 1094 | 1095 | mask = ~(MAX_ULONG << n2); 1096 | 1097 | // 1098 | // first deal with shifts by less than 32 bits 1099 | // 1100 | 1101 | carry_from_left = 0; 1102 | for (i = 0; i < INTRNMAN_LEN; i++) 1103 | { 1104 | carry_to_right = man[i] & mask; 1105 | 1106 | man[i] >>= n2; 1107 | 1108 | man[i] |= carry_from_left; 1109 | 1110 | carry_from_left = carry_to_right << (32 - n2); 1111 | } 1112 | 1113 | // 1114 | // now shift whole 32-bit ints 1115 | // 1116 | 1117 | for (i = INTRNMAN_LEN - 1; i >= 0; i--) 1118 | { 1119 | if (i >= n1) 1120 | { 1121 | man[i] = man[i - n1]; 1122 | } 1123 | else 1124 | { 1125 | man[i] = 0; 1126 | } 1127 | } 1128 | } 1129 | 1130 | INTRNCVT_STATUS 1131 | _ld12cvt(_ULDBL12 *pld12, void *d, FpFormatDescriptor *format) 1132 | { 1133 | ULONG man[INTRNMAN_LEN]; 1134 | ULONG saved_man[INTRNMAN_LEN]; 1135 | ULONG msw; 1136 | unsigned int bexp; // biased exponent 1137 | int exp_shift; 1138 | int exponent, sign; 1139 | INTRNCVT_STATUS retval; 1140 | 1141 | exponent = (*U_EXP_12(pld12) & 0x7fff) - 0x3fff; // unbias exponent 1142 | sign = *U_EXP_12(pld12) & 0x8000; 1143 | 1144 | // 1145 | // bexp is the final biased value of the exponent to be used 1146 | // Each of the following blocks should provide appropriate 1147 | // values for man, bexp and retval. The mantissa is also 1148 | // shifted to the right, leaving space for the exponent 1149 | // and sign to be inserted 1150 | // 1151 | 1152 | if (exponent == 0 - 0x3fff) 1153 | { 1154 | // either a denormal or zero 1155 | bexp = 0; 1156 | 1157 | if (_IsZeroMan(man)) 1158 | { 1159 | retval = INTRNCVT_OK; 1160 | } 1161 | else 1162 | { 1163 | _FillZeroMan(man); 1164 | 1165 | // denormal has been flushed to zero 1166 | 1167 | retval = INTRNCVT_UNDERFLOW; 1168 | } 1169 | } 1170 | else 1171 | { 1172 | man[0] = *UL_MANHI_12(pld12); 1173 | man[1] = *UL_MANLO_12(pld12); 1174 | man[2] = *U_XT_12(pld12) << 16; 1175 | 1176 | // save mantissa in case it needs to be rounded again 1177 | // at a different point (e.g., if the result is a denormal) 1178 | 1179 | _CopyMan(saved_man, man); 1180 | 1181 | if (_RoundMan(man, format->precision)) 1182 | { 1183 | exponent++; 1184 | } 1185 | 1186 | if (exponent < format->min_exp - format->precision) 1187 | { 1188 | // 1189 | // underflow that produces a zero 1190 | // 1191 | 1192 | _FillZeroMan(man); 1193 | bexp = 0; 1194 | retval = INTRNCVT_UNDERFLOW; 1195 | } 1196 | 1197 | else if (exponent <= format->min_exp) 1198 | { 1199 | // 1200 | // underflow that produces a denormal 1201 | // 1202 | // 1203 | 1204 | // The (unbiased) exponent will be MIN_EXP 1205 | // Find out how much the mantissa should be shifted 1206 | // One shift is done implicitly by moving the 1207 | // binary point one bit to the left, i.e., 1208 | // we treat the mantissa as .ddddd instead of d.dddd 1209 | // (where d is a binary digit) 1210 | 1211 | int shift = format->min_exp - exponent; 1212 | 1213 | // The mantissa should be rounded again, so it 1214 | // has to be restored 1215 | 1216 | _CopyMan(man, saved_man); 1217 | 1218 | _ShrMan(man, shift); 1219 | _RoundMan(man, format->precision); // need not check for carry 1220 | 1221 | // make room for the exponent + sign 1222 | 1223 | _ShrMan(man, format->exp_width + 1); 1224 | 1225 | bexp = 0; 1226 | retval = INTRNCVT_UNDERFLOW; 1227 | } 1228 | 1229 | else if (exponent >= format->max_exp) 1230 | { 1231 | // 1232 | // overflow, return infinity 1233 | // 1234 | 1235 | _FillZeroMan(man); 1236 | man[0] |= (1 << 31); // set MSB 1237 | 1238 | // make room for the exponent + sign 1239 | 1240 | _ShrMan(man, (format->exp_width + 1) - 1); 1241 | 1242 | bexp = format->max_exp + format->bias; 1243 | 1244 | retval = INTRNCVT_OVERFLOW; 1245 | } 1246 | 1247 | else 1248 | { 1249 | // 1250 | // valid, normalized result 1251 | // 1252 | 1253 | bexp = exponent + format->bias; 1254 | 1255 | // clear implied bit 1256 | 1257 | man[0] &= (~(1 << 31)); 1258 | 1259 | // 1260 | // shift right to make room for exponent + sign 1261 | // 1262 | 1263 | _ShrMan(man, (format->exp_width + 1) - 1); 1264 | 1265 | retval = INTRNCVT_OK; 1266 | } 1267 | } 1268 | 1269 | exp_shift = 32 - (format->exp_width + 1); 1270 | msw = man[0] | (bexp << exp_shift) | (sign ? 1 << 31 : 0); 1271 | 1272 | if (format->format_width == 64) 1273 | { 1274 | *UL_HI_D(d) = msw; 1275 | *UL_LO_D(d) = man[1]; 1276 | } 1277 | 1278 | else if (format->format_width == 32) 1279 | { 1280 | *(ULONG *)d = msw; 1281 | } 1282 | 1283 | return retval; 1284 | } 1285 | 1286 | INTRNCVT_STATUS 1287 | _ld12tod(_ULDBL12 *pld12, double *d) 1288 | { 1289 | return _ld12cvt(pld12, d, &DoubleFormat); 1290 | } 1291 | 1292 | #ifdef MTHREAD 1293 | FLT 1294 | _fltin2(FLT flt, const char *str, int len_ignore, int scale_ignore, int radix_ignore) 1295 | #else 1296 | FLT 1297 | _fltin(const char *str, int len_ignore, int scale_ignore, int radix_ignore) 1298 | #endif 1299 | { 1300 | _ULDBL12 ld12; 1301 | double x; 1302 | char *EndPtr; 1303 | unsigned flags; 1304 | int retflags = 0; 1305 | 1306 | flags = __strgtold12_my(&ld12, &EndPtr, (char *)str, 0); 1307 | if (flags & SLD_NODIGITS) 1308 | { 1309 | retflags |= CFIN_NODIGITS; 1310 | *(ULONG *)&x = 0; 1311 | *((ULONG *)&x + 1) = 0; 1312 | } 1313 | else 1314 | { 1315 | INTRNCVT_STATUS intrncvt; 1316 | 1317 | intrncvt = _ld12tod(&ld12, &x); 1318 | 1319 | if (flags & SLD_OVERFLOW || intrncvt == INTRNCVT_OVERFLOW) 1320 | { 1321 | retflags |= CFIN_OVERFLOW; 1322 | } 1323 | if (flags & SLD_UNDERFLOW || intrncvt == INTRNCVT_UNDERFLOW) 1324 | { 1325 | retflags |= CFIN_UNDERFLOW; 1326 | } 1327 | } 1328 | 1329 | flt->flags = retflags; 1330 | flt->nbytes = (int)(EndPtr - (char *)str); 1331 | flt->dval = *(double *)&x; 1332 | 1333 | return flt; 1334 | } 1335 | -------------------------------------------------------------------------------- /kcrt/invargc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __declspec(noreturn) void __cdecl _invoke_watson( 4 | _In_opt_z_ wchar_t const *_Expression, 5 | _In_opt_z_ wchar_t const *_FunctionName, 6 | _In_opt_z_ wchar_t const *_FileName, 7 | _In_ unsigned int _LineNo, 8 | _In_ uintptr_t _Reserved) 9 | { 10 | // 11 | // return; 12 | } 13 | -------------------------------------------------------------------------------- /kcrt/kcrt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kcrt/kcrt.h -------------------------------------------------------------------------------- /kcrt/kcrtc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kcrt/kcrtc.c -------------------------------------------------------------------------------- /kcrt/kcrtfs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kcrt/kcrtfs.c -------------------------------------------------------------------------------- /kcrt/strtod.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | static int maxExponent = 511; /* Largest possible base 10 exponent. Any 5 | * exponent larger than this will already 6 | * produce underflow or overflow, so there's 7 | * no need to worry about additional digits. 8 | */ 9 | static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ 10 | 10., /* is 10^2^i. Used to convert decimal */ 11 | 100., /* exponents into floating-point numbers. */ 12 | 1.0e4, 13 | 1.0e8, 14 | 1.0e16, 15 | 1.0e32, 16 | 1.0e64, 17 | 1.0e128, 18 | 1.0e256}; 19 | 20 | double __cdecl kstrtod(char const *_String, char **_EndPtr) 21 | { 22 | /* const char *string; A decimal ASCII floating-point number, 23 | * optionally preceded by white space. 24 | * Must have form "-I.FE-X", where I is the 25 | * integer part of the mantissa, F is the 26 | * fractional part of the mantissa, and X 27 | * is the exponent. Either of the signs 28 | * may be "+", "-", or omitted. Either I 29 | * or F may be omitted, or both. The decimal 30 | * point isn't necessary unless F is present. 31 | * The "E" may actually be an "e". E and X 32 | * may both be omitted (but not just one). 33 | */ 34 | /* char **endPtr; If non-NULL, store terminating character's 35 | * address here. */ 36 | int sign, expSign = FALSE; 37 | double fraction, dblExp, *d; 38 | register const char *p; 39 | register int c; 40 | int exp = 0; /* Exponent read from "EX" field. */ 41 | int fracExp = 0; /* Exponent that derives from the fractional 42 | * part. Under normal circumstatnces, it is 43 | * the negative of the number of digits in F. 44 | * However, if I is very long, the last digits 45 | * of I get dropped (otherwise a long I with a 46 | * large negative exponent could cause an 47 | * unnecessary overflow on I alone). In this 48 | * case, fracExp is incremented one for each 49 | * dropped digit. */ 50 | int mantSize; /* Number of digits in mantissa. */ 51 | int decPt; /* Number of mantissa digits BEFORE decimal 52 | * point. */ 53 | const char *pExp; /* Temporarily holds location of exponent 54 | * in string. */ 55 | 56 | /* 57 | * Strip off leading blanks and check for a sign. 58 | */ 59 | 60 | p = _String; 61 | while (isspace(*p)) 62 | { 63 | p += 1; 64 | } 65 | if (*p == '-') 66 | { 67 | sign = TRUE; 68 | p += 1; 69 | } 70 | else 71 | { 72 | if (*p == '+') 73 | { 74 | p += 1; 75 | } 76 | sign = FALSE; 77 | } 78 | 79 | /* 80 | * Count the number of digits in the mantissa (including the decimal 81 | * point), and also locate the decimal point. 82 | */ 83 | 84 | decPt = -1; 85 | for (mantSize = 0;; mantSize += 1) 86 | { 87 | c = *p; 88 | if (!isdigit(c)) 89 | { 90 | if ((c != '.') || (decPt >= 0)) 91 | { 92 | break; 93 | } 94 | decPt = mantSize; 95 | } 96 | p += 1; 97 | } 98 | 99 | /* 100 | * Now suck up the digits in the mantissa. Use two integers to 101 | * collect 9 digits each (this is faster than using floating-point). 102 | * If the mantissa has more than 18 digits, ignore the extras, since 103 | * they can't affect the value anyway. 104 | */ 105 | 106 | pExp = p; 107 | p -= mantSize; 108 | if (decPt < 0) 109 | { 110 | decPt = mantSize; 111 | } 112 | else 113 | { 114 | mantSize -= 1; /* One of the digits was the point. */ 115 | } 116 | if (mantSize > 18) 117 | { 118 | fracExp = decPt - 18; 119 | mantSize = 18; 120 | } 121 | else 122 | { 123 | fracExp = decPt - mantSize; 124 | } 125 | if (mantSize == 0) 126 | { 127 | fraction = 0.0; 128 | p = _String; 129 | goto done; 130 | } 131 | else 132 | { 133 | int frac1, frac2; 134 | frac1 = 0; 135 | for (; mantSize > 9; mantSize -= 1) 136 | { 137 | c = *p; 138 | p += 1; 139 | if (c == '.') 140 | { 141 | c = *p; 142 | p += 1; 143 | } 144 | frac1 = 10 * frac1 + (c - '0'); 145 | } 146 | frac2 = 0; 147 | for (; mantSize > 0; mantSize -= 1) 148 | { 149 | c = *p; 150 | p += 1; 151 | if (c == '.') 152 | { 153 | c = *p; 154 | p += 1; 155 | } 156 | frac2 = 10 * frac2 + (c - '0'); 157 | } 158 | fraction = (1.0e9 * frac1) + frac2; 159 | } 160 | 161 | /* 162 | * Skim off the exponent. 163 | */ 164 | 165 | p = pExp; 166 | if ((*p == 'E') || (*p == 'e')) 167 | { 168 | p += 1; 169 | if (*p == '-') 170 | { 171 | expSign = TRUE; 172 | p += 1; 173 | } 174 | else 175 | { 176 | if (*p == '+') 177 | { 178 | p += 1; 179 | } 180 | expSign = FALSE; 181 | } 182 | while (isdigit(*p)) 183 | { 184 | exp = exp * 10 + (*p - '0'); 185 | p += 1; 186 | } 187 | } 188 | if (expSign) 189 | { 190 | exp = fracExp - exp; 191 | } 192 | else 193 | { 194 | exp = fracExp + exp; 195 | } 196 | 197 | /* 198 | * Generate a floating-point number that represents the exponent. 199 | * Do this by processing the exponent one bit at a time to combine 200 | * many powers of 2 of 10. Then combine the exponent with the 201 | * fraction. 202 | */ 203 | 204 | if (exp < 0) 205 | { 206 | expSign = TRUE; 207 | exp = -exp; 208 | } 209 | else 210 | { 211 | expSign = FALSE; 212 | } 213 | if (exp > maxExponent) 214 | { 215 | exp = maxExponent; 216 | errno = ERANGE; 217 | } 218 | dblExp = 1.0; 219 | for (d = powersOf10; exp != 0; exp >>= 1, d += 1) 220 | { 221 | if (exp & 01) 222 | { 223 | dblExp *= *d; 224 | } 225 | } 226 | if (expSign) 227 | { 228 | fraction /= dblExp; 229 | } 230 | else 231 | { 232 | fraction *= dblExp; 233 | } 234 | 235 | done: 236 | if (_EndPtr != NULL) 237 | { 238 | *_EndPtr = (char *)p; 239 | } 240 | 241 | if (sign) 242 | { 243 | return -fraction; 244 | } 245 | return fraction; 246 | } 247 | -------------------------------------------------------------------------------- /kcrt/strtoll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | _Check_return_ 5 | _ACRTIMP long long __cdecl strtoll(_In_z_ char const *_String, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix) 6 | { 7 | const char *nptr = (const char *)_String; 8 | char **endptr = (char **)_EndPtr; 9 | int base = (int)_Radix; 10 | 11 | register const char *s = nptr; 12 | register long long acc; 13 | register int c; 14 | register long long cutoff; 15 | register int neg = 0, any, cutlim; 16 | 17 | /* 18 | * Skip white space and pick up leading +/- sign if any. 19 | * If base is 0, allow 0x for hex and 0 for octal, else 20 | * assume decimal; if base is already 16, allow 0x. 21 | */ 22 | do 23 | { 24 | c = *s++; 25 | } while (isspace(c)); 26 | if (c == '-') 27 | { 28 | neg = 1; 29 | c = *s++; 30 | } 31 | else if (c == '+') 32 | c = *s++; 33 | if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) 34 | { 35 | c = s[1]; 36 | s += 2; 37 | base = 16; 38 | } 39 | if (base == 0) 40 | base = c == '0' ? 8 : 10; 41 | 42 | /* 43 | * Compute the cutoff value between legal numbers and illegal 44 | * numbers. That is the largest legal value, divided by the 45 | * base. An input number that is greater than this value, if 46 | * followed by a legal input character, is too big. One that 47 | * is equal to this value may be valid or not; the limit 48 | * between valid and invalid numbers is then based on the last 49 | * digit. For instance, if the range for longs is 50 | * [-2147483648..2147483647] and the input base is 10, 51 | * cutoff will be set to 214748364 and cutlim to either 52 | * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 53 | * a value > 214748364, or equal but the next digit is > 7 (or 8), 54 | * the number is too big, and we will return a range error. 55 | * 56 | * Set any if any `digits' consumed; make it negative to indicate 57 | * overflow. 58 | */ 59 | cutoff = neg ? -(long long)LLONG_MIN : LLONG_MAX; 60 | cutlim = cutoff % (long long)base; 61 | cutoff /= (long long)base; 62 | for (acc = 0, any = 0;; c = *s++) 63 | { 64 | if (isdigit(c)) 65 | c -= '0'; 66 | else if (isalpha(c)) 67 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 68 | else 69 | break; 70 | if (c >= base) 71 | break; 72 | if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 73 | any = -1; 74 | else 75 | { 76 | any = 1; 77 | acc *= base; 78 | acc += c; 79 | } 80 | } 81 | if (any < 0) 82 | { 83 | acc = neg ? LLONG_MIN : LLONG_MAX; 84 | errno = ERANGE; 85 | } 86 | else if (neg) 87 | acc = -acc; 88 | if (endptr != 0) 89 | *endptr = (char *)(any ? s - 1 : nptr); 90 | return (acc); 91 | } 92 | -------------------------------------------------------------------------------- /kstl/Singleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class Singleton 5 | { 6 | public: 7 | Singleton() {} 8 | ~Singleton() {} 9 | 10 | private: 11 | Singleton(const Singleton &) = delete; 12 | Singleton &operator=(const Singleton &) = delete; 13 | 14 | public: 15 | static T &getInstance() 16 | { 17 | static T ms_pSingleton; 18 | return ms_pSingleton; 19 | } 20 | static T *instance() { return &getInstance(); } 21 | }; 22 | -------------------------------------------------------------------------------- /kstl/kernel_stl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmh5225/kcpplib/8c064be5b54e10452f5e02cc9808047d451a11a2/kstl/kernel_stl.cpp -------------------------------------------------------------------------------- /kstl/kernel_stl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | //////////////////////////////////////////////////////////////////////////////// 6 | // 7 | // macro utilities 8 | // 9 | 10 | //////////////////////////////////////////////////////////////////////////////// 11 | // 12 | // constants and macros 13 | // 14 | 15 | #ifdef _HAS_EXCEPTIONS 16 | # undef _HAS_EXCEPTIONS 17 | #endif 18 | #define _HAS_EXCEPTIONS 0 19 | 20 | //////////////////////////////////////////////////////////////////////////////// 21 | // 22 | // types 23 | // 24 | 25 | //////////////////////////////////////////////////////////////////////////////// 26 | // 27 | // prototypes 28 | // 29 | 30 | //////////////////////////////////////////////////////////////////////////////// 31 | // 32 | // variables 33 | // 34 | 35 | //////////////////////////////////////////////////////////////////////////////// 36 | // 37 | // implementations 38 | // 39 | 40 | /// An alternative implmentation of a C++ exception handler. Issues a bug check. 41 | /// @param bug_check_code A bug check code 42 | DECLSPEC_NORETURN void 43 | KernelStlRaiseException(_In_ ULONG bug_check_code); 44 | 45 | // Followings are definitions of functions needed to link successfully. 46 | 47 | DECLSPEC_NORETURN void __cdecl _invalid_parameter_noinfo_noreturn(); 48 | 49 | namespace std { 50 | DECLSPEC_NORETURN void __cdecl _Xbad_alloc(); 51 | DECLSPEC_NORETURN void __cdecl _Xinvalid_argument(_In_z_ const char *); 52 | DECLSPEC_NORETURN void __cdecl _Xlength_error(_In_z_ const char *); 53 | DECLSPEC_NORETURN void __cdecl _Xout_of_range(_In_z_ const char *); 54 | DECLSPEC_NORETURN void __cdecl _Xoverflow_error(_In_z_ const char *); 55 | DECLSPEC_NORETURN void __cdecl _Xruntime_error(_In_z_ const char *); 56 | DECLSPEC_NORETURN void __cdecl _Xbad_function_call(); 57 | } // namespace std 58 | 59 | /// An alternative implmentation of the new operator 60 | /// @param size A size to allocate in bytes 61 | /// @return An allocated pointer. The operator delete should be used to free it 62 | void *__cdecl 63 | operator new(_In_ size_t size); 64 | void *__cdecl 65 | operator new[](_In_ size_t size); 66 | 67 | // lua ÐèÒªµÄ(ÆäʵÊÇeastl) 68 | void * 69 | operator new[](size_t size, const char *, int, unsigned, const char *, int); 70 | void * 71 | operator new[](size_t size, size_t, size_t, const char *, int, unsigned, const char *, int); 72 | 73 | /// An alternative implmentation of the new operator 74 | /// @param p A pointer to delete 75 | void __cdecl 76 | operator delete(_In_ void *p); 77 | void __cdecl 78 | operator delete[](_In_ void *p); 79 | /// An alternative implmentation of the new operator 80 | /// @param p A pointer to delete 81 | /// @param size Ignored 82 | void __cdecl 83 | operator delete(_In_ void *p, _In_ size_t size); 84 | 85 | /// An alternative implmentation of __stdio_common_vsprintf_s 86 | /// @param _Options Ignored 87 | /// @param _Buffer Storage location for output 88 | /// @param _BufferCount Maximum number of characters to write 89 | /// @param _Format Format specification 90 | /// @param _Locale Ignored 91 | /// @param _ArgList Pointer to list of arguments 92 | /// @return The number of characters written, not including the terminating null 93 | /// character, or a negative value if an output error occurs 94 | _Success_(return >= 0) 95 | EXTERN_C 96 | int __cdecl __stdio_common_vsprintf_s( 97 | _In_ unsigned __int64 _Options, 98 | _Out_writes_z_(_BufferCount) char *_Buffer, 99 | _In_ size_t _BufferCount, 100 | _In_z_ _Printf_format_string_params_(2) char const *_Format, 101 | _In_opt_ _locale_t _Locale, 102 | va_list _ArgList); 103 | 104 | _Success_(return >= 0) 105 | EXTERN_C 106 | int __cdecl __stdio_common_vsprintf( 107 | _In_ unsigned __int64 _Options, 108 | _Out_writes_z_(_BufferCount) char *_Buffer, 109 | _In_ size_t _BufferCount, 110 | _In_z_ _Printf_format_string_params_(2) char const *_Format, 111 | _In_opt_ _locale_t _Locale, 112 | va_list _ArgList); 113 | 114 | /// An alternative implmentation of __stdio_common_vswprintf_s 115 | /// @param _Options Ignored 116 | /// @param _Buffer Storage location for output 117 | /// @param _BufferCount Maximum number of characters to write 118 | /// @param _Format Format specification 119 | /// @param _Locale Ignored 120 | /// @param _ArgList Pointer to list of arguments 121 | /// @return The number of characters written, not including the terminating null 122 | /// character, or a negative value if an output error occurs 123 | _Success_(return >= 0) 124 | _Check_return_opt_ EXTERN_C 125 | int __cdecl __stdio_common_vswprintf_s( 126 | _In_ unsigned __int64 _Options, 127 | _Out_writes_z_(_BufferCount) wchar_t *_Buffer, 128 | _In_ size_t _BufferCount, 129 | _In_z_ _Printf_format_string_params_(2) wchar_t const *_Format, 130 | _In_opt_ _locale_t _Locale, 131 | va_list _ArgList); 132 | 133 | _Success_(return >= 0) 134 | _Check_return_opt_ EXTERN_C 135 | int __cdecl __stdio_common_vswprintf( 136 | _In_ unsigned __int64 _Options, 137 | _Out_writes_z_(_BufferCount) wchar_t *_Buffer, 138 | _In_ size_t _BufferCount, 139 | _In_z_ _Printf_format_string_params_(2) wchar_t const *_Format, 140 | _In_opt_ _locale_t _Locale, 141 | va_list _ArgList); 142 | -------------------------------------------------------------------------------- /kstl/kstl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | -------------------------------------------------------------------------------- /kstl/kstl_stdint.h: -------------------------------------------------------------------------------- 1 | //#pragma once 2 | // typedef signed char int8_t; 3 | // typedef short int16_t; 4 | // typedef int int32_t; 5 | // 6 | // typedef unsigned char uint8_t; 7 | // typedef unsigned short uint16_t; 8 | // typedef unsigned int uint32_t; 9 | // 10 | // typedef signed char int_least8_t; 11 | // typedef short int_least16_t; 12 | // typedef int int_least32_t; 13 | // 14 | // typedef unsigned char uint_least8_t; 15 | // typedef unsigned short uint_least16_t; 16 | // typedef unsigned int uint_least32_t; 17 | // 18 | // typedef char int_fast8_t; 19 | // typedef int int_fast16_t; 20 | // typedef int int_fast32_t; 21 | // 22 | // typedef unsigned char uint_fast8_t; 23 | // typedef unsigned int uint_fast16_t; 24 | // typedef unsigned int uint_fast32_t; 25 | // 26 | //#ifndef _INTPTR_T_DEFINED 27 | //#define _INTPTR_T_DEFINED 28 | //#ifdef _AMD64_ 29 | // typedef __int64 intptr_t; 30 | //#else /* _WIN64 */ 31 | // typedef _W64 int intptr_t; 32 | //#endif /* _WIN64 */ 33 | //#endif /* _INTPTR_T_DEFINED */ 34 | // 35 | //#ifndef _UINTPTR_T_DEFINED 36 | //#define _UINTPTR_T_DEFINED 37 | //#ifdef _AMD64_ 38 | // typedef unsigned __int64 uintptr_t; 39 | //#else /* _WIN64 */ 40 | // typedef _W64 unsigned int uintptr_t; 41 | //#endif /* _WIN64 */ 42 | //#endif /* _UINTPTR_T_DEFINED */ 43 | // 44 | // typedef LONGLONG int64_t; 45 | // typedef ULONGLONG uint64_t; 46 | // 47 | // typedef LONGLONG int_least64_t; 48 | // typedef ULONGLONG uint_least64_t; 49 | // 50 | // typedef LONGLONG int_fast64_t; 51 | // typedef ULONGLONG uint_fast64_t; 52 | // 53 | // typedef LONGLONG intmax_t; 54 | // typedef ULONGLONG uintmax_t; 55 | // 56 | // typedef unsigned int uint32; 57 | // typedef int int32; 58 | // 59 | // typedef unsigned short uint16; 60 | // typedef short int16; 61 | // 62 | // typedef unsigned char uint8; 63 | // typedef char int8; 64 | // 65 | // typedef unsigned long long int uint64; 66 | -------------------------------------------------------------------------------- /kstl/kstlhead.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | // boost 26 | //#if !defined(_DEBUG) 27 | //#define BOOST_DISABLE_ASSERTS 28 | //#endif 29 | //#pragma warning(disable: 4503) 30 | //#include 31 | //#include 32 | -------------------------------------------------------------------------------- /kstl/scope.h: -------------------------------------------------------------------------------- 1 | 2 | // --------------------------------------------------------------------------- 3 | // kcpplib::scope_resource == std::experimental::unique_resource 4 | // kcpplib::scope_exit == std::experimental::scope_exit 5 | // 6 | #pragma once 7 | #include 8 | 9 | namespace kcpplib { 10 | 11 | template 12 | class scope_resource 13 | { 14 | public: 15 | using this_type = scope_resource; 16 | using value_type = T; 17 | 18 | ~scope_resource() noexcept { TReleaseFunctor()(m_Resource); } 19 | 20 | scope_resource() = default; 21 | 22 | scope_resource(T Resource) : m_Resource(Resource) {} 23 | 24 | value_type get() const noexcept { return m_Resource; } 25 | 26 | void reset(value_type Resource = nullptr) noexcept 27 | { 28 | TReleaseFunctor()(m_Resource); 29 | m_Resource = Resource; 30 | } 31 | 32 | value_type release() noexcept 33 | { 34 | auto res = m_Resource; 35 | m_Resource = nullptr; 36 | return res; 37 | } 38 | 39 | void swap(this_type &Other) noexcept 40 | { 41 | auto other = Other.m_Resource; 42 | Other.m_Resource = m_Resource; 43 | m_Resource = other; 44 | } 45 | 46 | value_type operator*() const noexcept { return m_Resource; } 47 | 48 | value_type *operator&() noexcept { return &m_Resource; } 49 | 50 | this_type &operator=(T Resource) 51 | { 52 | reset(Resource); 53 | return *this; 54 | } 55 | 56 | operator value_type() { return get(); } 57 | 58 | private: 59 | value_type m_Resource = nullptr; 60 | }; 61 | 62 | template 63 | class scope_exit 64 | { 65 | public: 66 | scope_exit(T &&Callable) : m_Callable(std::move(Callable)) {} 67 | 68 | ~scope_exit() 69 | { 70 | if (m_Execute) 71 | { 72 | m_Callable(); 73 | } 74 | } 75 | 76 | void release() { m_Execute = false; } 77 | 78 | private: 79 | bool m_Execute = true; 80 | T m_Callable; 81 | }; 82 | 83 | } // namespace std 84 | -------------------------------------------------------------------------------- /kstl/stdcpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma data_seg(".STL$A") 4 | void (*___StlStartInitCalls__[1])(void) = {0}; 5 | #pragma data_seg(".STL$L") 6 | void (*___StlEndInitCalls__[1])(void) = {0}; 7 | #pragma data_seg(".STL$M") 8 | void (*___StlStartTerminateCalls__[1])(void) = {0}; 9 | #pragma data_seg(".STL$Z") 10 | void (*___StlEndTerminateCalls__[1])(void) = {0}; 11 | #pragma data_seg() 12 | 13 | #pragma comment(linker, "/merge:.STL=.data") 14 | -------------------------------------------------------------------------------- /kstl/typeinfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | type_info::~type_info() {} 4 | --------------------------------------------------------------------------------