1 /** 2 * D header file for POSIX. 3 * 4 * Copyright: Copyright Sean Kelly 2005 - 2009. 5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 * Authors: Sean Kelly, Alex Rønne Petersen 7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition 8 */ 9 10 /* Copyright Sean Kelly 2005 - 2009. 11 * Distributed under the Boost Software License, Version 1.0. 12 * (See accompanying file LICENSE or copy at 13 * http://www.boost.org/LICENSE_1_0.txt) 14 */ 15 module core.sys.posix.sys.stat; 16 17 import core.sys.posix.config; 18 import core.stdc.stdint; 19 import core.sys.posix.time; // for timespec 20 public import core.sys.posix.sys.types; // for off_t, mode_t 21 22 version (OSX) 23 version = Darwin; 24 else version (iOS) 25 version = Darwin; 26 else version (TVOS) 27 version = Darwin; 28 else version (WatchOS) 29 version = Darwin; 30 31 version (RISCV32) version = RISCV_Any; 32 version (RISCV64) version = RISCV_Any; 33 version (SPARC) version = SPARC_Any; 34 version (SPARC64) version = SPARC_Any; 35 36 version (Posix): 37 extern (C) nothrow @nogc: 38 39 // 40 // Required 41 // 42 /* 43 struct stat 44 { 45 dev_t st_dev; 46 ino_t st_ino; 47 mode_t st_mode; 48 nlink_t st_nlink; 49 uid_t st_uid; 50 gid_t st_gid; 51 off_t st_size; 52 time_t st_atime; 53 time_t st_mtime; 54 time_t st_ctime; 55 } 56 57 S_ISUID 58 S_ISGID 59 S_ISVTX 60 61 S_TYPEISMQ(buf) 62 S_TYPEISSEM(buf) 63 S_TYPEISSHM(buf) 64 */ 65 66 version (linux) 67 { 68 version (X86) 69 { 70 struct stat_t 71 { 72 dev_t st_dev; 73 ushort __pad1; 74 static if (!__USE_FILE_OFFSET64) 75 { 76 ino_t st_ino; 77 } 78 else 79 { 80 uint __st_ino; 81 } 82 mode_t st_mode; 83 nlink_t st_nlink; 84 uid_t st_uid; 85 gid_t st_gid; 86 dev_t st_rdev; 87 ushort __pad2; 88 off_t st_size; 89 blksize_t st_blksize; 90 blkcnt_t st_blocks; 91 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 92 { 93 timespec st_atim; 94 timespec st_mtim; 95 timespec st_ctim; 96 extern(D) @safe @property inout pure nothrow 97 { 98 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 99 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 100 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 101 } 102 } 103 else 104 { 105 time_t st_atime; 106 ulong_t st_atimensec; 107 time_t st_mtime; 108 ulong_t st_mtimensec; 109 time_t st_ctime; 110 ulong_t st_ctimensec; 111 } 112 static if (__USE_FILE_OFFSET64) 113 { 114 ino_t st_ino; 115 } 116 else 117 { 118 c_ulong __unused4; 119 c_ulong __unused5; 120 } 121 } 122 } 123 else version (X86_64) 124 { 125 struct stat_t 126 { 127 dev_t st_dev; 128 ino_t st_ino; 129 nlink_t st_nlink; 130 mode_t st_mode; 131 uid_t st_uid; 132 gid_t st_gid; 133 uint __pad0; 134 dev_t st_rdev; 135 off_t st_size; 136 blksize_t st_blksize; 137 blkcnt_t st_blocks; 138 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 139 { 140 timespec st_atim; 141 timespec st_mtim; 142 timespec st_ctim; 143 extern(D) @safe @property inout pure nothrow 144 { 145 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 146 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 147 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 148 } 149 } 150 else 151 { 152 time_t st_atime; 153 ulong_t st_atimensec; 154 time_t st_mtime; 155 ulong_t st_mtimensec; 156 time_t st_ctime; 157 ulong_t st_ctimensec; 158 } 159 slong_t[3] __unused; 160 } 161 } 162 else version (HPPA) 163 { 164 private 165 { 166 alias __dev_t = ulong; 167 alias __ino_t = c_ulong; 168 alias __ino64_t = ulong; 169 alias __mode_t = uint; 170 alias __nlink_t = size_t; 171 alias __uid_t = uint; 172 alias __gid_t = uint; 173 alias __off_t = c_long; 174 alias __off64_t = long; 175 alias __blksize_t = c_long; 176 alias __blkcnt_t = c_long; 177 alias __blkcnt64_t = long; 178 alias __timespec = timespec; 179 alias __time_t = time_t; 180 } 181 struct stat_t 182 { 183 __dev_t st_dev; 184 ushort __pad1; 185 186 static if (!__USE_FILE_OFFSET64) 187 { 188 __ino_t st_ino; 189 } 190 else 191 { 192 __ino_t __st_ino; 193 } 194 __mode_t st_mode; 195 __nlink_t st_nlink; 196 __uid_t st_uid; 197 __gid_t st_gid; 198 __dev_t st_rdev; 199 ushort __pad2; 200 201 static if (!__USE_FILE_OFFSET64) 202 { 203 __off_t st_size; 204 } 205 else 206 { 207 __off64_t st_size; 208 } 209 __blksize_t st_blksize; 210 211 static if (!__USE_FILE_OFFSET64) 212 { 213 __blkcnt_t st_blocks; 214 } 215 else 216 { 217 __blkcnt64_t st_blocks; 218 } 219 220 static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 221 { 222 __timespec st_atim; 223 __timespec st_mtim; 224 __timespec st_ctim; 225 extern(D) @safe @property inout pure nothrow 226 { 227 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 228 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 229 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 230 } 231 } 232 else 233 { 234 __time_t st_atime; 235 c_ulong st_atimensec; 236 __time_t st_mtime; 237 c_ulong st_mtimensec; 238 __time_t st_ctime; 239 c_ulong st_ctimensec; 240 } 241 242 static if (!__USE_FILE_OFFSET64) 243 { 244 c_ulong __unused4; 245 c_ulong __unused5; 246 } 247 else 248 { 249 __ino64_t st_ino; 250 } 251 } 252 static if (__USE_FILE_OFFSET64) 253 static assert(stat_t.sizeof == 104); 254 else 255 static assert(stat_t.sizeof == 88); 256 } 257 else version (MIPS_O32) 258 { 259 struct stat_t 260 { 261 c_ulong st_dev; 262 c_long[3] st_pad1; 263 ino_t st_ino; 264 mode_t st_mode; 265 nlink_t st_nlink; 266 uid_t st_uid; 267 gid_t st_gid; 268 c_ulong st_rdev; 269 static if (!__USE_FILE_OFFSET64) 270 { 271 c_long[2] st_pad2; 272 off_t st_size; 273 c_long st_pad3; 274 } 275 else 276 { 277 c_long[3] st_pad2; 278 off_t st_size; 279 } 280 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 281 { 282 timespec st_atim; 283 timespec st_mtim; 284 timespec st_ctim; 285 extern(D) @safe @property inout pure nothrow 286 { 287 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 288 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 289 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 290 } 291 } 292 else 293 { 294 time_t st_atime; 295 c_ulong st_atimensec; 296 time_t st_mtime; 297 c_ulong st_mtimensec; 298 time_t st_ctime; 299 c_ulong st_ctimensec; 300 } 301 blksize_t st_blksize; 302 static if (!__USE_FILE_OFFSET64) 303 { 304 blkcnt_t st_blocks; 305 } 306 else 307 { 308 c_long st_pad4; 309 blkcnt_t st_blocks; 310 } 311 c_long[14] st_pad5; 312 } 313 static if (!__USE_FILE_OFFSET64) 314 static assert(stat_t.sizeof == 144); 315 else 316 static assert(stat_t.sizeof == 160); 317 } 318 else version (MIPS64) 319 { 320 struct stat_t 321 { 322 dev_t st_dev; 323 int[3] st_pad1; 324 ino_t st_ino; 325 mode_t st_mode; 326 nlink_t st_nlink; 327 uid_t st_uid; 328 gid_t st_gid; 329 dev_t st_rdev; 330 static if (!__USE_FILE_OFFSET64) 331 { 332 uint[2] st_pad2; 333 off_t st_size; 334 int st_pad3; 335 } 336 else 337 { 338 uint[3] st_pad2; 339 off_t st_size; 340 } 341 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 342 { 343 timespec st_atim; 344 timespec st_mtim; 345 timespec st_ctim; 346 extern(D) @safe @property inout pure nothrow 347 { 348 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 349 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 350 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 351 } 352 } 353 else 354 { 355 time_t st_atime; 356 c_ulong st_atimensec; 357 time_t st_mtime; 358 c_ulong st_mtimensec; 359 time_t st_ctime; 360 c_ulong st_ctimensec; 361 } 362 blksize_t st_blksize; 363 uint st_pad4; 364 blkcnt_t st_blocks; 365 int[14] st_pad5; 366 } 367 version (MIPS_N32) 368 { 369 static if (!__USE_FILE_OFFSET64) 370 static assert(stat_t.sizeof == 160); 371 else 372 static assert(stat_t.sizeof == 176); 373 } 374 else version (MIPS_O64) 375 { 376 static if (!__USE_FILE_OFFSET64) 377 static assert(stat_t.sizeof == 160); 378 else 379 static assert(stat_t.sizeof == 176); 380 } 381 else 382 { 383 static assert(stat_t.sizeof == 216); 384 } 385 } 386 else version (PPC) 387 { 388 struct stat_t 389 { 390 dev_t st_dev; 391 static if (!__USE_FILE_OFFSET64) 392 { 393 ushort __pad1; 394 ino_t st_ino; 395 } 396 else 397 ino_t st_ino; 398 mode_t st_mode; 399 nlink_t st_nlink; 400 uid_t st_uid; 401 gid_t st_gid; 402 dev_t st_rdev; 403 ushort __pad2; 404 off_t st_size; 405 blksize_t st_blksize; 406 blkcnt_t st_blocks; 407 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 408 { 409 timespec st_atim; 410 timespec st_mtim; 411 timespec st_ctim; 412 extern(D) @safe @property inout pure nothrow 413 { 414 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 415 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 416 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 417 } 418 } 419 else 420 { 421 time_t st_atime; 422 c_ulong st_atimensec; 423 time_t st_mtime; 424 c_ulong st_mtimensec; 425 time_t st_ctime; 426 c_ulong st_ctimensec; 427 } 428 c_ulong __unused4; 429 c_ulong __unused5; 430 } 431 static if (__USE_FILE_OFFSET64) 432 static assert(stat_t.sizeof == 104); 433 else 434 static assert(stat_t.sizeof == 88); 435 } 436 else version (PPC64) 437 { 438 struct stat_t 439 { 440 dev_t st_dev; 441 ino_t st_ino; 442 nlink_t st_nlink; 443 mode_t st_mode; 444 uid_t st_uid; 445 gid_t st_gid; 446 int __pad2; 447 dev_t st_rdev; 448 off_t st_size; 449 blksize_t st_blksize; 450 blkcnt_t st_blocks; 451 static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 452 { 453 timespec st_atim; 454 timespec st_mtim; 455 timespec st_ctim; 456 extern(D) @safe @property inout pure nothrow 457 { 458 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 459 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 460 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 461 } 462 } 463 else 464 { 465 time_t st_atime; 466 c_ulong st_atimensec; 467 time_t st_mtime; 468 c_ulong st_mtimensec; 469 time_t st_ctime; 470 c_ulong st_ctimensec; 471 } 472 c_ulong __unused4; 473 c_ulong __unused5; 474 c_ulong __unused6; 475 } 476 static assert(stat_t.sizeof == 144); 477 } 478 else version (RISCV_Any) 479 { 480 private 481 { 482 alias __dev_t = ulong; 483 alias __ino_t = c_ulong; 484 alias __ino64_t = ulong; 485 alias __mode_t = uint; 486 alias __nlink_t = uint; 487 alias __uid_t = uint; 488 alias __gid_t = uint; 489 alias __off_t = c_long; 490 alias __off64_t = long; 491 alias __blksize_t = int; 492 alias __blkcnt_t = c_long; 493 alias __blkcnt64_t = long; 494 alias __timespec = timespec; 495 alias __time_t = time_t; 496 } 497 struct stat_t 498 { 499 __dev_t st_dev; 500 501 static if (__USE_FILE_OFFSET64) 502 { 503 __ino64_t st_ino; 504 } 505 else 506 { 507 __ino_t st_ino; 508 } 509 __mode_t st_mode; 510 __nlink_t st_nlink; 511 __uid_t st_uid; 512 __gid_t st_gid; 513 __dev_t st_rdev; 514 __dev_t __pad1; 515 516 static if (__USE_FILE_OFFSET64) 517 { 518 __off64_t st_size; 519 } 520 else 521 { 522 __off_t st_size; 523 } 524 __blksize_t st_blksize; 525 int __pad2; 526 527 static if (__USE_FILE_OFFSET64) 528 { 529 __blkcnt64_t st_blocks; 530 } 531 else 532 { 533 __blkcnt_t st_blocks; 534 } 535 536 static if (_DEFAULT_SOURCE) 537 { 538 __timespec st_atim; 539 __timespec st_mtim; 540 __timespec st_ctim; 541 extern(D) @safe @property inout pure nothrow 542 { 543 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 544 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 545 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 546 } 547 } 548 else 549 { 550 __time_t st_atime; 551 c_ulong st_atimensec; 552 __time_t st_mtime; 553 c_ulong st_mtimensec; 554 __time_t st_ctime; 555 c_ulong st_ctimensec; 556 } 557 int[2] __unused; 558 } 559 } 560 else version (ARM) 561 { 562 private 563 { 564 alias __dev_t = ulong; 565 alias __ino_t = c_ulong; 566 alias __ino64_t = ulong; 567 alias __mode_t = uint; 568 alias __nlink_t = size_t; 569 alias __uid_t = uint; 570 alias __gid_t = uint; 571 alias __off_t = c_long; 572 alias __off64_t = long; 573 alias __blksize_t = c_long; 574 alias __blkcnt_t = c_long; 575 alias __blkcnt64_t = long; 576 alias __timespec = timespec; 577 alias __time_t = time_t; 578 } 579 struct stat_t 580 { 581 __dev_t st_dev; 582 ushort __pad1; 583 584 static if (!__USE_FILE_OFFSET64) 585 { 586 __ino_t st_ino; 587 } 588 else 589 { 590 __ino_t __st_ino; 591 } 592 __mode_t st_mode; 593 __nlink_t st_nlink; 594 __uid_t st_uid; 595 __gid_t st_gid; 596 __dev_t st_rdev; 597 ushort __pad2; 598 599 static if (!__USE_FILE_OFFSET64) 600 { 601 __off_t st_size; 602 } 603 else 604 { 605 __off64_t st_size; 606 } 607 __blksize_t st_blksize; 608 609 static if (!__USE_FILE_OFFSET64) 610 { 611 __blkcnt_t st_blocks; 612 } 613 else 614 { 615 __blkcnt64_t st_blocks; 616 } 617 618 static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700) 619 { 620 __timespec st_atim; 621 __timespec st_mtim; 622 __timespec st_ctim; 623 extern(D) @safe @property inout pure nothrow 624 { 625 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 626 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 627 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 628 } 629 } 630 else 631 { 632 __time_t st_atime; 633 c_ulong st_atimensec; 634 __time_t st_mtime; 635 c_ulong st_mtimensec; 636 __time_t st_ctime; 637 c_ulong st_ctimensec; 638 } 639 640 static if (!__USE_FILE_OFFSET64) 641 { 642 c_ulong __unused4; 643 c_ulong __unused5; 644 } 645 else 646 { 647 __ino64_t st_ino; 648 } 649 } 650 static if (__USE_FILE_OFFSET64) 651 static assert(stat_t.sizeof == 104); 652 else 653 static assert(stat_t.sizeof == 88); 654 } 655 else version (AArch64) 656 { 657 private 658 { 659 alias __dev_t = ulong; 660 alias __ino_t = c_ulong; 661 alias __ino64_t = ulong; 662 alias __mode_t = uint; 663 alias __nlink_t = uint; 664 alias __uid_t = uint; 665 alias __gid_t = uint; 666 alias __off_t = c_long; 667 alias __off64_t = long; 668 alias __blksize_t = int; 669 alias __blkcnt_t = c_long; 670 alias __blkcnt64_t = long; 671 alias __timespec = timespec; 672 alias __time_t = time_t; 673 } 674 struct stat_t 675 { 676 __dev_t st_dev; 677 678 static if (!__USE_FILE_OFFSET64) 679 { 680 __ino_t st_ino; 681 } 682 else 683 { 684 __ino64_t st_ino; 685 } 686 __mode_t st_mode; 687 __nlink_t st_nlink; 688 __uid_t st_uid; 689 __gid_t st_gid; 690 __dev_t st_rdev; 691 __dev_t __pad1; 692 693 static if (!__USE_FILE_OFFSET64) 694 { 695 __off_t st_size; 696 } 697 else 698 { 699 __off64_t st_size; 700 } 701 __blksize_t st_blksize; 702 int __pad2; 703 704 static if (!__USE_FILE_OFFSET64) 705 { 706 __blkcnt_t st_blocks; 707 } 708 else 709 { 710 __blkcnt64_t st_blocks; 711 } 712 713 static if (_DEFAULT_SOURCE) 714 { 715 __timespec st_atim; 716 __timespec st_mtim; 717 __timespec st_ctim; 718 extern(D) @safe @property inout pure nothrow 719 { 720 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 721 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 722 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 723 } 724 } 725 else 726 { 727 __time_t st_atime; 728 c_ulong st_atimensec; 729 __time_t st_mtime; 730 c_ulong st_mtimensec; 731 __time_t st_ctime; 732 c_ulong st_ctimensec; 733 } 734 int[2] __unused; 735 } 736 version (D_LP64) 737 static assert(stat_t.sizeof == 128); 738 else 739 static assert(stat_t.sizeof == 104); 740 } 741 else version (SPARC_Any) 742 { 743 private 744 { 745 alias __dev_t = ulong; 746 alias __ino_t = c_ulong; 747 alias __ino64_t = ulong; 748 alias __mode_t = uint; 749 alias __nlink_t = uint; 750 alias __uid_t = uint; 751 alias __gid_t = uint; 752 alias __off_t = c_long; 753 alias __off64_t = long; 754 alias __blksize_t = c_long; 755 alias __blkcnt_t = c_long; 756 alias __blkcnt64_t = long; 757 alias __timespec = timespec; 758 alias __time_t = time_t; 759 } 760 struct stat_t 761 { 762 __dev_t st_dev; 763 static if (__WORDSIZE == 64 || !__USE_FILE_OFFSET64) 764 { 765 ushort __pad1; 766 __ino_t st_ino; 767 } 768 else 769 { 770 __ino64_t st_ino; 771 } 772 __mode_t st_mode; 773 __nlink_t st_nlink; 774 __uid_t st_uid; 775 __gid_t st_gid; 776 __dev_t st_rdev; 777 ushort __pad2; 778 779 static if (!__USE_FILE_OFFSET64) 780 { 781 __off_t st_size; 782 } 783 else 784 { 785 __off64_t st_size; 786 } 787 __blksize_t st_blksize; 788 789 static if (!__USE_FILE_OFFSET64) 790 { 791 __blkcnt_t st_blocks; 792 } 793 else 794 { 795 __blkcnt64_t st_blocks; 796 } 797 798 static if (_XOPEN_SOURCE >= 700) 799 { 800 __timespec st_atim; 801 __timespec st_mtim; 802 __timespec st_ctim; 803 extern(D) @safe @property inout pure nothrow 804 { 805 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 806 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 807 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 808 } 809 } 810 else 811 { 812 __time_t st_atime; 813 c_ulong st_atimensec; 814 __time_t st_mtime; 815 c_ulong st_mtimensec; 816 __time_t st_ctime; 817 c_ulong st_ctimensec; 818 } 819 820 c_ulong __unused4; 821 c_ulong __unused5; 822 } 823 static if (__USE_LARGEFILE64) alias stat_t stat64_t; 824 825 static if (__WORDSIZE == 64) 826 static assert(stat_t.sizeof == 144); 827 else static if (__USE_FILE_OFFSET64) 828 static assert(stat_t.sizeof == 104); 829 else 830 static assert(stat_t.sizeof == 88); 831 832 } 833 else version (S390) 834 { 835 private 836 { 837 alias __dev_t = ulong; 838 alias __ino_t = c_ulong; 839 alias __ino64_t = ulong; 840 alias __mode_t = uint; 841 alias __nlink_t = uint; 842 alias __uid_t = uint; 843 alias __gid_t = uint; 844 alias __off_t = c_long; 845 alias __off64_t = long; 846 alias __blksize_t = c_long; 847 alias __blkcnt_t = c_long; 848 alias __blkcnt64_t = long; 849 alias __timespec = timespec; 850 alias __time_t = time_t; 851 } 852 struct stat_t 853 { 854 __dev_t st_dev; 855 uint __pad1; 856 static if (!__USE_FILE_OFFSET64) 857 __ino_t st_ino; 858 else 859 __ino_t __st_ino; 860 __mode_t st_mode; 861 __nlink_t st_nlink; 862 __uid_t st_uid; 863 __gid_t st_gid; 864 __dev_t st_rdev; 865 uint __pad2; 866 static if (!__USE_FILE_OFFSET64) 867 __off_t st_size; 868 else 869 __off64_t st_size; 870 __blksize_t st_blksize; 871 static if (!__USE_FILE_OFFSET64) 872 __blkcnt_t st_blocks; 873 else 874 __blkcnt64_t st_blocks; 875 static if (_XOPEN_SOURCE >= 700) 876 { 877 __timespec st_atim; 878 __timespec st_mtim; 879 __timespec st_ctim; 880 extern(D) @safe @property inout pure nothrow 881 { 882 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 883 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 884 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 885 } 886 } 887 else 888 { 889 __time_t st_atime; 890 c_ulong st_atimensec; 891 __time_t st_mtime; 892 c_ulong st_mtimensec; 893 __time_t st_ctime; 894 c_ulong st_ctimensec; 895 } 896 static if (!__USE_FILE_OFFSET64) 897 { 898 c_ulong __glibc_reserved4; 899 c_ulong __glibc_reserved5; 900 } 901 else 902 __ino64_t st_ino; 903 } 904 static if (__USE_FILE_OFFSET64) 905 static assert(stat_t.sizeof == 104); 906 else 907 static assert(stat_t.sizeof == 88); 908 } 909 else version (SystemZ) 910 { 911 private 912 { 913 alias __dev_t = ulong; 914 alias __ino_t = c_ulong; 915 alias __ino64_t = ulong; 916 alias __mode_t = uint; 917 alias __nlink_t = ulong; 918 alias __uid_t = uint; 919 alias __gid_t = uint; 920 alias __off_t = c_long; 921 alias __off64_t = long; 922 alias __blksize_t = c_long; 923 alias __blkcnt_t = c_long; 924 alias __blkcnt64_t = long; 925 alias __timespec = timespec; 926 alias __time_t = time_t; 927 } 928 struct stat_t 929 { 930 __dev_t st_dev; 931 __ino_t st_ino; 932 __nlink_t st_nlink; 933 __mode_t st_mode; 934 __uid_t st_uid; 935 __gid_t st_gid; 936 int __glibc_reserved0; 937 __dev_t st_rdev; 938 __off_t st_size; 939 static if (_XOPEN_SOURCE >= 700) 940 { 941 __timespec st_atim; 942 __timespec st_mtim; 943 __timespec st_ctim; 944 extern(D) @safe @property inout pure nothrow 945 { 946 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 947 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 948 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 949 } 950 } 951 else 952 { 953 __time_t st_atime; 954 c_ulong st_atimensec; 955 __time_t st_mtime; 956 c_ulong st_mtimensec; 957 __time_t st_ctime; 958 c_ulong st_ctimensec; 959 } 960 __blksize_t st_blksize; 961 __blkcnt_t st_blocks; 962 c_long[3] __glibc_reserved; 963 } 964 static if (_XOPEN_SOURCE >= 700) 965 static assert(stat_t.sizeof == 144); 966 else 967 static assert(stat_t.sizeof == 144); 968 } 969 else 970 static assert(0, "unimplemented"); 971 972 enum S_ISUID = 0x800; // octal 04000 973 enum S_ISGID = 0x400; // octal 02000 974 enum S_ISVTX = 0x200; // octal 01000 975 976 static if ( true /*__USE_POSIX199309*/ ) 977 { 978 extern bool S_TYPEISMQ( stat_t* buf ) { return false; } 979 extern bool S_TYPEISSEM( stat_t* buf ) { return false; } 980 extern bool S_TYPEISSHM( stat_t* buf ) { return false; } 981 } 982 983 enum UTIME_NOW = 0x3fffffff; 984 enum UTIME_OMIT = 0x3ffffffe; 985 } 986 else version (Darwin) 987 { 988 // _DARWIN_FEATURE_64_BIT_INODE stat is default for Mac OSX >10.5 and is 989 // only meaningful type for other OS X/Darwin variants (e.g. iOS). 990 // man stat(2) gives details. 991 struct stat_t 992 { 993 dev_t st_dev; 994 mode_t st_mode; 995 nlink_t st_nlink; 996 ino_t st_ino; 997 uid_t st_uid; 998 gid_t st_gid; 999 dev_t st_rdev; 1000 union 1001 { 1002 struct 1003 { 1004 timespec st_atimespec; 1005 timespec st_mtimespec; 1006 timespec st_ctimespec; 1007 timespec st_birthtimespec; 1008 } 1009 struct 1010 { 1011 time_t st_atime; 1012 c_long st_atimensec; 1013 time_t st_mtime; 1014 c_long st_mtimensec; 1015 time_t st_ctime; 1016 c_long st_ctimensec; 1017 time_t st_birthtime; 1018 c_long st_birthtimensec; 1019 } 1020 } 1021 off_t st_size; 1022 blkcnt_t st_blocks; 1023 blksize_t st_blksize; 1024 uint st_flags; 1025 uint st_gen; 1026 int st_lspare; 1027 long[2] st_qspare; 1028 } 1029 1030 enum S_ISUID = 0x800; // octal 04000 1031 enum S_ISGID = 0x400; // octal 02000 1032 enum S_ISVTX = 0x200; // octal 01000 1033 } 1034 else version (FreeBSD) 1035 { 1036 import core.sys.freebsd.config; 1037 1038 // https://github.com/freebsd/freebsd/blob/master/sys/sys/stat.h 1039 static if (__FreeBSD_version >= INO64_FIRST) 1040 { 1041 struct stat_t 1042 { 1043 dev_t st_dev; 1044 ino_t st_ino; 1045 nlink_t st_nlink; 1046 mode_t st_mode; 1047 short st_padding0; 1048 uid_t st_uid; 1049 gid_t st_gid; 1050 int st_padding1; 1051 dev_t st_rdev; 1052 1053 version (X86) int st_atim_ext; 1054 timespec st_atim; 1055 1056 version (X86) int st_mtim_ext; 1057 timespec st_mtim; 1058 1059 version (X86) int st_ctim_ext; 1060 timespec st_ctim; 1061 1062 version (X86) int st_btim_ext; 1063 timespec st_birthtim; 1064 1065 off_t st_size; 1066 blkcnt_t st_blocks; 1067 blksize_t st_blksize; 1068 fflags_t st_flags; 1069 ulong st_gen; 1070 ulong[10] st_spare; 1071 1072 extern(D) @safe @property inout pure nothrow 1073 { 1074 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 1075 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 1076 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 1077 ref inout(time_t) st_birthtime() return { return st_birthtim.tv_sec; } 1078 } 1079 } 1080 } 1081 else 1082 { 1083 struct stat_t 1084 { 1085 uint st_dev; 1086 uint st_ino; 1087 mode_t st_mode; 1088 ushort st_nlink; 1089 uid_t st_uid; 1090 gid_t st_gid; 1091 uint st_rdev; 1092 timespec st_atim; 1093 timespec st_mtim; 1094 timespec st_ctim; 1095 off_t st_size; 1096 blkcnt_t st_blocks; 1097 blksize_t st_blksize; 1098 fflags_t st_flags; 1099 uint st_gen; 1100 int st_lspare; 1101 timespec st_birthtim; 1102 ubyte[16 - timespec.sizeof] padding; 1103 1104 extern(D) @safe @property inout pure nothrow 1105 { 1106 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 1107 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 1108 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 1109 ref inout(time_t) st_birthtime() return { return st_birthtim.tv_sec; } 1110 } 1111 } 1112 } 1113 1114 enum S_ISUID = 0x800; // octal 0004000 1115 enum S_ISGID = 0x400; // octal 0002000 1116 enum S_ISVTX = 0x200; // octal 0001000 1117 1118 enum UTIME_NOW = -1; 1119 enum UTIME_OMIT = -2; 1120 } 1121 else version (NetBSD) 1122 { 1123 struct stat_t 1124 { 1125 dev_t st_dev; /* inode's device */ 1126 mode_t st_mode; /* inode protection mode */ 1127 ino_t st_ino; /* inode's number */ 1128 nlink_t st_nlink; /* number of hard links */ 1129 uid_t st_uid; /* user ID of the file's owner */ 1130 gid_t st_gid; /* group ID of the file's group */ 1131 dev_t st_rdev; /* device type */ 1132 time_t st_atime; /* time of last access */ 1133 long st_atimensec; /* nsec of last access */ 1134 time_t st_mtime; /* time of last data modification */ 1135 long st_mtimensec; /* nsec of last data modification */ 1136 time_t st_ctime; /* time of last file status change */ 1137 long st_ctimensec; /* nsec of last file status change */ 1138 time_t st_birthtime; /* time of creation */ 1139 long st_birthtimensec; /* nsec of time of creation */ 1140 off_t st_size; /* file size, in bytes */ 1141 blkcnt_t st_blocks; /* blocks allocated for file */ 1142 blksize_t st_blksize; /* optimal blocksize for I/O */ 1143 uint32_t st_flags; /* user defined flags for file */ 1144 uint32_t st_gen; /* file generation number */ 1145 uint32_t[2] st_spare; 1146 } 1147 1148 enum S_ISUID = 0x800; // octal 0004000 1149 enum S_ISGID = 0x400; // octal 0002000 1150 enum S_ISVTX = 0x200; // octal 0001000 1151 } 1152 else version (OpenBSD) 1153 { 1154 import core.sys.openbsd.sys.cdefs; 1155 1156 struct stat_t 1157 { 1158 mode_t st_mode; 1159 dev_t st_dev; 1160 ino_t st_ino; 1161 nlink_t st_nlink; 1162 uid_t st_uid; 1163 gid_t st_gid; 1164 dev_t st_rdev; 1165 static if (__POSIX_VISIBLE >= 200809 || __BSD_VISIBLE) 1166 { 1167 timespec st_atim; 1168 timespec st_mtim; 1169 timespec st_ctim; 1170 extern(D) @safe @property inout pure nothrow 1171 { 1172 ref inout(time_t) st_atime() return { return st_atim.tv_sec; } 1173 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; } 1174 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; } 1175 } 1176 } 1177 else 1178 { 1179 time_t st_atime; 1180 long st_atimensec; 1181 time_t st_mtime; 1182 long st_mtimensec; 1183 time_t st_ctime; 1184 long st_ctimensec; 1185 } 1186 off_t st_size; 1187 blkcnt_t st_blocks; 1188 blksize_t st_blksize; 1189 uint32_t st_flags; 1190 uint32_t st_gen; 1191 static if (__POSIX_VISIBLE >= 200809 || __BSD_VISIBLE) 1192 { 1193 timespec __st_birthtim; 1194 } 1195 else 1196 { 1197 time_t __st_birthtime; 1198 long __st_birthtimensec; 1199 } 1200 } 1201 1202 enum S_ISUID = 0x800; // octal 0004000 1203 enum S_ISGID = 0x400; // octal 0002000 1204 enum S_ISVTX = 0x200; // octal 0001000 1205 } 1206 else version (DragonFlyBSD) 1207 { 1208 struct stat_t { 1209 ino_t st_ino; /* inode's number */ 1210 nlink_t st_nlink; /* number of hard links */ 1211 dev_t st_dev; /* inode's device */ 1212 mode_t st_mode; /* inode protection mode */ 1213 uint16_t st_padding1; 1214 uid_t st_uid; /* user ID of the file's owner */ 1215 gid_t st_gid; /* group ID of the file's group */ 1216 dev_t st_rdev; /* device type */ 1217 time_t st_atime; 1218 c_long __st_atimensec; 1219 time_t st_mtime; 1220 c_long __st_mtimensec; 1221 time_t st_ctime; 1222 c_long __st_ctimensec; 1223 off_t st_size; /* file size, in bytes */ 1224 int64_t st_blocks; /* blocks allocated for file */ 1225 uint32_t st_blksize; /* optimal blocksize for I/O */ 1226 uint32_t st_flags; /* user defined flags for file */ 1227 uint32_t st_gen; /* file generation number */ 1228 int32_t st_lspare; 1229 int64_t st_qspare1; /* was recursive change detect */ 1230 int64_t st_qspare2; 1231 } 1232 1233 enum S_ISUID = 0x800; // octal 0004000 1234 enum S_ISGID = 0x400; // octal 0002000 1235 enum S_ISVTX = 0x200; // octal 0001000 1236 } 1237 else version (Solaris) 1238 { 1239 private enum _ST_FSTYPSZ = 16; 1240 1241 version (D_LP64) 1242 { 1243 struct stat_t 1244 { 1245 dev_t st_dev; 1246 ino_t st_ino; 1247 mode_t st_mode; 1248 nlink_t st_nlink; 1249 uid_t st_uid; 1250 gid_t st_gid; 1251 dev_t st_rdev; 1252 off_t st_size; 1253 union 1254 { 1255 timestruc_t st_atim; 1256 time_t st_atime; 1257 } 1258 union 1259 { 1260 timestruc_t st_mtim; 1261 time_t st_mtime; 1262 } 1263 union 1264 { 1265 timestruc_t st_ctim; 1266 time_t st_ctime; 1267 } 1268 blksize_t st_blksize; 1269 blkcnt_t st_blocks; 1270 char[_ST_FSTYPSZ] st_fstype = 0; 1271 } 1272 1273 static if (__USE_LARGEFILE64) alias stat_t stat64_t; 1274 } 1275 else 1276 { 1277 struct stat32_t 1278 { 1279 dev_t st_dev; 1280 c_long[3] st_pad1; 1281 ino_t st_ino; 1282 mode_t st_mode; 1283 nlink_t st_nlink; 1284 uid_t st_uid; 1285 gid_t st_gid; 1286 dev_t st_rdev; 1287 c_long[2] st_pad2; 1288 off_t st_size; 1289 c_long st_pad3; 1290 union 1291 { 1292 timestruc_t st_atim; 1293 time_t st_atime; 1294 } 1295 union 1296 { 1297 timestruc_t st_mtim; 1298 time_t st_mtime; 1299 } 1300 union 1301 { 1302 timestruc_t st_ctim; 1303 time_t st_ctime; 1304 } 1305 blksize_t st_blksize; 1306 blkcnt_t st_blocks; 1307 char[_ST_FSTYPSZ] st_fstype = 0; 1308 c_long[8] st_pad4; 1309 } 1310 1311 struct stat64_t 1312 { 1313 dev_t st_dev; 1314 c_long[3] st_pad1; 1315 ino64_t st_ino; 1316 mode_t st_mode; 1317 nlink_t st_nlink; 1318 uid_t st_uid; 1319 gid_t st_gid; 1320 dev_t st_rdev; 1321 c_long[2] st_pad2; 1322 off64_t st_size; 1323 union 1324 { 1325 timestruc_t st_atim; 1326 time_t st_atime; 1327 } 1328 union 1329 { 1330 timestruc_t st_mtim; 1331 time_t st_mtime; 1332 } 1333 union 1334 { 1335 timestruc_t st_ctim; 1336 time_t st_ctime; 1337 } 1338 blksize_t st_blksize; 1339 blkcnt64_t st_blocks; 1340 char[_ST_FSTYPSZ] st_fstype = 0; 1341 c_long[8] st_pad4; 1342 } 1343 1344 static if (__USE_FILE_OFFSET64) 1345 alias stat64_t stat_t; 1346 else 1347 alias stat32_t stat_t; 1348 1349 } 1350 1351 enum S_ISUID = 0x800; 1352 enum S_ISGID = 0x400; 1353 enum S_ISVTX = 0x200; 1354 } 1355 else 1356 { 1357 static assert(false, "Unsupported platform"); 1358 } 1359 1360 /* 1361 S_IRWXU 1362 S_IRUSR 1363 S_IWUSR 1364 S_IXUSR 1365 S_IRWXG 1366 S_IRGRP 1367 S_IWGRP 1368 S_IXGRP 1369 S_IRWXO 1370 S_IROTH 1371 S_IWOTH 1372 S_IXOTH 1373 1374 S_ISBLK(m) 1375 S_ISCHR(m) 1376 S_ISDIR(m) 1377 S_ISFIFO(m) 1378 S_ISREG(m) 1379 S_ISLNK(m) 1380 S_ISSOCK(m) 1381 */ 1382 1383 version (CRuntime_Glibc) 1384 { 1385 enum S_IRUSR = 0x100; // octal 0400 1386 enum S_IWUSR = 0x080; // octal 0200 1387 enum S_IXUSR = 0x040; // octal 0100 1388 enum S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR; 1389 1390 enum S_IRGRP = S_IRUSR >> 3; 1391 enum S_IWGRP = S_IWUSR >> 3; 1392 enum S_IXGRP = S_IXUSR >> 3; 1393 enum S_IRWXG = S_IRWXU >> 3; 1394 1395 enum S_IROTH = S_IRGRP >> 3; 1396 enum S_IWOTH = S_IWGRP >> 3; 1397 enum S_IXOTH = S_IXGRP >> 3; 1398 enum S_IRWXO = S_IRWXG >> 3; 1399 1400 private 1401 { 1402 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1403 { 1404 return ( mode & S_IFMT ) == mask; 1405 } 1406 } 1407 1408 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1409 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1410 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1411 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1412 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1413 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1414 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1415 1416 int utimensat(int dirfd, const char *pathname, 1417 ref const(timespec)[2] times, int flags); 1418 int futimens(int fd, ref const(timespec)[2] times); 1419 } 1420 else version (Darwin) 1421 { 1422 enum S_IRUSR = 0x100; // octal 0400 1423 enum S_IWUSR = 0x080; // octal 0200 1424 enum S_IXUSR = 0x040; // octal 0100 1425 enum S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR; 1426 1427 enum S_IRGRP = S_IRUSR >> 3; 1428 enum S_IWGRP = S_IWUSR >> 3; 1429 enum S_IXGRP = S_IXUSR >> 3; 1430 enum S_IRWXG = S_IRWXU >> 3; 1431 1432 enum S_IROTH = S_IRGRP >> 3; 1433 enum S_IWOTH = S_IWGRP >> 3; 1434 enum S_IXOTH = S_IXGRP >> 3; 1435 enum S_IRWXO = S_IRWXG >> 3; 1436 1437 private 1438 { 1439 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1440 { 1441 return ( mode & S_IFMT ) == mask; 1442 } 1443 } 1444 1445 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1446 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1447 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1448 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1449 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1450 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1451 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1452 } 1453 else version (FreeBSD) 1454 { 1455 enum S_IRUSR = 0x100; // octal 0000400 1456 enum S_IWUSR = 0x080; // octal 0000200 1457 enum S_IXUSR = 0x040; // octal 0000100 1458 enum S_IRWXU = 0x1C0; // octal 0000700 1459 1460 enum S_IRGRP = 0x020; // octal 0000040 1461 enum S_IWGRP = 0x010; // octal 0000020 1462 enum S_IXGRP = 0x008; // octal 0000010 1463 enum S_IRWXG = 0x038; // octal 0000070 1464 1465 enum S_IROTH = 0x4; // 0000004 1466 enum S_IWOTH = 0x2; // 0000002 1467 enum S_IXOTH = 0x1; // 0000001 1468 enum S_IRWXO = 0x7; // 0000007 1469 1470 private 1471 { 1472 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1473 { 1474 return ( mode & S_IFMT ) == mask; 1475 } 1476 } 1477 1478 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1479 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1480 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1481 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1482 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1483 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1484 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1485 1486 // Since FreeBSD 11: 1487 version (none) 1488 { 1489 int utimensat(int dirfd, const char *pathname, 1490 ref const(timespec)[2] times, int flags); 1491 int futimens(int fd, ref const(timespec)[2] times); 1492 } 1493 } 1494 else version (NetBSD) 1495 { 1496 enum S_IRUSR = 0x100; // octal 0000400 1497 enum S_IWUSR = 0x080; // octal 0000200 1498 enum S_IXUSR = 0x040; // octal 0000100 1499 enum S_IRWXU = 0x1C0; // octal 0000700 1500 1501 enum S_IRGRP = 0x020; // octal 0000040 1502 enum S_IWGRP = 0x010; // octal 0000020 1503 enum S_IXGRP = 0x008; // octal 0000010 1504 enum S_IRWXG = 0x038; // octal 0000070 1505 1506 enum S_IROTH = 0x4; // 0000004 1507 enum S_IWOTH = 0x2; // 0000002 1508 enum S_IXOTH = 0x1; // 0000001 1509 enum S_IRWXO = 0x7; // 0000007 1510 1511 private 1512 { 1513 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1514 { 1515 return ( mode & S_IFMT ) == mask; 1516 } 1517 } 1518 1519 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1520 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1521 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1522 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1523 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1524 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1525 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1526 } 1527 else version (OpenBSD) 1528 { 1529 enum S_IRUSR = 0x100; // octal 0000400 1530 enum S_IWUSR = 0x080; // octal 0000200 1531 enum S_IXUSR = 0x040; // octal 0000100 1532 enum S_IRWXU = 0x1C0; // octal 0000700 1533 1534 enum S_IRGRP = 0x020; // octal 0000040 1535 enum S_IWGRP = 0x010; // octal 0000020 1536 enum S_IXGRP = 0x008; // octal 0000010 1537 enum S_IRWXG = 0x038; // octal 0000070 1538 1539 enum S_IROTH = 0x4; // 0000004 1540 enum S_IWOTH = 0x2; // 0000002 1541 enum S_IXOTH = 0x1; // 0000001 1542 enum S_IRWXO = 0x7; // 0000007 1543 1544 extern (D) bool S_ISBLK(mode_t mode) { return (mode & S_IFMT) == S_IFBLK; } 1545 extern (D) bool S_ISCHR(mode_t mode) { return (mode & S_IFMT) == S_IFCHR; } 1546 extern (D) bool S_ISDIR(mode_t mode) { return (mode & S_IFMT) == S_IFDIR; } 1547 extern (D) bool S_ISFIFO(mode_t mode) { return (mode & S_IFMT) == S_IFIFO; } 1548 extern (D) bool S_ISREG(mode_t mode) { return (mode & S_IFMT) == S_IFREG; } 1549 extern (D) bool S_ISLNK(mode_t mode) { return (mode & S_IFMT) == S_IFLNK; } 1550 extern (D) bool S_ISSOCK(mode_t mode) { return (mode & S_IFMT) == S_IFSOCK; } 1551 } 1552 else version (DragonFlyBSD) 1553 { 1554 enum S_IRUSR = 0x100; // octal 0000400 1555 enum S_IWUSR = 0x080; // octal 0000200 1556 enum S_IXUSR = 0x040; // octal 0000100 1557 enum S_IRWXU = 0x1C0; // octal 0000700 1558 1559 enum S_IRGRP = 0x020; // octal 0000040 1560 enum S_IWGRP = 0x010; // octal 0000020 1561 enum S_IXGRP = 0x008; // octal 0000010 1562 enum S_IRWXG = 0x038; // octal 0000070 1563 1564 enum S_IROTH = 0x4; // 0000004 1565 enum S_IWOTH = 0x2; // 0000002 1566 enum S_IXOTH = 0x1; // 0000001 1567 enum S_IRWXO = 0x7; // 0000007 1568 1569 private 1570 { 1571 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1572 { 1573 return ( mode & S_IFMT ) == mask; 1574 } 1575 } 1576 1577 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1578 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1579 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1580 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1581 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1582 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1583 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1584 } 1585 else version (Solaris) 1586 { 1587 enum S_IRUSR = 0x100; 1588 enum S_IWUSR = 0x080; 1589 enum S_IXUSR = 0x040; 1590 enum S_IRWXU = 0x1C0; 1591 1592 enum S_IRGRP = 0x020; 1593 enum S_IWGRP = 0x010; 1594 enum S_IXGRP = 0x008; 1595 enum S_IRWXG = 0x038; 1596 1597 enum S_IROTH = 0x4; // 0000004 1598 enum S_IWOTH = 0x2; // 0000002 1599 enum S_IXOTH = 0x1; // 0000001 1600 enum S_IRWXO = 0x7; // 0000007 1601 1602 private 1603 { 1604 extern (D) bool S_ISTYPE(mode_t mode, uint mask) 1605 { 1606 return (mode & S_IFMT) == mask; 1607 } 1608 } 1609 1610 extern (D) bool S_ISBLK(mode_t mode) { return S_ISTYPE(mode, S_IFBLK); } 1611 extern (D) bool S_ISCHR(mode_t mode) { return S_ISTYPE(mode, S_IFCHR); } 1612 extern (D) bool S_ISDIR(mode_t mode) { return S_ISTYPE(mode, S_IFDIR); } 1613 extern (D) bool S_ISFIFO(mode_t mode) { return S_ISTYPE(mode, S_IFIFO); } 1614 extern (D) bool S_ISREG(mode_t mode) { return S_ISTYPE(mode, S_IFREG); } 1615 extern (D) bool S_ISLNK(mode_t mode) { return S_ISTYPE(mode, S_IFLNK); } 1616 extern (D) bool S_ISSOCK(mode_t mode) { return S_ISTYPE(mode, S_IFSOCK); } 1617 extern (D) bool S_ISDOOR(mode_t mode) { return S_ISTYPE(mode, S_IFDOOR); } 1618 extern (D) bool S_ISPORT(mode_t mode) { return S_ISTYPE(mode, S_IFPORT); } 1619 } 1620 else version (CRuntime_Bionic) 1621 { 1622 enum S_IRUSR = 0x100; // octal 0000400 1623 enum S_IWUSR = 0x080; // octal 0000200 1624 enum S_IXUSR = 0x040; // octal 0000100 1625 enum S_IRWXU = 0x1C0; // octal 0000700 1626 1627 enum S_IRGRP = 0x020; // octal 0000040 1628 enum S_IWGRP = 0x010; // octal 0000020 1629 enum S_IXGRP = 0x008; // octal 0000010 1630 enum S_IRWXG = 0x038; // octal 0000070 1631 1632 enum S_IROTH = 0x4; // 0000004 1633 enum S_IWOTH = 0x2; // 0000002 1634 enum S_IXOTH = 0x1; // 0000001 1635 enum S_IRWXO = 0x7; // 0000007 1636 1637 private 1638 { 1639 extern (D) bool S_ISTYPE( uint mode, uint mask ) 1640 { 1641 return ( mode & S_IFMT ) == mask; 1642 } 1643 } 1644 1645 extern (D) bool S_ISBLK( uint mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1646 extern (D) bool S_ISCHR( uint mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1647 extern (D) bool S_ISDIR( uint mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1648 extern (D) bool S_ISFIFO( uint mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1649 extern (D) bool S_ISREG( uint mode ) { return S_ISTYPE( mode, S_IFREG ); } 1650 extern (D) bool S_ISLNK( uint mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1651 extern (D) bool S_ISSOCK( uint mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1652 1653 // Added since Lollipop 1654 int utimensat(int dirfd, const char *pathname, 1655 ref const(timespec)[2] times, int flags); 1656 } 1657 else version (CRuntime_Musl) 1658 { 1659 enum { 1660 S_IRUSR = 0x100, // octal 0400 1661 S_IWUSR = 0x080, // octal 0200 1662 S_IXUSR = 0x040, // octal 0100 1663 S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR, 1664 1665 S_IRGRP = S_IRUSR >> 3, 1666 S_IWGRP = S_IWUSR >> 3, 1667 S_IXGRP = S_IXUSR >> 3, 1668 S_IRWXG = S_IRWXU >> 3, 1669 1670 S_IROTH = S_IRGRP >> 3, 1671 S_IWOTH = S_IWGRP >> 3, 1672 S_IXOTH = S_IXGRP >> 3, 1673 S_IRWXO = S_IRWXG >> 3, 1674 } 1675 1676 private 1677 { 1678 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1679 { 1680 return ( mode & S_IFMT ) == mask; 1681 } 1682 } 1683 1684 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1685 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1686 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1687 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1688 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1689 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1690 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1691 1692 int utimensat(int dirfd, const char *pathname, 1693 ref const(timespec)[2] times, int flags); 1694 } 1695 else version (CRuntime_UClibc) 1696 { 1697 enum S_IRUSR = 0x100; // octal 0400 1698 enum S_IWUSR = 0x080; // octal 0200 1699 enum S_IXUSR = 0x040; // octal 0100 1700 enum S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR; 1701 1702 enum S_IRGRP = S_IRUSR >> 3; 1703 enum S_IWGRP = S_IWUSR >> 3; 1704 enum S_IXGRP = S_IXUSR >> 3; 1705 enum S_IRWXG = S_IRWXU >> 3; 1706 1707 enum S_IROTH = S_IRGRP >> 3; 1708 enum S_IWOTH = S_IWGRP >> 3; 1709 enum S_IXOTH = S_IXGRP >> 3; 1710 enum S_IRWXO = S_IRWXG >> 3; 1711 1712 private 1713 { 1714 extern (D) bool S_ISTYPE( mode_t mode, uint mask ) 1715 { 1716 return ( mode & S_IFMT ) == mask; 1717 } 1718 } 1719 1720 extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); } 1721 extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); } 1722 extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); } 1723 extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); } 1724 extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); } 1725 extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); } 1726 extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); } 1727 1728 int utimensat(int dirfd, const char *pathname, 1729 ref const(timespec)[2] times, int flags); 1730 int futimens(int fd, ref const(timespec)[2] times); 1731 } 1732 else 1733 { 1734 static assert(false, "Unsupported platform"); 1735 } 1736 1737 /* 1738 int chmod(const scope char*, mode_t); 1739 int fchmod(int, mode_t); 1740 int fstat(int, stat*); 1741 int lstat(const scope char*, stat*); 1742 int mkdir(const scope char*, mode_t); 1743 int mkfifo(const scope char*, mode_t); 1744 int stat(const scope char*, stat*); 1745 mode_t umask(mode_t); 1746 */ 1747 1748 int chmod(const scope char*, mode_t); 1749 int fchmod(int, mode_t); 1750 //int fstat(int, stat_t*); 1751 //int lstat(const scope char*, stat_t*); 1752 int mkdir(const scope char*, mode_t); 1753 int mkfifo(const scope char*, mode_t); 1754 //int stat(const scope char*, stat_t*); 1755 mode_t umask(mode_t); 1756 1757 version (CRuntime_Glibc) 1758 { 1759 static if ( __USE_LARGEFILE64 ) 1760 { 1761 int fstat64(int, stat_t*) @trusted; 1762 alias fstat64 fstat; 1763 1764 int lstat64(const scope char*, stat_t*); 1765 alias lstat64 lstat; 1766 1767 int stat64(const scope char*, stat_t*); 1768 alias stat64 stat; 1769 } 1770 else 1771 { 1772 int fstat(int, stat_t*) @trusted; 1773 int lstat(const scope char*, stat_t*); 1774 int stat(const scope char*, stat_t*); 1775 } 1776 } 1777 else version (Solaris) 1778 { 1779 version (D_LP64) 1780 { 1781 int fstat(int, stat_t*) @trusted; 1782 int lstat(const scope char*, stat_t*); 1783 int stat(const scope char*, stat_t*); 1784 1785 static if (__USE_LARGEFILE64) 1786 { 1787 alias fstat fstat64; 1788 alias lstat lstat64; 1789 alias stat stat64; 1790 } 1791 } 1792 else 1793 { 1794 static if (__USE_LARGEFILE64) 1795 { 1796 int fstat64(int, stat_t*) @trusted; 1797 alias fstat64 fstat; 1798 1799 int lstat64(const scope char*, stat_t*); 1800 alias lstat64 lstat; 1801 1802 int stat64(const scope char*, stat_t*); 1803 alias stat64 stat; 1804 } 1805 else 1806 { 1807 int fstat(int, stat_t*) @trusted; 1808 int lstat(const scope char*, stat_t*); 1809 int stat(const scope char*, stat_t*); 1810 } 1811 } 1812 } 1813 else version (Darwin) 1814 { 1815 // OS X maintains backwards compatibility with older binaries using 32-bit 1816 // inode functions by appending $INODE64 to newer 64-bit inode functions. 1817 version (OSX) 1818 { 1819 version (AArch64) 1820 { 1821 int fstat(int, stat_t*); 1822 int lstat(const scope char*, stat_t*); 1823 int stat(const scope char*, stat_t*); 1824 } 1825 else 1826 { 1827 pragma(mangle, "fstat$INODE64") int fstat(int, stat_t*); 1828 pragma(mangle, "lstat$INODE64") int lstat(const scope char*, stat_t*); 1829 pragma(mangle, "stat$INODE64") int stat(const scope char*, stat_t*); 1830 } 1831 } 1832 else 1833 { 1834 int fstat(int, stat_t*); 1835 int lstat(const scope char*, stat_t*); 1836 int stat(const scope char*, stat_t*); 1837 } 1838 } 1839 else version (FreeBSD) 1840 { 1841 version (GNU) 1842 { 1843 int fstat(int, stat_t*); 1844 int lstat(const scope char*, stat_t*); 1845 int stat(const scope char*, stat_t*); 1846 } 1847 else 1848 { 1849 static if (__FreeBSD_version >= INO64_FIRST) 1850 { 1851 pragma(mangle, "fstat@FBSD_1.5") int fstat(int, stat_t*); 1852 pragma(mangle, "lstat@FBSD_1.5") int lstat(const scope char*, stat_t*); 1853 pragma(mangle, "stat@FBSD_1.5") int stat(const scope char*, stat_t*); 1854 } 1855 else 1856 { 1857 pragma(mangle, "fstat@FBSD_1.0") int fstat(int, stat_t*); 1858 pragma(mangle, "lstat@FBSD_1.0") int lstat(const scope char*, stat_t*); 1859 pragma(mangle, "stat@FBSD_1.0") int stat(const scope char*, stat_t*); 1860 } 1861 } 1862 } 1863 else version (NetBSD) 1864 { 1865 int __fstat50(int, stat_t*); 1866 int __lstat50(const scope char*, stat_t*); 1867 int __stat50(const scope char*, stat_t*); 1868 alias __fstat50 fstat; 1869 alias __lstat50 lstat; 1870 alias __stat50 stat; 1871 } 1872 else version (OpenBSD) 1873 { 1874 int fstat(int, stat_t*); 1875 int lstat(const scope char*, stat_t*); 1876 int stat(const scope char*, stat_t*); 1877 } 1878 else version (DragonFlyBSD) 1879 { 1880 int fstat(int, stat_t*); 1881 int lstat(const scope char*, stat_t*); 1882 int stat(const scope char*, stat_t*); 1883 } 1884 else version (CRuntime_Bionic) 1885 { 1886 int fstat(int, stat_t*) @trusted; 1887 int lstat(const scope char*, stat_t*); 1888 int stat(const scope char*, stat_t*); 1889 } 1890 else version (CRuntime_Musl) 1891 { 1892 pragma(mangle, muslRedirTime64Mangle!("stat", "__stat_time64")) 1893 int stat(const scope char*, stat_t*); 1894 pragma(mangle, muslRedirTime64Mangle!("fstat", "__fstat_time64")) 1895 int fstat(int, stat_t*); 1896 pragma(mangle, muslRedirTime64Mangle!("lstat", "__lstat_time64")) 1897 int lstat(const scope char*, stat_t*); 1898 1899 alias fstat fstat64; 1900 alias lstat lstat64; 1901 alias stat stat64; 1902 } 1903 else version (CRuntime_UClibc) 1904 { 1905 static if ( __USE_LARGEFILE64 ) 1906 { 1907 int fstat64(int, stat_t*) @trusted; 1908 alias fstat64 fstat; 1909 1910 int lstat64(const scope char*, stat_t*); 1911 alias lstat64 lstat; 1912 1913 int stat64(const scope char*, stat_t*); 1914 alias stat64 stat; 1915 } 1916 else 1917 { 1918 int fstat(int, stat_t*) @trusted; 1919 int lstat(const scope char*, stat_t*); 1920 int stat(const scope char*, stat_t*); 1921 } 1922 } 1923 1924 // 1925 // Typed Memory Objects (TYM) 1926 // 1927 /* 1928 S_TYPEISTMO(buf) 1929 */ 1930 1931 // 1932 // XOpen (XSI) 1933 // 1934 /* 1935 S_IFMT 1936 S_IFBLK 1937 S_IFCHR 1938 S_IFIFO 1939 S_IFREG 1940 S_IFDIR 1941 S_IFLNK 1942 S_IFSOCK 1943 */ 1944 1945 version (linux) 1946 { 1947 enum S_IFMT = 0xF000; // octal 0170000 1948 enum S_IFBLK = 0x6000; // octal 0060000 1949 enum S_IFCHR = 0x2000; // octal 0020000 1950 enum S_IFIFO = 0x1000; // octal 0010000 1951 enum S_IFREG = 0x8000; // octal 0100000 1952 enum S_IFDIR = 0x4000; // octal 0040000 1953 enum S_IFLNK = 0xA000; // octal 0120000 1954 enum S_IFSOCK = 0xC000; // octal 0140000 1955 } 1956 else version (Darwin) 1957 { 1958 enum S_IFMT = 0xF000; // octal 0170000 1959 enum S_IFBLK = 0x6000; // octal 0060000 1960 enum S_IFCHR = 0x2000; // octal 0020000 1961 enum S_IFIFO = 0x1000; // octal 0010000 1962 enum S_IFREG = 0x8000; // octal 0100000 1963 enum S_IFDIR = 0x4000; // octal 0040000 1964 enum S_IFLNK = 0xA000; // octal 0120000 1965 enum S_IFSOCK = 0xC000; // octal 0140000 1966 } 1967 else version (FreeBSD) 1968 { 1969 enum S_IFMT = 0xF000; // octal 0170000 1970 enum S_IFBLK = 0x6000; // octal 0060000 1971 enum S_IFCHR = 0x2000; // octal 0020000 1972 enum S_IFIFO = 0x1000; // octal 0010000 1973 enum S_IFREG = 0x8000; // octal 0100000 1974 enum S_IFDIR = 0x4000; // octal 0040000 1975 enum S_IFLNK = 0xA000; // octal 0120000 1976 enum S_IFSOCK = 0xC000; // octal 0140000 1977 } 1978 else version (NetBSD) 1979 { 1980 enum S_IFMT = 0xF000; // octal 0170000 1981 enum S_IFBLK = 0x6000; // octal 0060000 1982 enum S_IFCHR = 0x2000; // octal 0020000 1983 enum S_IFIFO = 0x1000; // octal 0010000 1984 enum S_IFREG = 0x8000; // octal 0100000 1985 enum S_IFDIR = 0x4000; // octal 0040000 1986 enum S_IFLNK = 0xA000; // octal 0120000 1987 enum S_IFSOCK = 0xC000; // octal 0140000 1988 } 1989 else version (OpenBSD) 1990 { 1991 enum S_IFMT = 0xF000; // octal 0170000 1992 enum S_IFBLK = 0x6000; // octal 0060000 1993 enum S_IFCHR = 0x2000; // octal 0020000 1994 enum S_IFIFO = 0x1000; // octal 0010000 1995 enum S_IFREG = 0x8000; // octal 0100000 1996 enum S_IFDIR = 0x4000; // octal 0040000 1997 enum S_IFLNK = 0xA000; // octal 0120000 1998 enum S_IFSOCK = 0xC000; // octal 0140000 1999 } 2000 else version (DragonFlyBSD) 2001 { 2002 enum S_IFMT = 0xF000; // octal 0170000 2003 enum S_IFBLK = 0x6000; // octal 0060000 2004 enum S_IFCHR = 0x2000; // octal 0020000 2005 enum S_IFIFO = 0x1000; // octal 0010000 2006 enum S_IFREG = 0x8000; // octal 0100000 2007 enum S_IFDIR = 0x4000; // octal 0040000 2008 enum S_IFLNK = 0xA000; // octal 0120000 2009 enum S_IFSOCK = 0xC000; // octal 0140000 2010 } 2011 else version (Solaris) 2012 { 2013 enum S_IFMT = 0xF000; 2014 enum S_IFBLK = 0x6000; 2015 enum S_IFCHR = 0x2000; 2016 enum S_IFIFO = 0x1000; 2017 enum S_IFREG = 0x8000; 2018 enum S_IFDIR = 0x4000; 2019 enum S_IFLNK = 0xA000; 2020 enum S_IFSOCK = 0xC000; 2021 enum S_IFDOOR = 0xD000; 2022 enum S_IFPORT = 0xE000; 2023 } 2024 else 2025 { 2026 static assert(false, "Unsupported platform"); 2027 } 2028 2029 /* 2030 int mknod(const scope char*, mode_t, dev_t); 2031 */ 2032 2033 version (CRuntime_Glibc) 2034 { 2035 int mknod(const scope char*, mode_t, dev_t); 2036 } 2037 else version (Darwin) 2038 { 2039 int mknod(const scope char*, mode_t, dev_t); 2040 } 2041 else version (FreeBSD) 2042 { 2043 version (GNU) 2044 { 2045 int mknod(const scope char*, mode_t, dev_t); 2046 } 2047 else 2048 { 2049 static if (__FreeBSD_version >= INO64_FIRST) 2050 pragma(mangle, "mknod@FBSD_1.5") int mknod(const scope char*, mode_t, dev_t); 2051 else 2052 pragma(mangle, "mknod@FBSD_1.0") int mknod(const scope char*, mode_t, dev_t); 2053 } 2054 } 2055 else version (NetBSD) 2056 { 2057 int mknod(const scope char*, mode_t, dev_t); 2058 } 2059 else version (OpenBSD) 2060 { 2061 int mknod(const scope char*, mode_t, dev_t); 2062 } 2063 else version (DragonFlyBSD) 2064 { 2065 int mknod(const scope char*, mode_t, dev_t); 2066 } 2067 else version (Solaris) 2068 { 2069 int mknod(const scope char*, mode_t, dev_t); 2070 } 2071 else version (CRuntime_Bionic) 2072 { 2073 int mknod(const scope char*, mode_t, dev_t); 2074 } 2075 else version (CRuntime_Musl) 2076 { 2077 int mknod(const scope char*, mode_t, dev_t); 2078 } 2079 else version (CRuntime_UClibc) 2080 { 2081 int mknod(const scope char*, mode_t, dev_t); 2082 } 2083 else 2084 { 2085 static assert(false, "Unsupported platform"); 2086 }