Changeset 2935
- Timestamp:
- Dec 30, 2006, 11:41:43 PM (19 years ago)
- Location:
- trunk/libc
- Files:
-
- 3 added
- 1 deleted
- 25 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/Makefile.kmk
r2906 r2935 53 53 $(TARGET_libc_glibc) \ 54 54 $(TARGET_libc_msun) 55 libc_SOURCES.os2 = \56 $(TARGET_libc_libsocket) \57 $(TARGET_libc_libsyslog)55 #libc_SOURCES.os2 = \ 56 # $(TARGET_libc_libsocket) \ 57 # $(TARGET_libc_libsyslog) 58 58 libc_SOURCES.nt = $(TARGET_kNIX.nt) 59 59 … … 66 66 $(TARGET_libc_glibc_l) \ 67 67 $(TARGET_libc_msun_l) 68 libc_frontend_l_SOURCES.os2 = \69 $(TARGET_libc_libsocket_l) \70 $(TARGET_libc_libsyslog_l)68 #libc_frontend_l_SOURCES.os2 = \ 69 # $(TARGET_libc_libsocket_l) \ 70 # $(TARGET_libc_libsyslog_l) 71 71 endif 72 72 … … 79 79 $(TARGET_libc_glibc_p) \ 80 80 $(TARGET_libc_msun_p) 81 libc_frontend_p_SOURCES.os2 = \82 $(TARGET_libc_libsocket_p) \83 $(TARGET_libc_libsyslog_p)81 #libc_frontend_p_SOURCES.os2 = \ 82 # $(TARGET_libc_libsocket_p) \ 83 # $(TARGET_libc_libsyslog_p) 84 84 endif 85 85 … … 103 103 $(TARGET_libc_fbsdlibc_asm_l) \ 104 104 $(TARGET_libc_glibc_asm_l) \ 105 $(TARGET_libc_msun_asm_l) \ 106 $(TARGET_libc_kNIX_asm_l) 105 $(TARGET_libc_msun_asm_l) 107 106 endif 108 107 -
trunk/libc/include/klibc/backend.h
r2932 r2935 167 167 * 168 168 * @returns kLIBC file descriptor number on success. 169 * @returns -1 and errnoon failure.169 * @returns Negative error code (errno.h) on failure. 170 170 * 171 171 * @param hNative The native handle value. … … 173 173 */ 174 174 int __libc_Back_fhImport(intptr_t hNative, int fh); 175 176 /** 177 * Checks that a file handle is valid. 178 * 179 * @returns 0 if it's valid. 180 * @returns Negative error code (errno.h) on failure. 181 * 182 * @param fh The requested file handle. -1 if any will do. 183 */ 184 int __libc_Back_fhValidate(int fh); 175 185 176 186 /** @} */ -
trunk/libc/src/fbsdlibc/gen/Makefile.kmk
r2704 r2935 66 66 $(PATH_LIBC_SRC)/fbsdlibc/gen/setmode.c \ 67 67 $(PATH_LIBC_SRC)/fbsdlibc/gen/setprogname.c \ 68 $(PATH_LIBC_SRC)/fbsdlibc/gen/sleep.c \69 68 $(PATH_LIBC_SRC)/fbsdlibc/gen/srand48.c \ 70 69 $(PATH_LIBC_SRC)/fbsdlibc/gen/statvfs.c \ -
trunk/libc/src/glibc/sysdeps/os2/__spawni.c
r1055 r2935 84 84 85 85 /* find free handle and duplicate fdToSave onto it */ 86 while ( __libc_FH(*pfdMin))86 while (!__libc_Back_fhValidate(*pfdMin)) 87 87 (*pfdMin)++; 88 88 if (*pfdMin >= 0x10000) -
trunk/libc/src/kNIX/Makefile.kmk
r2929 r2935 1 # $Id :$1 # $Id$ 2 2 ## @file 3 3 # … … 36 36 libc_kNIX_SOURCES = \ 37 37 $(PATH_LIBC_SRC)/kNIX/b_fhImport.c \ 38 $(PATH_LIBC_SRC)/kNIX/b_fhValidate.c \ 38 39 $(PATH_LIBC_SRC)/kNIX/b_fsPathResolve.c \ 39 40 $(PATH_LIBC_SRC)/kNIX/b_fsSymlinkModeSet.c \ … … 172 173 $(PATH_LIBC_SRC)/kNIX/os2/386/unwind.s \ 173 174 $(PATH_LIBC_SRC)/kNIX/os2/386/__init_environ.s \ 175 $(PATH_LIBC_SRC)/kNIX/os2/_os2_bad.c \ 174 176 $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \ 175 177 $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c -
trunk/libc/src/kNIX/b_fhImport.c
r2929 r2935 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 3 * … … 45 45 if (!rc) 46 46 __libc_FHPut(pFH); 47 LIBCLOG_MIX_RETURN_INT( -1);47 LIBCLOG_MIX_RETURN_INT(rc); 48 48 } 49 49 -
trunk/libc/src/kNIX/fs.c
r2929 r2935 54 54 * Internal Functions * 55 55 *******************************************************************************/ 56 static uint32_t crc32str(const char *psz);57 #if 058 static uint32_t djb2(const char *str);59 #endif60 static uint32_t sdbm(const char *str);61 56 62 57 … … 169 164 if (psz[1] == ':') 170 165 psz += 2; 171 *pInode = ((uint64_t) crc32str(psz) << 32) | (uint64_t)sdbm(psz);166 *pInode = ((uint64_t)__libc_back_crc32str(psz) << 32) | (uint64_t)__libc_back_sdbm(psz); 172 167 return Dev; 173 168 } … … 217 212 adequately explained. */ 218 213 219 static uint32_tdjb2(const char *str)214 uint32_t __libc_back_djb2(const char *str) 220 215 { 221 216 uint32_t hash = 5381; … … 240 235 this is one of the algorithms used in berkeley db (see sleepycat) and 241 236 elsewhere. */ 242 static uint32_tsdbm(const char *str)237 uint32_t __libc_back_sdbm(const char *str) 243 238 { 244 239 uint32_t hash = 0; … … 345 340 }; 346 341 347 static uint32_t 348 crc32str(const char *psz) 342 uint32_t __libc_back_crc32str(const char *psz) 349 343 { 350 344 const uint8_t *p; -
trunk/libc/src/kNIX/kNIX.h
r2929 r2935 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 3 * … … 233 233 __LIBC_PFSINFO __libc_back_fsInfoObjAddRef(__LIBC_PFSINFO pFsInfo); 234 234 void __libc_back_fsInfoObjRelease(__LIBC_PFSINFO pFsInfo); 235 236 uint32_t __libc_back_djb2(const char *psz); 237 uint32_t __libc_back_sdbm(const char *psz); 238 uint32_t __libc_back_crc32str(const char *psz); 239 235 240 /** @} */ 236 241 -
trunk/libc/src/kNIX/os2/_os2_bad.c
r2925 r2935 1 /* os2bad.c (emx+gcc) */ 1 /* $Id: $ */ 2 /** @file 3 * 4 * kNIX - EMX runtime support (emximp). 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net> 7 * 8 * 9 * This file is part of kLIBC. 10 * 11 * kLIBC is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License as published 13 * by the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * kLIBC is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kLIBC; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 2 26 3 #include "libc-alias.h" 4 #include <stdlib.h> 5 #include <emx/syscalls.h> 27 #include "kNIX.h" 6 28 7 static char msg[] = "\r\nOS/2 API call not fixed up\r\n"; 29 void _os2_bad(void); 30 void _os2_bad(void) 31 { 32 __libc_Back_panic(0, NULL, "An import wasn't resolved!"); 33 } 8 34 9 void _os2_bad (void);10 11 void _os2_bad (void)12 {13 __write (2, msg, sizeof (msg) - 1);14 _exit (2);15 } -
trunk/libc/src/kNIX/os2/b_time.c
r2929 r2935 42 42 { 43 43 struct tm Tm; 44 if (!__libc_gfTZInfoOk) 45 tzset(); 44 46 gmtime_r(&Time, &Tm); 45 47 pTime->twosecs = Tm.tm_sec / 2; … … 68 70 Tm.tm_mon = Date.month ? Date.month - 1 : 0; 69 71 Tm.tm_year = Date.year + 1980 - 1900; 72 if (!__libc_gfTZInfoOk) 73 tzset(); 70 74 time_t UnixTime = mktime(&Tm); LIBC_ASSERT(UnixTime != -1); 71 75 int rc = _loc2gmt(&UnixTime, -1); (void)rc; LIBC_ASSERT(rc != -1); -
trunk/libc/src/kNIX/os2/fhOS2File.c
r2929 r2935 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 3 * … … 955 955 956 956 /** Operations on sockets. */ 957 const __LIBC_FHOPS gOS2FileOps =957 const __LIBC_FHOPS __libc_back_gFileOps = 958 958 { 959 959 enmFH_File, /* Handle type. */ -
trunk/libc/src/kNIX/os2/fs-os2.c
r2929 r2935 1 /* $Id : fs.c 2742 2006-07-26 01:35:40Z bird$ */1 /* $Id$ */ 2 2 /** @file 3 3 * … … 48 48 * Global Variables * 49 49 *******************************************************************************/ 50 ULONG (* _System __libc_gpfnDosOpenL)(PCSZ pszFileName, PHFILE phFile, PULONG pulAction, LONGLONG llFileSize, ULONG ulAttribute, ULONG ulOpenFlags, ULONG ulOpenMode, PEAOP2 pEABuf) = NULL; 51 ULONG (* _System __libc_gpfnDosSetFilePtrL)(HFILE hFile, LONGLONG llOffset, ULONG ulOrigin, PLONGLONG pllPos) = NULL; 52 ULONG (* _System __libc_gpfnDosSetFileSizeL)(HFILE hFile, LONGLONG cbSize) = NULL; 53 ULONG (* _System __libc_gpfnDosSetFileLocksL)(HFILE hFile, __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock, ULONG ulTimeout, ULONG flFlags) = NULL; 54 55 /** Symlink EA name. */ 56 static const char __libc_gszSymlinkEA[] = EA_SYMLINK; 57 /** UID EA name. */ 58 static const char __libc_gszUidEA[] = EA_UID; 59 /** GID EA name. */ 60 static const char __libc_gszGidEA[] = EA_GID; 61 /** Mode EA name. */ 62 static const char __libc_gszModeEA[] = EA_MODE; 63 /** Ino EA name. */ 64 static const char __libc_gszInoEA[] = EA_INO; 65 /** RDev EA name. */ 66 static const char __libc_gszRDevEA[] = EA_RDEV; 67 /** Gen(eration) EA name. */ 68 static const char __libc_gszGenEA[] = EA_GEN; 69 /** User flags EA name. */ 70 static const char __libc_gszFlagsEA[] = EA_FLAGS; 71 72 /** 73 * The prefilled GEA2LIST construct for querying a symlink. 74 */ 75 #pragma pack(1) 76 static const struct 77 { 78 ULONG cbList; 79 ULONG oNextEntryOffset; 80 BYTE cbName; 81 CHAR szName[sizeof(EA_SYMLINK)]; 82 } gGEA2ListSymlink = 83 { 84 sizeof(gGEA2ListSymlink), 85 0, 86 sizeof(EA_SYMLINK) - 1, 87 EA_SYMLINK 88 }; 89 #pragma pack() 90 91 /** 92 * The prefilled GEA2LIST construct for querying all unix attributes. 93 */ 94 const struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST __libc_gFsUnixAttribsGEA2List = 95 { 96 #define OFF(a,b) offsetof(struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST, a) - offsetof(struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST, b) 97 sizeof(__libc_gFsUnixAttribsGEA2List), 98 OFF(offUID, offSymlink), sizeof(EA_SYMLINK) - 1, EA_SYMLINK, 99 OFF(offGID, offUID), sizeof(EA_UID) - 1, EA_UID, 100 OFF(offMode, offGID), sizeof(EA_GID) - 1, EA_GID, 101 OFF(offINO, offMode), sizeof(EA_MODE) - 1, EA_MODE, 102 OFF(offRDev, offINO), sizeof(EA_INO) - 1, EA_INO, 103 OFF(offGen, offRDev), sizeof(EA_RDEV) - 1, EA_RDEV, 104 OFF(offFlags, offGen), sizeof(EA_GEN) - 1, EA_GEN, 105 0, sizeof(EA_FLAGS) - 1, EA_FLAGS 106 #undef OFF 107 }; 108 #pragma pack() 109 110 /** 111 * The prefilled GEA2LIST construct for querying all the mode attribute. 112 */ 113 #pragma pack(1) 114 static const struct 115 { 116 ULONG cbList; 117 ULONG oNextEntryOffset; 118 BYTE cbName; 119 CHAR szName[sizeof(EA_MODE)]; 120 } gGEA2ListMode = 121 { 122 sizeof(gGEA2ListMode), 123 0, 124 sizeof(EA_MODE) - 1, 125 EA_MODE 126 }; 127 #pragma pack() 128 129 /** 130 * The prefilled FEA2LIST construct for setting all attributes during a creation operation. 131 */ 132 #pragma pack(1) 133 const struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST __libc_gFsUnixAttribsCreateFEA2List = 134 { 135 #define OFF(a,b) offsetof(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST, a) - offsetof(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST, b) 136 sizeof(__libc_gFsUnixAttribsCreateFEA2List), 137 OFF(offGID, offUID), FEA_NEEDEA, sizeof(EA_UID) - 1, sizeof(uint32_t) + 4, EA_UID, EAT_BINARY, sizeof(uint32_t), 0, "", 138 OFF(offMode, offGID), FEA_NEEDEA, sizeof(EA_GID) - 1, sizeof(uint32_t) + 4, EA_GID, EAT_BINARY, sizeof(uint32_t), 0, "", 139 OFF(offINO, offMode), FEA_NEEDEA, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), 0, "", 140 OFF(offRDev, offINO), FEA_NEEDEA, sizeof(EA_INO) - 1, sizeof(uint64_t) + 4, EA_INO, EAT_BINARY, sizeof(uint64_t), 0, "", 141 OFF(offGen, offRDev), FEA_NEEDEA, sizeof(EA_RDEV) - 1, sizeof(uint32_t) + 4, EA_RDEV, EAT_BINARY, sizeof(uint32_t), 0, "", 142 OFF(offFlags, offGen), FEA_NEEDEA, sizeof(EA_GEN) - 1, sizeof(uint32_t) + 4, EA_GEN, EAT_BINARY, sizeof(uint32_t), 0, "", 143 0, FEA_NEEDEA, sizeof(EA_FLAGS) - 1, sizeof(uint32_t) + 4, EA_FLAGS, EAT_BINARY, sizeof(uint32_t), 0, "" 144 #undef OFF 145 }; 146 #pragma pack() 147 148 /** 149 * The prefilled GEA2LIST construct for querying unix attributes for directory listing. 150 */ 151 const struct __LIBC_BACK_FSUNIXATTRIBSDIRGEA2LIST __libc_gFsUnixAttribsDirGEA2List = 152 { 153 #define OFF(a,b) offsetof(struct __LIBC_BACK_FSUNIXATTRIBSDIRGEA2LIST, a) - offsetof(struct __LIBC_BACK_FSUNIXATTRIBSDIRGEA2LIST, b) 154 sizeof(__libc_gFsUnixAttribsDirGEA2List), 155 OFF(offINO, offMode), sizeof(EA_MODE) - 1, EA_MODE, 156 0, sizeof(EA_INO) - 1, EA_INO, 157 #undef OFF 158 }; 159 #pragma pack() 160 50 161 /** 51 162 * The special /@unixroot rewrite rule. … … 55 166 __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR, "/@unixroot", 10, __libc_gszUnixRoot, 0 56 167 }; 57 58 168 59 169 /** Array of pointers to fs info objects for all … … 68 178 * Internal Functions * 69 179 *******************************************************************************/ 180 static int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree); 181 static int fsIsSymlink(const char *pszNativePath); 70 182 71 183 … … 413 525 } 414 526 527 528 /** 529 * Cleans up a path specifier a little bit. 530 * This includes removing duplicate slashes, uncessary single dots, and 531 * trailing slashes. 532 * 533 * @returns Number of bytes in the clean path. 534 * @param pszPath The path to cleanup. 535 * @param fFlags Flags controlling the operation of the function. 536 * See the BACKFS_FLAGS_* defines. 537 * @param pfFlags Where to clear the BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ flag if a 538 * trailing slash was found. 539 */ 540 static int fsCleanPath(char *pszPath, unsigned fFlags, unsigned *pfFlags) 541 { 542 /* 543 * Change to '/' and remove duplicates. 544 */ 545 int fUnc = 0; 546 char *pszSrc = pszPath; 547 char *pszTrg = pszPath; 548 if ( (pszPath[0] == '\\' || pszPath[0] == '/') 549 && (pszPath[1] == '\\' || pszPath[1] == '/') 550 && pszPath[2] != '\\' && pszPath[2] != '/') 551 { /* Skip first slash in a unc path. */ 552 pszSrc++; 553 *pszTrg++ = '/'; 554 fUnc = 1; 555 } 556 557 for (;;) 558 { 559 char ch = *pszSrc++; 560 if (ch == '/' || ch == '\\') 561 { 562 *pszTrg++ = '/'; 563 for (;;) 564 { 565 do ch = *pszSrc++; 566 while (ch == '/' || ch == '\\'); 567 568 /* Remove '/./' and '/.'. */ 569 if (ch != '.' || (*pszSrc && *pszSrc != '/' && *pszSrc != '\\')) 570 break; 571 } 572 } 573 *pszTrg = ch; 574 if (!ch) 575 break; 576 pszTrg++; 577 } 578 579 /* 580 * Remove trailing slash if the path may be pointing to a directory. 581 * A symlink search is converted to a directory search if this is encountered. 582 */ 583 int cch = pszTrg - pszPath; 584 if ( (fFlags & (BACKFS_FLAGS_RESOLVE_DIR | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)) 585 && cch > 1 586 && pszTrg[-1] == '/' 587 && pszTrg[-2] != ':' 588 && pszTrg[-2] != '/') 589 { 590 pszPath[--cch] = '\0'; 591 if (pfFlags) 592 { 593 *pfFlags &= ~(BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK); 594 if (fFlags & BACKFS_FLAGS_RESOLVE_FULL_SYMLINK) 595 *pfFlags |= BACKFS_FLAGS_RESOLVE_DIR | BACKFS_FLAGS_RESOLVE_FULL; 596 } 597 } 598 599 return cch; 600 } 601 602 603 /** 604 * Resolves and verifies the user path to a native path. 605 * 606 * @returns 0 on success. 607 * @returns Negative error code (errno.h) on failiure. 608 * @param pszUserPath The user path. 609 * @parm fFlags Flags controlling the operation of the function. 610 * See the BACKFS_FLAGS_* defines. 611 * @param pszNativePath Where to store the native path. This buffer is at 612 * least PATH_MAX bytes big. 613 * @param pfInUnixTree Where to store the result-in-unix-tree indicator. Optional. 614 */ 615 int __libc_back_fsResolve(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree) 616 { 617 if (pszUserPath && *pszUserPath) 618 return fsResolveUnix(pszUserPath, fFlags, pszNativePath, pfInUnixTree); 619 620 /* failure */ 621 *pszNativePath = '\0'; 622 if (pfInUnixTree) 623 *pfInUnixTree = 0; 624 625 LIBC_ASSERT(pszUserPath); 626 if (!pszUserPath) 627 return -EINVAL; 628 return -ENOENT; 629 } 630 631 632 /** 633 * Resolves and verifies the user path to a native path. 634 * 635 * @returns 0 on success. 636 * @returns Negative error code (errno.h) on failiure. 637 * @param pszUserPath The user path. 638 * @parm fFlags Flags controlling the operation of the function. 639 * See the BACKFS_FLAGS_* defines. 640 * @param pszNativePath Where to store the native path. This buffer is at 641 * least PATH_MAX bytes big. 642 * @param pfInUnixTree Where to store the result-in-unix-tree indicator. Optional. 643 */ 644 static int fsResolveUnix(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree) 645 { 646 LIBCLOG_ENTER("pszUserPath=%p:{%s} pszNativePath=%p *pfInUnixTree=%p\n", 647 (void *)pszUserPath, pszUserPath, (void *)pszNativePath, (void *)pfInUnixTree); 648 const char *pszUserPathIn = pszUserPath; 649 char _achBuffer[SIZEOF_ACHBUFFER + 4]; 650 char *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3); 651 unsigned cLoopsLeft = 8; 652 int fInUnixTree = __libc_gfInUnixTree; 653 int rcRet = 0; 654 HDIR hDir = HDIR_CREATE; 655 __LIBC_PFSINFO pFsInfo = NULL; 656 int fUnixEAs; 657 FS_VAR() 658 FS_SAVE_LOAD(); 659 for (;;) 660 { 661 /* 662 * Determin root slash position. 663 */ 664 int iRoot; 665 if (pszUserPath[0] == '/' || pszUserPath[0] == '\\') 666 { 667 iRoot = 0; 668 fInUnixTree = __libc_gfInUnixTree; 669 } 670 else if ( pszUserPath[0] && pszUserPath[1] == ':' 671 && (pszUserPath[2] == '/' || pszUserPath[2] == '\\')) 672 { 673 iRoot = 2; 674 fInUnixTree = 0; 675 } 676 /* 677 * No root slash? Make one! 678 * This can only happen in the first pass (unless something BAD happens of course). 679 */ 680 else 681 { 682 ULONG ul; 683 int rc; 684 if (pszUserPath[1] != ':') 685 { 686 /* 687 * Current drive. 688 */ 689 ULONG ulDisk; 690 rc = DosQueryCurrentDisk(&ulDisk, &ul); 691 pszNativePath[0] = ulDisk + 'A' - 1; 692 ul = PATH_MAX - 2; 693 if (!rc) 694 rc = DosQueryCurrentDir(0, (PSZ)&pszNativePath[3], &ul); 695 iRoot = __libc_gfInUnixTree ? __libc_gcchUnixRoot : 2; 696 /* fInUnixTree remains whatever it is */ 697 } 698 else 699 { 700 /* 701 * Drive letter but no root slash. 702 */ 703 pszNativePath[0] = pszUserPath[0]; 704 ul = PATH_MAX - 2; 705 rc = DosQueryCurrentDir(pszUserPath[0] - (pszUserPath[0] >= 'A' && pszUserPath[0] <= 'Z' ? 'A' : 'a') + 1, (PSZ)&pszNativePath[3], &ul); 706 pszUserPath += 2; 707 iRoot = 2; 708 fInUnixTree = 0; 709 } 710 /* failed? */ 711 if (rc) 712 { 713 rcRet = -__libc_back_native2errno(rc); 714 break; 715 } 716 717 /* 718 * Add the path stuff from the user. 719 */ 720 pszNativePath[1] = ':'; 721 pszNativePath[2] = '/'; 722 int cch = strlen(pszNativePath); 723 pszNativePath[cch++] = '/'; 724 int cchUserPath = strlen(pszUserPath) + 1; 725 if (cch + cchUserPath > PATH_MAX) 726 { 727 rcRet = -ENAMETOOLONG; 728 break; 729 } 730 memcpy(&pszNativePath[cch], pszUserPath, cchUserPath); 731 pszUserPath = memcpy(pachBuffer, pszNativePath, cch + cchUserPath); 732 } 733 734 /* 735 * Verify any drive specifier. 736 */ 737 if (pszUserPath[1] == ':') 738 { 739 if (*pszUserPath >= 'a' && *pszUserPath <= 'z') 740 { 741 if ((uintptr_t)(pszUserPath - pachBuffer) > SIZEOF_ACHBUFFER) 742 pszUserPath = strcpy(pachBuffer, pszUserPath); 743 *(char *)(void *)pszUserPath += 'A' - 'a'; 744 } 745 else if (!(*pszUserPath >= 'A' && *pszUserPath <= 'Z')) 746 { 747 rcRet = -ENOENT; 748 break; 749 } 750 } 751 752 /* 753 * Apply rewrite rules. 754 * Path now goes to pszNativePath buffer. 755 */ 756 int cchNativePath = __libc_PathRewrite(pszUserPath, pszNativePath, PATH_MAX); 757 if (cchNativePath > 0) 758 { 759 /* 760 * Redetermin root because of rewrite. 761 */ 762 iRoot = pszNativePath[1] == ':' ? 2 : 0; 763 } 764 else if (!cchNativePath) 765 { 766 cchNativePath = strlen(pszUserPath); 767 if (cchNativePath + 2 > PATH_MAX) 768 { 769 rcRet = -ENAMETOOLONG; 770 break; 771 } 772 memcpy(pszNativePath, pszUserPath, cchNativePath + 1); 773 } 774 else 775 { 776 rcRet = -EINVAL; 777 break; 778 } 779 780 /* 781 * Check if special OS/2 name. 782 */ 783 if (pszNativePath[0] == '/' || pszNativePath[0] == '\\') 784 { 785 int fDone = 0; 786 if ( (pszNativePath[1] == 'p' || pszNativePath[1] == 'P') 787 && (pszNativePath[2] == 'i' || pszNativePath[2] == 'I') 788 && (pszNativePath[3] == 'p' || pszNativePath[3] == 'P') 789 && (pszNativePath[4] == 'e' || pszNativePath[4] == 'E') 790 && (pszNativePath[5] == '/' || pszNativePath[5] == '\\')) 791 fDone = 1; 792 else if ((pszNativePath[1]== 'd' || pszNativePath[1] == 'D') 793 && (pszNativePath[2] == 'e' || pszNativePath[2] == 'E') 794 && (pszNativePath[3] == 'v' || pszNativePath[3] == 'V') 795 && (pszNativePath[4] == '/' || pszNativePath[4] == '\\') 796 ) 797 { 798 PFSQBUFFER2 pfsqb = (PFSQBUFFER2)pachBuffer; 799 ULONG cb = SIZEOF_ACHBUFFER; 800 fDone = !DosQueryFSAttach((PCSZ)pszNativePath, 0, FSAIL_QUERYNAME, pfsqb, &cb); 801 } 802 803 /* If it was, copy path to pszNativePath and go to exit code. */ 804 if (fDone) 805 { 806 int cch = strlen(pszNativePath) + 1; 807 if (cch <= PATH_MAX) 808 { 809 fsCleanPath(pszNativePath, fFlags, NULL); 810 rcRet = 0; 811 } 812 else 813 rcRet = -ENAMETOOLONG; 814 break; 815 } 816 } 817 818 /* 819 * Remove excessive slashing and convert all slashes to '/'. 820 */ 821 cchNativePath = fsCleanPath(pszNativePath, fFlags, &fFlags); 822 823 /* 824 * Expand unix root or add missing drive letter. 825 */ 826 if (pszNativePath[0] == '/' && pszNativePath[1] != '/') 827 { 828 memcpy(pachBuffer, pszNativePath, cchNativePath + 1); 829 if (__libc_gcchUnixRoot) 830 { 831 iRoot = __libc_gcchUnixRoot; 832 if (cchNativePath + iRoot >= PATH_MAX) 833 { 834 rcRet = -ENAMETOOLONG; 835 break; 836 } 837 memcpy(pszNativePath, __libc_gszUnixRoot, iRoot); 838 fInUnixTree = 1; 839 } 840 else 841 { 842 iRoot = 2; 843 ULONG ulDisk = 0; 844 ULONG ul; 845 DosQueryCurrentDisk(&ulDisk, &ul); 846 if (cchNativePath + iRoot >= PATH_MAX) 847 { 848 rcRet = -ENAMETOOLONG; 849 break; 850 } 851 pszNativePath[0] = ulDisk + 'A' - 1; 852 pszNativePath[1] = ':'; 853 } 854 if (cchNativePath != 1 || iRoot <= 2) 855 memcpy(&pszNativePath[iRoot], pachBuffer, cchNativePath + 1); 856 else 857 pszNativePath[iRoot] = pszNativePath[iRoot + 1] = '\0'; /* The +1 fixes '/' access in an compartement (pszPrev below). */ 858 cchNativePath += iRoot; 859 } 860 861 862 /* 863 * Check all directory components. 864 * 865 * We actually don't bother checking if they're directories, only that 866 * they exists. This shouldn't matter much since any operation on the 867 * next/final component will assume the previous one being a directory. 868 * 869 * While walking we will clean up all use of '.' and '..' so we'll end 870 * up with an optimal path in the end. 871 */ 872 /** @todo If we've retreived the current directory, we can safely save of the effort of validating it! */ 873 874 /* 875 * Find the end of the first component (start and end + 1). 876 */ 877 char *pszPrev; 878 char *psz; 879 if (pszNativePath[0] == '/' && pszNativePath[1] == '/' && pszNativePath[2] != '/') 880 { 881 /* UNC - skip past the share name. */ 882 psz = strchr(&pszNativePath[2], '/'); 883 if (!psz) 884 { 885 rcRet = -ENOENT; 886 break; 887 } 888 psz = strchr(psz + 1, '/'); 889 if (!psz) 890 { 891 strupr(pszNativePath); /* The server + share is uppercased for consistant ino_t calculations. */ 892 rcRet = 0; 893 break; 894 } 895 *psz = '\0'; /* The server + share is uppercased for consistant ino_t calculations. */ 896 strupr(pszNativePath); 897 *psz = '/'; 898 pszPrev = ++psz; 899 fInUnixTree = 0; /* Unix root cannot be UNC. */ 900 iRoot = psz - pszNativePath; 901 psz = strchr(psz, '/'); 902 903 /* We don't do UNIX EAs on UNCs */ 904 fUnixEAs = 0; 905 } 906 else 907 { 908 /* drive letters are always uppercase! (inode dev number req) */ 909 LIBC_ASSERT(pszNativePath[1] == ':'); 910 if (pszNativePath[0] >= 'a' && pszNativePath[0] <= 'z') 911 pszNativePath[0] -= 'a' - 'A'; 912 pszPrev = &pszNativePath[iRoot + 1]; 913 psz = strchr(pszPrev, '/'); 914 915 /* Unix EAs? */ 916 pFsInfo = __libc_back_fsInfoObjByPathCached(pszNativePath, pFsInfo); 917 LIBC_ASSERTM(pFsInfo, "%s\n", pszNativePath); 918 fUnixEAs = pFsInfo ? pFsInfo->fUnixEAs : 0; 919 } 920 LIBC_ASSERTM(pszPrev - pszNativePath >= iRoot, "iRoot=%d pszPrev offset %d pszNativePath=%s\n", iRoot, pszPrev - pszNativePath, pszNativePath); 921 /* If only one component, we'll check if the fVerifyLast was requested. */ 922 if ( !psz 923 && (fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)) 924 && *pszPrev) 925 psz = strchr(pszNativePath, '\0'); 926 927 /* 928 * Walking loop. 929 */ 930 int fDone = 1; 931 while (psz) 932 { 933 char chSlash = *psz; 934 *psz = '\0'; 935 936 /* 937 * Kill . and .. specs. 938 */ 939 if ( pszPrev[0] == '.' 940 && ( pszPrev[1] == '\0' 941 || (pszPrev[1] == '.' && pszPrev[2] == '\0') ) ) 942 { 943 if ( pszPrev[1] != '\0' 944 && (uintptr_t)(pszPrev - pszNativePath) != iRoot + 1) 945 { 946 for (pszPrev -= 2; *pszPrev != '/'; pszPrev--) 947 /* noop */; 948 pszPrev++; 949 } 950 *psz = chSlash; 951 memmove(pszPrev - 1, psz, cchNativePath - (psz - pszNativePath) + 1); 952 cchNativePath -= psz - (pszPrev - 1); 953 954 /* 955 * Next path component and restart loop. 956 */ 957 if (!chSlash) 958 { 959 rcRet = 0; 960 break; 961 } 962 psz = pszPrev; 963 while (*psz != '/') 964 { 965 if (*psz) 966 psz++; 967 else 968 { 969 if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK))) 970 { 971 rcRet = 0; 972 psz = NULL; 973 } 974 break; 975 } 976 } 977 continue; 978 } 979 980 /* 981 * Check for obviously illegal characters in this path component 982 * saving us from having DosFindFirst getting '*' and '?'. 983 */ 984 if (strpbrk(pszPrev, "*?")) 985 { 986 rcRet = -ENOENT; /* hmm. will this be correct for all situation? */ 987 break; 988 } 989 990 /* 991 * Find the correct name and to check if it is a directory or not. 992 * This'll of course also provide proper verification of the path too. :-) 993 * 994 * This is a little bit messed up since we'll have to use wildcard for 995 * getting the casing resolved. 996 * 997 * The two find buffers are assumed to be equal down thru attrFile. 998 */ 999 //LIBC_ASSERT(psz - pszNativePath == cchNativePath); - figure this one. 1000 PFILEFINDBUF4 pFindBuf4 = (PFILEFINDBUF4)pachBuffer; 1001 PFILEFINDBUF3 pFindBuf3 = (PFILEFINDBUF3)pachBuffer; 1002 ULONG cFiles = 1; 1003 char chNext = psz[1]; 1004 psz[0] = '?'; 1005 psz[1] = '\0'; 1006 int rc = DosFindFirst((PCSZ)pszNativePath, &hDir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED, 1007 pachBuffer, SIZEOF_ACHBUFFER, &cFiles, fUnixEAs ? FIL_QUERYEASIZE : FIL_STANDARD); 1008 psz[0] = '\0'; 1009 psz[1] = chNext; 1010 if (rc || cFiles == 0) 1011 hDir = HDIR_CREATE; 1012 while (!rc && cFiles == 1 && (fUnixEAs ? pFindBuf4->cchName : pFindBuf3->cchName) != psz - pszPrev) 1013 rc = DosFindNext(hDir, pachBuffer, SIZEOF_ACHBUFFER, &cFiles); 1014 if (rc || cFiles == 0) 1015 { 1016 LIBCLOG_MSG("DosFindFirst/Next('%s',,,,,) -> %d resolving '%s'\n", pszNativePath, rc, pszUserPathIn); 1017 if ((fFlags & BACKFS_FLAGS_RESOLVE_FULL_MAYBE_) && !chSlash) 1018 { 1019 *psz = chSlash; 1020 rcRet = 0; 1021 } 1022 else 1023 rcRet = rc == ERROR_FILE_NOT_FOUND && chSlash ? -ENOENT : -__libc_back_native2errno(rc); 1024 break; 1025 } 1026 memcpy(pszPrev, fUnixEAs ? pFindBuf4->achName : pFindBuf3->achName, psz - pszPrev); 1027 int fIsDirectory = (pFindBuf4->attrFile & FILE_DIRECTORY) != 0; 1028 1029 /* 1030 * Try querying the symlink EA value. 1031 * (This operation will reuse the achBuffer overwriting the pFindBuf[3/4] data!) 1032 * 1033 * Yeah, we could do this in the same operation as the DosFindFirst() but 1034 * a little bird told me that level 3 DosFindFirst request had not been 1035 * returning the right things at some point, and besides it's return data 1036 * is rather clumsily laid out. So, I decided not to try my luck on it. 1037 * 1038 * On second thought, we seems to end up having to use DosFindFirst in some 1039 * cases anyway... very nice. 1040 */ 1041 if ( fUnixEAs 1042 && pFindBuf4->cbList > sizeof(USHORT) * 2 + 1 1043 && ( (fFlags & BACKFS_FLAGS_RESOLVE_FULL) 1044 || chSlash) 1045 && !fIsDirectory) 1046 { 1047 PEAOP2 pEaOp2 = (PEAOP2)pachBuffer; 1048 pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListSymlink; 1049 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1050 pEaOp2->oError = 0; 1051 pEaOp2->fpFEA2List->cbList = SIZEOF_ACHBUFFER - sizeof(*pEaOp2); 1052 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(*pEaOp2)); 1053 if (rc) 1054 { 1055 cFiles = 1; 1056 pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListSymlink; 1057 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1058 pEaOp2->oError = 0; 1059 pEaOp2->fpFEA2List->cbList = SIZEOF_ACHBUFFER - sizeof(*pEaOp2); 1060 rc = DosFindFirst((PCSZ)pszNativePath, &hDir, 0, pEaOp2, pEaOp2->fpFEA2List->cbList + sizeof(*pEaOp2), &cFiles, FIL_QUERYEASFROMLIST); 1061 if (rc || cFiles == 0) 1062 { 1063 hDir = HDIR_CREATE; 1064 LIBCLOG_MSG("DosFindFirst('%s',,,pEaOp2,) -> %d resolving '%s'\n", pszNativePath, rc, pszUserPathIn); 1065 if ((fFlags & BACKFS_FLAGS_RESOLVE_FULL_MAYBE_) && !chSlash) 1066 rcRet = 0; 1067 else 1068 rcRet = rc == ERROR_FILE_NOT_FOUND && chSlash ? -ENOENT : -__libc_back_native2errno(rc); 1069 break; 1070 } 1071 pEaOp2->fpFEA2List = (PFEA2LIST)((char *)pEaOp2 + sizeof(EAOP2) + offsetof(FILEFINDBUF3, cchName)); 1072 } 1073 1074 /* 1075 * Did we find any symlink EA? 1076 */ 1077 if ( pEaOp2->fpFEA2List->cbList > sizeof(pEaOp2->fpFEA2List->list[0]) 1078 && pEaOp2->fpFEA2List->list[0].cbValue) 1079 { 1080 /* Validate the EA. */ 1081 PUSHORT pusType = (PUSHORT)((char *)&pEaOp2->fpFEA2List->list[1] + pEaOp2->fpFEA2List->list[0].cbName); 1082 char *pszSymlink = (char *)&pusType[2]; 1083 if ( pusType[0] != EAT_ASCII 1084 || pusType[1] > pEaOp2->fpFEA2List->list[0].cbValue 1085 || !pusType[1] 1086 || !*pszSymlink) 1087 { 1088 LIBCLOG_ERROR("Invalid symlink EA! type=%x len=%d cbValue=%d *pszSymlink=%c\n", 1089 pusType[0], pusType[1], pEaOp2->fpFEA2List->list[0].cbValue, *pszSymlink); 1090 rcRet = -EFTYPE; 1091 break; 1092 } 1093 1094 /* Check if we've reached the max number of symlink loops before we continue. */ 1095 if (cLoopsLeft-- <= 0) 1096 { 1097 rcRet = -ELOOP; 1098 break; 1099 } 1100 1101 /* Cleanup the symlink and find it's length. */ 1102 pszSymlink[pusType[1]] = '\0'; 1103 int cchSymlink = fsCleanPath(pszSymlink, fFlags, NULL); 1104 1105 /* Merge the symlink with the path. */ 1106 int cchLeft = cchNativePath - (psz - pszNativePath); 1107 if (*pszSymlink == '/' || *pszSymlink == '\\' || pszSymlink[1] == ':') 1108 { 1109 /* 1110 * Replace the path up to the current point with the symlink, 1111 */ 1112 if (cchSymlink + cchLeft + 2 >= PATH_MAX) 1113 { 1114 rcRet = -ENAMETOOLONG; 1115 break; 1116 } 1117 if (cchLeft) 1118 { 1119 if (pszSymlink[cchSymlink - 1] != '/') 1120 pszSymlink[cchSymlink++] = '/'; 1121 memcpy(&pszSymlink[cchSymlink], psz + 1, cchLeft + 1); 1122 } 1123 1124 /* restart the whole shebang. */ 1125 pszUserPath = pszSymlink; 1126 fDone = 0; 1127 break; 1128 } 1129 else 1130 { 1131 /* 1132 * Squeeze the symlink in instead of the current path component. 1133 */ 1134 if (cchSymlink + cchNativePath + 2 >= PATH_MAX) 1135 { 1136 rcRet = -ENAMETOOLONG; 1137 break; 1138 } 1139 if (cchLeft) 1140 { 1141 pszSymlink[cchSymlink++] = '/'; 1142 memcpy(&pszSymlink[cchSymlink], psz + 1, cchLeft + 1); 1143 cchSymlink += cchLeft; 1144 } 1145 memcpy(pszPrev, pszSymlink, cchSymlink + 1); 1146 cchNativePath += cchSymlink - (psz - pszPrev); 1147 1148 /* restart this component. */ 1149 psz = pszPrev; 1150 while (*psz != '/') 1151 { 1152 if (*psz) 1153 psz++; 1154 else 1155 { 1156 if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK))) 1157 { 1158 rcRet = 0; 1159 psz = NULL; 1160 } 1161 break; 1162 } 1163 } 1164 continue; 1165 } 1166 } 1167 } 1168 1169 /* 1170 * If we get here it was not a symlink and we should check how the directoryness 1171 * of it fit's into the big picture... 1172 */ 1173 if (!fIsDirectory && chSlash) 1174 { 1175 LIBCLOG_ERROR("'%s' is not a directory (resolving '%s')\n", pszNativePath, pszUserPathIn); 1176 rcRet = -ENOTDIR; 1177 break; 1178 } 1179 1180 /* 1181 * Next path component. 1182 */ 1183 *psz++ = chSlash; 1184 if (!chSlash) 1185 { 1186 rcRet = 0; 1187 if ( (fFlags & (BACKFS_FLAGS_RESOLVE_DIR | BACKFS_FLAGS_RESOLVE_DIR_MAYBE_)) == BACKFS_FLAGS_RESOLVE_DIR 1188 && !fIsDirectory 1189 && ( !fUnixEAs 1190 || pFindBuf4->cbList <= sizeof(USHORT) * 2 + 1 1191 || !fsIsSymlink(pszNativePath))) 1192 rcRet = -ENOTDIR; 1193 break; 1194 } 1195 pszPrev = psz; 1196 while (*psz != '/') 1197 { 1198 if (!*psz) 1199 { 1200 if (!(fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK))) 1201 { 1202 rcRet = 0; 1203 psz = NULL; 1204 } 1205 break; 1206 } 1207 psz++; 1208 } 1209 } /* inner loop */ 1210 1211 if (fDone) 1212 break; 1213 } /* outer loop */ 1214 1215 /* 1216 * Cleanup find handle and fs object. 1217 */ 1218 if (hDir != HDIR_CREATE) 1219 DosFindClose(hDir); 1220 if (pFsInfo) 1221 __libc_back_fsInfoObjRelease(pFsInfo); 1222 FS_RESTORE(); 1223 1224 /* 1225 * Copy the resolved path the the caller buffer. 1226 */ 1227 if (pfInUnixTree) 1228 *pfInUnixTree = fInUnixTree; 1229 if (!rcRet) 1230 { 1231 int cch = strlen(pszNativePath) + 1; 1232 if (cch == 1 || (cch == 3 && pszNativePath[1] == ':')) 1233 { 1234 pszNativePath[cch - 1] = '/'; 1235 pszNativePath[cch] = '\0'; 1236 } 1237 LIBCLOG_RETURN_MSG(0, "ret 0 pszNativePath=%p:{%s}\n", (void *)pszNativePath, pszNativePath); 1238 } 1239 1240 /* failure */ 1241 LIBCLOG_ERROR_RETURN_MSG(rcRet, "ret %d pszNativePath=%p:{%s}\n", rcRet, (void *)pszNativePath, pszNativePath); 1242 pszUserPathIn = pszUserPathIn; 1243 } 1244 1245 1246 /** 1247 * Initializes a unix attribute structure before creating a new inode. 1248 * The call must have assigned default values to the the structure before doing this call! 1249 * 1250 * @returns Device number. 1251 * @param pFEas The attribute structure to fill with actual values. 1252 * @param pszNativePath The native path, used to calculate the inode number. 1253 * @param Mode The correct mode (the caller have fixed this!). 1254 */ 1255 dev_t __libc_back_fsUnixAttribsInit(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas, char *pszNativePath, mode_t Mode) 1256 { 1257 /* 1258 * Calc Inode number. 1259 * We replace the lower 32-bit with a random value. 1260 */ 1261 /* low 32-bit - random */ 1262 static union 1263 { 1264 uint64_t u64TSC; 1265 unsigned short ausSeed[4]; 1266 } s_Seed = {0}; 1267 static _smutex s_smtxSeed = 0; 1268 _smutex_request(&s_smtxSeed); 1269 /* seed it ? */ 1270 if (!s_Seed.ausSeed[3]) 1271 { 1272 __asm__ __volatile__ ("rdtsc" : "=A" (s_Seed.u64TSC)); 1273 s_Seed.ausSeed[3] = 1; 1274 } 1275 pFEas->u64INO = nrand48(&s_Seed.ausSeed[0]) & 0xffffffff; 1276 _smutex_release(&s_smtxSeed); 1277 1278 /* high 32-bit - crc32 */ 1279 const char *psz = pszNativePath; 1280 if (psz[1] == ':') 1281 psz += 2; 1282 pFEas->u64INO |= (uint64_t)__libc_back_crc32str(psz) << 32; 1283 1284 /* 1285 * The other stuff. 1286 */ 1287 pFEas->u32UID = __libc_spmGetId(__LIBC_SPMID_EUID); 1288 pFEas->u32GID = __libc_spmGetId(__LIBC_SPMID_EGID); /** @todo sticky bit! */ 1289 pFEas->u32Mode = Mode; 1290 LIBC_ASSERT(pFEas->u32RDev == 0); 1291 LIBC_ASSERT(pFEas->u32Gen == 0); 1292 LIBC_ASSERT(pFEas->u32Flags == 0); 1293 1294 /* 1295 * Calc device. 1296 */ 1297 char chDrv = *pszNativePath; 1298 if (chDrv == '/' || chDrv == '\\') 1299 return makedev('U', 0); /* U as in UNC */ 1300 LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z'); 1301 return makedev('V', chDrv); /* V as in Volume */ 1302 } 1303 1304 1305 /** 1306 * Reads the unix EAs for a file which is being stat'ed. 1307 * 1308 * @returns 0 on success. 1309 * @returns Negative errno on failure. 1310 * @param hFile File handle to the fs object. If no handle handy, set to -1. 1311 * @param pszNativePath Native path to the fs object. If handle is give this will be ignored. 1312 * @param pStat Pointer to the stat buffer. 1313 * The buffer is only updated if and with the EAs we find, 1314 * so the caller must fill the fields with defaults before 1315 * calling this function. 1316 */ 1317 int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat) 1318 { 1319 LIBCLOG_ENTER("hFile=%d pszNativePath=%p:{%s} pStat=%p\n", hFile, (void *)pszNativePath, pszNativePath, (void *)pStat); 1320 1321 /* Try come up with an accurate max estimate of a maximum result. */ 1322 char achBuffer[sizeof(EAOP2) + sizeof(FILEFINDBUF3) + sizeof(__libc_gFsUnixAttribsGEA2List) + 7 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + CCHMAXPATH + 6 * sizeof(uint32_t) + 0x30]; 1323 char *pachBuffer = (char *)((uintptr_t)&achBuffer[3] & ~3); 1324 PEAOP2 pEaOp2 = (PEAOP2)pachBuffer; 1325 int rc = -1000; 1326 1327 /* 1328 * Issue the query. 1329 */ 1330 if (hFile >= 0) 1331 { 1332 pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List; 1333 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1334 pEaOp2->oError = 0; 1335 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1336 rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2)); 1337 } 1338 if (rc && pszNativePath) 1339 { 1340 pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List; 1341 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1342 pEaOp2->oError = 0; 1343 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1344 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2)); 1345 if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED || rc == ERROR_INVALID_ACCESS) 1346 { 1347 HDIR hDir = HDIR_CREATE; 1348 ULONG cFiles = 1; 1349 pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List; 1350 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1351 pEaOp2->oError = 0; 1352 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1353 rc = DosFindFirst((PCSZ)pszNativePath, &hDir, 0, pEaOp2, pEaOp2->fpFEA2List->cbList + sizeof(*pEaOp2), &cFiles, FIL_QUERYEASFROMLIST); 1354 if (!rc) 1355 { 1356 DosFindClose(hDir); 1357 pEaOp2->fpFEA2List = (PFEA2LIST)((char *)pEaOp2 + sizeof(EAOP2) + offsetof(FILEFINDBUF3, cchName)); 1358 } 1359 } 1360 } 1361 if (rc) 1362 { 1363 LIBC_ASSERTM(rc == ERROR_ACCESS_DENIED || rc == ERROR_SHARING_VIOLATION || rc == ERROR_EAS_NOT_SUPPORTED, 1364 "Bogus EAs? rc=%d oError=%ld\n", rc, pEaOp2->oError); 1365 rc = -__libc_back_native2errno(rc); 1366 LIBCLOG_ERROR_RETURN_INT(rc); 1367 } 1368 if (pEaOp2->fpFEA2List->cbList < LIBC_UNIX_EA_MIN) 1369 LIBCLOG_RETURN_INT(0); 1370 1371 /* 1372 * Parse the result. 1373 */ 1374 PFEA2 pFea2 = &pEaOp2->fpFEA2List->list[0]; 1375 for (;;) 1376 { 1377 if (pFea2->cbValue > 0) 1378 { 1379 #define COMPARE_EANAME(name) (pFea2->cbName == sizeof(name) - 1 && !memcmp(name, pFea2->szName, sizeof(name) - 1)) 1380 if (COMPARE_EANAME(__libc_gszSymlinkEA)) 1381 pStat->st_mode = (pStat->st_mode & ~S_IFMT) | S_IFLNK; 1382 else 1383 { 1384 PUSHORT pusType = (PUSHORT)&pFea2->szName[pFea2->cbName + 1]; 1385 if (*pusType == EAT_BINARY) 1386 { 1387 pusType++; 1388 if (*pusType == sizeof(uint32_t)) 1389 { 1390 uint32_t u32 = *(uint32_t *)++pusType; 1391 if (COMPARE_EANAME(__libc_gszUidEA)) 1392 pStat->st_uid = u32; 1393 else if (COMPARE_EANAME(__libc_gszGidEA)) 1394 pStat->st_gid = u32; 1395 else if (COMPARE_EANAME(__libc_gszModeEA)) 1396 { 1397 if ( S_ISDIR(u32) || S_ISCHR(u32) || S_ISBLK(u32) || S_ISREG(u32) 1398 || S_ISFIFO(u32) || S_ISLNK(u32) || S_ISSOCK(u32) || S_ISWHT(u32)) 1399 pStat->st_mode = u32; 1400 else 1401 LIBC_ASSERTM_FAILED("Invalid file mode EA: u32=0%o (st_mode=0%o)\n", u32, pStat->st_mode); 1402 } 1403 else if (COMPARE_EANAME(__libc_gszRDevEA)) 1404 pStat->st_rdev = u32; 1405 else if (COMPARE_EANAME(__libc_gszGenEA)) 1406 pStat->st_gen = u32; 1407 else if (COMPARE_EANAME(__libc_gszFlagsEA)) 1408 pStat->st_flags = u32; 1409 else 1410 LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d! u32=%#x (%d)\n", pFea2->szName, pFea2->cbName, u32, u32); 1411 } 1412 else if (*pusType == sizeof(uint64_t)) 1413 { 1414 uint64_t u64 = *(uint64_t *)++pusType; 1415 if (COMPARE_EANAME(__libc_gszInoEA)) 1416 pStat->st_ino = u64; 1417 else 1418 LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d! u64=%#llx (%lld)\n", pFea2->szName, pFea2->cbName, u64, u64); 1419 } 1420 else 1421 LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' len=%#x and len=4 or 8.\n", pFea2->szName, *pusType); 1422 } 1423 else 1424 LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' type=%#x len=%#x, expected type=%#x and len=4 or 8.\n", 1425 pFea2->szName, pusType[0], pusType[1], EAT_BINARY); 1426 } 1427 #undef COMPARE_EANAME 1428 } 1429 1430 /* next */ 1431 if (pFea2->oNextEntryOffset <= sizeof(FEA2)) 1432 break; 1433 pFea2 = (PFEA2)((uintptr_t)pFea2 + pFea2->oNextEntryOffset); 1434 } 1435 1436 /* 1437 * Calc st_ino and st_dev if not found. 1438 */ 1439 if ((!pStat->st_ino || !pStat->st_dev) && pszNativePath) 1440 { 1441 ino_t Inode; 1442 dev_t Dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &Inode); 1443 if (!pStat->st_ino) 1444 pStat->st_ino = Inode; 1445 if (!pStat->st_dev) 1446 pStat->st_dev = Dev; 1447 } 1448 1449 LIBCLOG_RETURN_INT(0); 1450 } 1451 1452 1453 /** 1454 * Reads the unix file mode EA. 1455 * 1456 * @returns 0 on success. 1457 * @returns -ENOTSUP if the file mode EA is not present or if Unix EAs isn't supported on the volume. 1458 * @returns Negative errno on failure. 1459 * @param hFile File handle to the fs object. If no handle handy, set to -1. 1460 * @param pszNativePath Native path to the fs object. If handle is give this will be ignored. 1461 * @param pMode Where to store the mode mask. 1462 */ 1463 int __libc_back_fsUnixAttribsGetMode(int hFile, const char *pszNativePath, mode_t *pMode) 1464 { 1465 LIBCLOG_ENTER("hFile=%d pszNativePath=%p:{%s} pMode=%p\n", hFile, (void *)pszNativePath, pszNativePath, (void *)pMode); 1466 1467 /* Try come up with an accurate max estimate of a maximum result. */ 1468 char achBuffer[sizeof(EAOP2) + sizeof(FILEFINDBUF3) + sizeof(gGEA2ListMode) + 1 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + 1 * sizeof(uint32_t) + 0x30]; 1469 char *pachBuffer = (char *)((uintptr_t)&achBuffer[3] & ~3); 1470 PEAOP2 pEaOp2 = (PEAOP2)pachBuffer; 1471 int rc = -1000; 1472 1473 *pMode = 0; 1474 1475 /** @todo the following query is generic! It's repeated 3 times already in this file (only the gea list and buffer size varies). */ 1476 /* 1477 * Issue the query. 1478 */ 1479 if (hFile >= 0) 1480 { 1481 pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode; 1482 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1483 pEaOp2->oError = 0; 1484 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1485 rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2)); 1486 } 1487 if (rc && pszNativePath) 1488 { 1489 pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode; 1490 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1491 pEaOp2->oError = 0; 1492 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1493 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2)); 1494 if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED || rc == ERROR_INVALID_ACCESS) 1495 { 1496 HDIR hDir = HDIR_CREATE; 1497 ULONG cFiles = 1; 1498 pEaOp2->fpGEA2List = (PGEA2LIST)&gGEA2ListMode; 1499 pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1); 1500 pEaOp2->oError = 0; 1501 pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2); 1502 rc = DosFindFirst((PCSZ)pszNativePath, &hDir, 0, pEaOp2, pEaOp2->fpFEA2List->cbList + sizeof(*pEaOp2), &cFiles, FIL_QUERYEASFROMLIST); 1503 if (!rc) 1504 { 1505 DosFindClose(hDir); 1506 pEaOp2->fpFEA2List = (PFEA2LIST)((char *)pEaOp2 + sizeof(EAOP2) + offsetof(FILEFINDBUF3, cchName)); 1507 } 1508 } 1509 } 1510 if (rc) 1511 { 1512 LIBC_ASSERTM(rc == ERROR_ACCESS_DENIED || rc == ERROR_SHARING_VIOLATION || rc == ERROR_EAS_NOT_SUPPORTED, 1513 "Bogus EAs? rc=%d oError=%ld\n", rc, pEaOp2->oError); 1514 rc = -__libc_back_native2errno(rc); 1515 LIBCLOG_ERROR_RETURN_INT(rc); 1516 } 1517 1518 /* 1519 * Parse the result. 1520 * There is only one EA here, so this is gonna be pretty simple... 1521 */ 1522 rc = -ENOTSUP; 1523 PFEA2 pFea2 = &pEaOp2->fpFEA2List->list[0]; 1524 if ( pEaOp2->fpFEA2List->cbList > sizeof(*pFea2) 1525 && pFea2->cbValue > 0 1526 && pFea2->cbName == sizeof(EA_MODE) - 1 1527 && !memcmp(EA_MODE, pFea2->szName, sizeof(EA_MODE) - 1) 1528 ) 1529 { 1530 PUSHORT pusType = (PUSHORT)&pFea2->szName[pFea2->cbName + 1]; 1531 if ( pusType[0] == EAT_BINARY 1532 && pusType[1] == sizeof(uint32_t) 1533 ) 1534 { 1535 uint32_t u32 = *(uint32_t *)(pusType + 2); 1536 if ( S_ISDIR(u32) || S_ISCHR(u32) || S_ISBLK(u32) || S_ISREG(u32) 1537 || S_ISFIFO(u32) || S_ISLNK(u32) || S_ISSOCK(u32) || S_ISWHT(u32)) 1538 { 1539 *pMode = u32; 1540 rc = 0; 1541 } 1542 else 1543 LIBC_ASSERTM_FAILED("Invalid file mode EA: u32=0%o\n", u32); 1544 } 1545 else 1546 LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' type=%#x len=%#x, expected type=%#x and len=4.\n", 1547 pFea2->szName, pusType[0], pusType[1], EAT_BINARY); 1548 } 1549 1550 LIBCLOG_RETURN_MSG(rc, "ret %d *pMode=#%x\n", rc, *pMode); 1551 } 1552 1553 1554 /** 1555 * Reads the content of a symbolic link. 1556 * 1557 * This is weird interface as it will return a truncated result if not 1558 * enough buffer space. It is also weird in that there is no string 1559 * terminator. 1560 * 1561 * @returns Number of bytes returned in pachBuf. 1562 * @returns -1 and errno on failure. 1563 * @param pszNativePath The path to the symlink to read. 1564 * @param pachBuf Where to store the symlink value. 1565 * @param cchBuf Size of buffer. 1566 */ 1567 int __libc_back_fsNativeSymlinkRead(const char *pszNativePath, char *pachBuf, size_t cchBuf) 1568 { 1569 LIBCLOG_ENTER("pszNativePath=%p:{%s} pachBuf=%p cchBuf=%d\n", (void *)pszNativePath, pszNativePath, (void *)pachBuf, cchBuf); 1570 1571 /* 1572 * Query the symlink EA value. 1573 */ 1574 char _achBuffer[SIZEOF_ACHBUFFER + 4]; 1575 char *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3); 1576 EAOP2 EaOp; 1577 EaOp.fpGEA2List = (PGEA2LIST)&gGEA2ListSymlink; 1578 EaOp.fpFEA2List = (PFEA2LIST)pachBuffer; 1579 EaOp.oError = 0; 1580 EaOp.fpFEA2List->cbList = SIZEOF_ACHBUFFER; 1581 int rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, &EaOp, sizeof(EaOp)); 1582 if (!rc) 1583 { 1584 if ( EaOp.fpFEA2List->cbList > sizeof(EaOp.fpFEA2List->list[0]) 1585 && EaOp.fpFEA2List->list[0].cbValue) 1586 { 1587 /* 1588 * Validate the EA. 1589 */ 1590 PUSHORT pusType = (PUSHORT)((char *)&EaOp.fpFEA2List->list[1] + EaOp.fpFEA2List->list[0].cbName); 1591 int cchSymlink = pusType[1]; 1592 char *pszSymlink = (char *)&pusType[2]; 1593 if ( pusType[0] == EAT_ASCII 1594 && cchSymlink < EaOp.fpFEA2List->list[0].cbValue 1595 && cchSymlink > 0 1596 && *pszSymlink) 1597 { 1598 /* 1599 * Copy it to the buffer and return. 1600 */ 1601 if (cchSymlink > cchBuf) 1602 { 1603 LIBCLOG_ERROR("Buffer to small. %d bytes required, %d bytes available. pszSymlink='%.*s' pszNativePath='%s'\n", 1604 cchSymlink, cchBuf, cchSymlink, pszSymlink, pszNativePath); 1605 cchSymlink = cchBuf; 1606 } 1607 memcpy(pachBuf, pszSymlink, cchSymlink); 1608 LIBCLOG_RETURN_INT(cchSymlink); 1609 } 1610 else 1611 LIBCLOG_ERROR_RETURN(-EFTYPE, "ret -EFTYPE - Invalid symlink EA! type=%x len=%d cbValue=%d *pszSymlink=%c pszNativePath='%s'\n", 1612 pusType[0], pusType[1], EaOp.fpFEA2List->list[0].cbValue, *pszSymlink, pszNativePath); 1613 } 1614 else 1615 LIBCLOG_ERROR_RETURN(-EINVAL, "ret -EINVAL - %s is not a symlink!\n", pszNativePath); 1616 } 1617 else 1618 LIBCLOG_ERROR("DosQueryPathInfo(%s) -> %d!\n", pszNativePath, rc); 1619 1620 /* failure */ 1621 rc = -__libc_back_native2errno(rc); 1622 LIBCLOG_ERROR_RETURN_INT(rc); 1623 } 1624 1625 1626 /** 1627 * Checks if the specified path is a symlink or not. 1628 * @returns true / false. 1629 * @param pszNativePath Path to the potential symlink. 1630 */ 1631 static int fsIsSymlink(const char *pszNativePath) 1632 { 1633 char sz[16]; 1634 return __libc_back_fsNativeSymlinkRead(pszNativePath, sz, sizeof(sz)) >= 0; 1635 } 1636 -
trunk/libc/src/libc/app/putenv.c
r2254 r2935 5 5 #include <string.h> 6 6 #include <errno.h> 7 #include < emx/startup.h>8 #include < emx/time.h> /* _tzset_flag */7 #include <klibc/time.h> 8 #include <klibc/initterm.h> 9 9 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 10 #include < InnoTekLIBC/logstrict.h>10 #include <klibc/logstrict.h> 11 11 12 12 int _STD(putenv)(const char *string) … … 80 80 } 81 81 82 _tzset_flag = 0; /* Call tzset() */ 82 /* If it's TZ, invalidate the tz data. */ 83 if (len == 2 && string[0] == 'T' && string[1] == 'Z') 84 __libc_gfTZInfoOk = 0; 85 83 86 LIBCLOG_RETURN_INT(0); 84 87 } 88 -
trunk/libc/src/libc/app/setenv.c
r2909 r2935 2 2 /** @file 3 3 * 4 * LIBC APP- setenv().4 * kLIBC - setenv(). 5 5 * 6 6 * Copyright (c) 2003 InnoTek Systemberatung GmbH 7 * Author: knut st. osmundsen <bird-src spam@anduin.net>8 * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>7 * Author: knut st. osmundsen <bird-src-spam@innotek.de> 8 * Copyright (c) 2005-2006 knut st. osmundsen <bird-src-spam@anduin.net> 9 9 * 10 10 * 11 * This file is part of InnoTekLIBC.11 * This file is part of kLIBC. 12 12 * 13 * InnoTekLIBC is free software; you can redistribute it and/or modify13 * kLIBC is free software; you can redistribute it and/or modify 14 14 * it under the terms of the GNU General Public License as published by 15 15 * the Free Software Foundation; either version 2 of the License, or 16 16 * (at your option) any later version. 17 17 * 18 * InnoTekLIBC is distributed in the hope that it will be useful,18 * kLIBC is distributed in the hope that it will be useful, 19 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the … … 22 22 * 23 23 * You should have received a copy of the GNU General Public License 24 * along with InnoTekLIBC; if not, write to the Free Software24 * along with kLIBC; if not, write to the Free Software 25 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 26 * … … 34 34 #include <string.h> 35 35 #include <errno.h> 36 #include < emx/startup.h>36 #include <klibc/initterm.h> 37 37 #include <klibc/time.h> 38 38 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV … … 74 74 } 75 75 76 /* look for the TZ variable and invalid the time zone data when encountered. */76 /* If it's TZ, invalidate the tz data. */ 77 77 if (envname[0] == 'T' && envname[1] == 'Z' && envname[2] == '\0') 78 78 __libc_gfTZInfoOk = 0; -
trunk/libc/src/libc/app/unsetenv.c
r2254 r2935 34 34 #include <string.h> 35 35 #include <errno.h> 36 #include <emx/startup.h> 37 #include <emx/time.h> 38 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 39 #include <InnoTekLIBC/logstrict.h> 36 #include <klibc/time.h> 37 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 38 #include <klibc/logstrict.h> 40 39 41 40 … … 80 79 break; 81 80 LIBCLOG_MSG("deleted '%s'\n", s); 82 _tzset_flag = 0; /* Call tzset() */ 81 /* If it's TZ, invalidate the tz data. */ 82 if (lenname == 2 && name[0] == 'T' && name[1] == 'Z') 83 __libc_gfTZInfoOk = 0; 83 84 } 84 85 else … … 91 92 LIBCLOG_RETURN_INT(0); 92 93 } 94 -
trunk/libc/src/libc/io/_tempnam.c
r1454 r2935 11 11 #include <io.h> 12 12 #include <errno.h> 13 #include <sys/stat.h> 13 14 #include <sys/param.h> 14 15 #include <emx/io.h> 15 #include <emx/syscalls.h>16 16 #include "_tmp.h" 17 17 … … 22 22 static int _isdir (char *dst, const char *src) 23 23 { 24 int attr;24 struct stat s; 25 25 26 26 if (_fullpath (dst, src, MAXPATHLEN) != 0) 27 27 return 0; 28 attr = __chmod (dst, 0, 0);29 return attr >= 0 && (attr & _A_SUBDIR);28 return lstat (dst, &s) == 0 29 && S_ISDIR(s.st_mode); 30 30 } 31 31 -
trunk/libc/src/libc/io/_vsopen.c
r2810 r2935 8 8 #include <sys/types.h> 9 9 #include <sys/stat.h> 10 #include <emx/io.h> 11 #include <emx/syscalls.h> 12 #include <InnoTekLIBC/backend.h> 10 #include <klibc/io.h> 11 #include <klibc/backend.h> 13 12 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO 14 #include < InnoTekLIBC/logstrict.h>13 #include <klibc/logstrict.h> 15 14 16 15 /* Bugs: O_TRUNC|O_RDONLY not implemented - bird: rejecting it makes more sense, just ask the OpenBSD guys. */ … … 162 161 { 163 162 LIBCLOG_MSG("Ctrl-Z: Reopening the file in O_WRONLY mode.\n"); 164 __ close(fd);163 __libc_Back_ioClose(fd); 165 164 int fLibcSaved = fLibc; 166 165 fLibc = (fLibc & ~(O_ACCMODE | O_EXCL | __LIBC_FH_TYPEMASK)) | O_WRONLY; /* Ignore exclusive open. */ -
trunk/libc/src/libc/io/fdopen.c
r2229 r2935 9 9 #include <stdio.h> 10 10 #include <stdio.h> 11 #include <emx/io.h> 11 #include <klibc/io.h> 12 #include <klibc/backend.h> 12 13 13 14 #define FALSE 0 … … 22 23 int omode; 23 24 24 if (!__libc_FH(handle)) 25 int rc = __libc_Back_fhValidate(handle); 26 if (rc) 25 27 { 26 errno = EBADF;28 errno = -rc; 27 29 return NULL; 28 30 } … … 98 100 return dst; 99 101 } 102 -
trunk/libc/src/libc/io/fstat.c
r2672 r2935 1 /* fstat.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */ 1 /* $Id: $ */ 2 /** @file 3 * 4 * kLIBC - fstat(). 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net> 7 * 8 * 9 * This file is part of kLIBC. 10 * 11 * kLIBC is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License as published 13 * by the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * kLIBC is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kLIBC; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 2 26 3 27 #include "libc-alias.h" 4 #include <time.h> 5 #include <io.h> 28 #include <sys/stat.h> 6 29 #include <errno.h> 7 #include <sys/types.h> 8 #include <sys/stat.h> 9 #include <emx/time.h> 10 #include <emx/syscalls.h> 11 #include <InnoTekLIBC/backend.h> 30 #include <klibc/backend.h> 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_FS 32 #include <klibc/logstrict.h> 12 33 13 int _STD(fstat) (int handle, struct stat *buffer)34 int _STD(fstat)(int fh, struct stat *pStat) 14 35 { 15 int rc = __libc_Back_fsFileStatFH (handle, buffer); 16 if (rc == 0) 36 LIBCLOG_ENTER("fh=%d pStat=%p\n", fh, (void *)pStat); 37 int rc = __libc_Back_fsFileStatFH(fh, pStat); 38 if (!rc) 17 39 { 18 if (!_tzset_flag) 19 tzset (); 20 _loc2gmt (&buffer->st_atime, -1); 21 _loc2gmt (&buffer->st_mtime, -1); 22 _loc2gmt (&buffer->st_ctime, -1); 23 _loc2gmt (&buffer->st_birthtime, -1); 40 LIBCLOG_MSG("%02x - st_dev: %#x\n", offsetof(struct stat, st_dev), pStat->st_dev); 41 LIBCLOG_MSG("%02x - st_attr: %#x\n", offsetof(struct stat, st_attr), pStat->st_attr); 42 LIBCLOG_MSG("%02x - st_ino: %#llx\n",offsetof(struct stat, st_ino), (long long)pStat->st_ino); 43 LIBCLOG_MSG("%02x - st_mode: %#x\n", offsetof(struct stat, st_mode), pStat->st_mode); 44 LIBCLOG_MSG("%02x - st_nlink: %u\n", offsetof(struct stat, st_nlink), pStat->st_nlink); 45 LIBCLOG_MSG("%02x - st_uid: %u\n", offsetof(struct stat, st_uid), pStat->st_uid); 46 LIBCLOG_MSG("%02x - st_gid: %u\n", offsetof(struct stat, st_gid), pStat->st_gid); 47 LIBCLOG_MSG("%02x - st_rdev: %#x\n", offsetof(struct stat, st_rdev), pStat->st_rdev); 48 LIBCLOG_MSG("%02x - st_lspare: %#x\n", offsetof(struct stat, st_lspare), pStat->st_lspare); 49 LIBCLOG_MSG("%02x - st_atime: %d\n", offsetof(struct stat, st_atime), pStat->st_atime); 50 LIBCLOG_MSG("%02x - st_mtime: %d\n", offsetof(struct stat, st_mtime), pStat->st_mtime); 51 LIBCLOG_MSG("%02x - st_ctime: %d\n", offsetof(struct stat, st_ctime), pStat->st_ctime); 52 LIBCLOG_MSG("%02x - st_size: %lld\n", offsetof(struct stat, st_size), (long long)pStat->st_size); 53 LIBCLOG_MSG("%02x - st_blocks: %lld\n", offsetof(struct stat, st_blocks), (long long)pStat->st_blocks); 54 LIBCLOG_MSG("%02x - st_blksize: %u\n", offsetof(struct stat, st_blksize), pStat->st_blksize); 55 LIBCLOG_MSG("%02x - st_flags: %#x\n", offsetof(struct stat, st_flags), pStat->st_flags); 56 LIBCLOG_MSG("%02x - st_gen: %#x\n", offsetof(struct stat, st_gen), pStat->st_gen); 57 LIBCLOG_MSG("%02x - st_birthtime: %d\n", offsetof(struct stat, st_birthtime), pStat->st_birthtime); 58 LIBCLOG_RETURN_INT(0); 24 59 } 25 else 26 { 27 errno = -rc; 28 rc = -1; 29 } 30 return rc; 60 errno = -rc; 61 LIBCLOG_ERROR_RETURN_INT(-1); 31 62 } 63 -
trunk/libc/src/libc/io/lstat.c
r2672 r2935 1 /* $Id$ */ /* lstat.c (libc) -- Copyright (c) 2003 knut st. osmundsen */1 /* $Id$ */ 2 2 /** @file 3 3 * 4 * lstat().4 * kLIBC - lstat(). 5 5 * 6 * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>6 * Copyright (c) 2004-2006 knut st. osmundsen <bird-src-spam@anduin.net> 7 7 * 8 8 * … … 25 25 */ 26 26 27 28 /*******************************************************************************29 * Header Files *30 *******************************************************************************/31 27 #include "libc-alias.h" 28 #include <sys/stat.h> 32 29 #include <errno.h> 33 #include <sys/types.h> 34 #include <sys/stat.h> 35 #include <emx/time.h> 36 #include <InnoTekLIBC/backend.h> 37 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC 38 #include <InnoTekLIBC/logstrict.h> 30 #include <klibc/backend.h> 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_FS 32 #include <klibc/logstrict.h> 39 33 40 34 41 int _STD(lstat)(const char * name, struct stat *buffer)35 int _STD(lstat)(const char *pszPath, struct stat *pStat) 42 36 { 43 LIBCLOG_ENTER(" name=%p:{%s} buffer=%p\n", (void *)name, name, (void *)buffer);44 int rc = __libc_Back_fsSymlinkStat( name, buffer);37 LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat); 38 int rc = __libc_Back_fsSymlinkStat(pszPath, pStat); 45 39 if (!rc) 46 40 { 47 if (!_tzset_flag) 48 tzset(); 49 _loc2gmt(&buffer->st_atime, -1); 50 _loc2gmt(&buffer->st_mtime, -1); 51 _loc2gmt(&buffer->st_ctime, -1); 52 _loc2gmt(&buffer->st_birthtime, -1); 41 LIBCLOG_MSG("%02x - st_dev: %#x\n", offsetof(struct stat, st_dev), pStat->st_dev); 42 LIBCLOG_MSG("%02x - st_attr: %#x\n", offsetof(struct stat, st_attr), pStat->st_attr); 43 LIBCLOG_MSG("%02x - st_ino: %#llx\n",offsetof(struct stat, st_ino), (long long)pStat->st_ino); 44 LIBCLOG_MSG("%02x - st_mode: %#x\n", offsetof(struct stat, st_mode), pStat->st_mode); 45 LIBCLOG_MSG("%02x - st_nlink: %u\n", offsetof(struct stat, st_nlink), pStat->st_nlink); 46 LIBCLOG_MSG("%02x - st_uid: %u\n", offsetof(struct stat, st_uid), pStat->st_uid); 47 LIBCLOG_MSG("%02x - st_gid: %u\n", offsetof(struct stat, st_gid), pStat->st_gid); 48 LIBCLOG_MSG("%02x - st_rdev: %#x\n", offsetof(struct stat, st_rdev), pStat->st_rdev); 49 LIBCLOG_MSG("%02x - st_lspare: %#x\n", offsetof(struct stat, st_lspare), pStat->st_lspare); 50 LIBCLOG_MSG("%02x - st_atime: %d\n", offsetof(struct stat, st_atime), pStat->st_atime); 51 LIBCLOG_MSG("%02x - st_mtime: %d\n", offsetof(struct stat, st_mtime), pStat->st_mtime); 52 LIBCLOG_MSG("%02x - st_ctime: %d\n", offsetof(struct stat, st_ctime), pStat->st_ctime); 53 LIBCLOG_MSG("%02x - st_size: %lld\n", offsetof(struct stat, st_size), (long long)pStat->st_size); 54 LIBCLOG_MSG("%02x - st_blocks: %lld\n", offsetof(struct stat, st_blocks), (long long)pStat->st_blocks); 55 LIBCLOG_MSG("%02x - st_blksize: %u\n", offsetof(struct stat, st_blksize), pStat->st_blksize); 56 LIBCLOG_MSG("%02x - st_flags: %#x\n", offsetof(struct stat, st_flags), pStat->st_flags); 57 LIBCLOG_MSG("%02x - st_gen: %#x\n", offsetof(struct stat, st_gen), pStat->st_gen); 58 LIBCLOG_MSG("%02x - st_birthtime: %d\n", offsetof(struct stat, st_birthtime), pStat->st_birthtime); 53 59 LIBCLOG_RETURN_INT(0); 54 60 } -
trunk/libc/src/libc/io/stat.c
r2672 r2935 1 /* stat.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */ 1 /* $Id: lstat.c 2672 2006-03-19 05:18:20Z bird $ */ 2 /** @file 3 * 4 * kLIBC - stat(). 5 * 6 * Copyright (c) 2004-2006 knut st. osmundsen <bird-src-spam@anduin.net> 7 * 8 * 9 * This file is part of InnoTek LIBC. 10 * 11 * InnoTek LIBC is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License as published 13 * by the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * InnoTek LIBC is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with InnoTek LIBC; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 2 26 3 27 #include "libc-alias.h" 28 #include <sys/stat.h> 4 29 #include <errno.h> 5 #include <sys/types.h> 6 #include <sys/stat.h> 7 #include <emx/time.h> 8 #include <InnoTekLIBC/backend.h> 9 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC 10 #include <InnoTekLIBC/logstrict.h> 30 #include <klibc/backend.h> 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_FS 32 #include <klibc/logstrict.h> 11 33 12 int _STD(stat)(const char * name, struct stat *buffer)34 int _STD(stat)(const char *pszPath, struct stat *pStat) 13 35 { 14 LIBCLOG_ENTER(" name=%p:{%s} buffer=%p\n", (void *)name, name, (void *)buffer);15 int rc = __libc_Back_fsFileStat( name, buffer);36 LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat); 37 int rc = __libc_Back_fsFileStat(pszPath, pStat); 16 38 if (!rc) 17 39 { 18 if (!_tzset_flag) 19 tzset(); 20 _loc2gmt(&buffer->st_atime, -1); 21 _loc2gmt(&buffer->st_mtime, -1); 22 _loc2gmt(&buffer->st_ctime, -1); 23 _loc2gmt(&buffer->st_birthtime, -1); 24 LIBCLOG_RETURN_INT(rc); 40 LIBCLOG_MSG("%02x - st_dev: %#x\n", offsetof(struct stat, st_dev), pStat->st_dev); 41 LIBCLOG_MSG("%02x - st_attr: %#x\n", offsetof(struct stat, st_attr), pStat->st_attr); 42 LIBCLOG_MSG("%02x - st_ino: %#llx\n",offsetof(struct stat, st_ino), (long long)pStat->st_ino); 43 LIBCLOG_MSG("%02x - st_mode: %#x\n", offsetof(struct stat, st_mode), pStat->st_mode); 44 LIBCLOG_MSG("%02x - st_nlink: %u\n", offsetof(struct stat, st_nlink), pStat->st_nlink); 45 LIBCLOG_MSG("%02x - st_uid: %u\n", offsetof(struct stat, st_uid), pStat->st_uid); 46 LIBCLOG_MSG("%02x - st_gid: %u\n", offsetof(struct stat, st_gid), pStat->st_gid); 47 LIBCLOG_MSG("%02x - st_rdev: %#x\n", offsetof(struct stat, st_rdev), pStat->st_rdev); 48 LIBCLOG_MSG("%02x - st_lspare: %#x\n", offsetof(struct stat, st_lspare), pStat->st_lspare); 49 LIBCLOG_MSG("%02x - st_atime: %d\n", offsetof(struct stat, st_atime), pStat->st_atime); 50 LIBCLOG_MSG("%02x - st_mtime: %d\n", offsetof(struct stat, st_mtime), pStat->st_mtime); 51 LIBCLOG_MSG("%02x - st_ctime: %d\n", offsetof(struct stat, st_ctime), pStat->st_ctime); 52 LIBCLOG_MSG("%02x - st_size: %lld\n", offsetof(struct stat, st_size), (long long)pStat->st_size); 53 LIBCLOG_MSG("%02x - st_blocks: %lld\n", offsetof(struct stat, st_blocks), (long long)pStat->st_blocks); 54 LIBCLOG_MSG("%02x - st_blksize: %u\n", offsetof(struct stat, st_blksize), pStat->st_blksize); 55 LIBCLOG_MSG("%02x - st_flags: %#x\n", offsetof(struct stat, st_flags), pStat->st_flags); 56 LIBCLOG_MSG("%02x - st_gen: %#x\n", offsetof(struct stat, st_gen), pStat->st_gen); 57 LIBCLOG_MSG("%02x - st_birthtime: %d\n", offsetof(struct stat, st_birthtime), pStat->st_birthtime); 58 LIBCLOG_RETURN_INT(0); 25 59 } 26 27 60 errno = -rc; 28 61 LIBCLOG_ERROR_RETURN_INT(-1); 29 62 } 63 -
trunk/libc/src/libc/libc.def
r2813 r2935 44 44 "__osmajor" @22 45 45 "__osminor" @23 46 "__pipe_size" @2446 ; dead "__pipe_size" @24 47 47 "__rand48_add" @25 48 48 "__rand48_mult" @26 … … 56 56 "__streamvec_tail" @34 57 57 "__tmpidx" @35 58 "__tzi" @3659 "__tzset_flag" @3758 ;"__tzi" @36 59 ;"__tzset_flag" @37 60 60 "__um_high_heap" @38 61 61 "__um_low_heap" @39 … … 213 213 "___buf_init" @226 214 214 "___call_hash" @227 215 "___chmod" @228216 "___close" @229215 ; dead "___chmod" @228 216 ; dead "___close" @229 217 217 "___collate_range_cmp" @230 218 218 "___ctordtorInit1" @231 … … 221 221 "___delpair" @234 222 222 "___legacy_dtoa" @235 223 "___dup" @236224 "___dup2" @237223 ; dead "___dup" @236 224 ; dead "___dup2" @237 225 225 "___error" @238 226 226 "___error_at_line" @239 227 "___exit" @240227 ; dead "___exit" @240 228 228 "___expand_table" @241 229 229 "___libc_Back_ioFileControl" @242 … … 241 241 ;msun - dead "___fpclassifyl" @254 242 242 "___free_ovflpage" @255 243 "___ftime" @256243 ; dead "___ftime" @256 244 244 "___get_buf" @257 245 245 "___get_page" @258 … … 248 248 "___hash_open" @261 249 249 "___ibitmap" @262 250 "___imphandle" @263250 ; dead "___imphandle" @263 251 251 "___init" @264 252 252 "___init_app" @265 253 253 "___init_dll" @266 254 "___ioctl1" @267255 "___ioctl2" @268254 ; dead "___ioctl1" @267 255 ; dead "___ioctl2" @268 256 256 "___isctype" @269 257 257 "___isfinite" @270 … … 321 321 "___libc_Back_threadInit" @334 322 322 "___libc_Back_threadStartup" @335 323 "___libc_FH " @336323 "___libc_FHPut" @336 324 324 "___libc_FHAllocate" @337 325 "___libc_FHClose" @338325 ; dead "___libc_FHClose" @338 326 326 "___libc_FHEnsureHandles" @339 327 "___libc_FH Ex" @340327 "___libc_FHGet" @340 328 328 "___libc_FHMoreHandles" @341 329 329 "___libc_ForkDefaultModuleCallback" @342 … … 375 375 "___ovfl_get" @388 376 376 "___ovfl_put" @389 377 "___pipe" @390377 ; dead "___pipe" @390 378 378 "___posix_spawn_file_actions_realloc" @391 379 379 "___put_page" @392 … … 381 381 "___pw_parse_entry" @394 382 382 "___pw_scan" @395 383 "___read" @396383 ; dead "___read" @396 384 384 "___read_kbd" @397 385 385 "___rec_close" @398 … … 402 402 "___remove_zeros" @415 403 403 "___select" @416 404 "___settime" @417404 ; dead "___settime" @417 405 405 "___signbit" @418 406 406 "___signbitf" @419 … … 417 417 "___strnlen" @430 418 418 "___strverscmp" @431 419 "___swchar" @432419 ; dead "___swchar" @432 420 420 "___threadid" @433 421 421 "___tolower" @434 422 422 "___toupper" @435 423 "___ttyname" @436424 "___ulimit" @437423 ; dead "___ttyname" @436 424 ; dead "___ulimit" @437 425 425 "___unwind2" @438 426 426 "__std_lutimes" @439 427 "___wait" @440428 "___waitpid" @441429 "___write" @442427 ; dead "___wait" @440 428 ; dead "___waitpid" @441 429 ; dead "___write" @442 430 430 "__abspath" @443 431 431 "__assert" @444 … … 466 466 "__const_ZERO" @479 467 467 "__control87" @480 468 "__core" @481468 ; dead "__core" @481 469 469 "__crlf" @482 470 470 "__day" @483 … … 611 611 "__mheap" @624 612 612 "__mktime" @625 613 "__month_day_leap" @626614 "__month_day_non_leap" @627613 ; dead "__month_day_leap" @626 614 ; dead "__month_day_non_leap" @627 615 615 "__msize" @628 616 616 "__newstream" @629 … … 1088 1088 "__stream_write" @1101 1089 1089 "__strncpy" @1102 1090 "__swchar" @11031091 "__sys_dump_heap_objs" @11041090 ; dead "__swchar" @1103 1091 ; dead "__sys_dump_heap_objs" @1104 1092 1092 "__tcalloc" @1105 1093 1093 "__tfree" @1106 … … 1149 1149 "__warn" @1162 1150 1150 "__wildcard" @1163 1151 "__year_day" @11641151 ; dead "__year_day" @1164 1152 1152 "_argz_delete" @1165 1153 1153 "_catclose" @1166 … … 1958 1958 "__std_nanf" @1956 1959 1959 "__std_nanl" @1957 1960 1960 ; new stuff 0.7 1961 "_gOS2FileOps" @1958 1962 "__std_adjtime" @1959 1963 "__std_getrusage" @1960 1964 "__std_ttyname_r" @1961 -
trunk/libc/src/libc/locale/os2/setlocale.c
r2729 r2935 1281 1281 FS_RESTORE(); 1282 1282 LIBC_ASSERTM_FAILED("DosQueryCp failed with rc=%d\n", rc); 1283 return - __libc_native2errno(rc);1283 return -EDOOFUS; 1284 1284 } 1285 1285 LIBC_ASSERT(cb >= sizeof(ULONG)); -
trunk/libc/src/libc/misc/Makefile.kmk
r2914 r2935 105 105 $(PATH_LIBC_SRC)/libc/misc/nullstub.c \ 106 106 $(PATH_LIBC_SRC)/libc/misc/on_exit.c \ 107 $(PATH_LIBC_SRC)/libc/misc/os2bad.c \108 107 $(PATH_LIBC_SRC)/libc/misc/path.c \ 109 108 $(PATH_LIBC_SRC)/libc/misc/pathconf.c \ -
trunk/libc/src/libc/misc/dtread.c
r732 r2935 10 10 #include <sys/dirent.h> 11 11 #include <sys/dirtree.h> 12 #include < emx/io.h>13 #include < emx/time.h>12 #include <klibc/io.h> 13 #include <klibc/time.h> 14 14 #include <emx/syscalls.h> 15 15 … … 165 165 int len, saved_errno; 166 166 167 if (!_tzset_flag) tzset (); 167 if (!__libc_gfTZInfoOk) 168 tzset (); 168 169 data.dir = dir; 169 170 data.mask = mask; … … 171 172 data.dir_pass = 1; 172 173 if (strcmp (mask, "*.*") == 0 173 || (strcmp (mask, "*") == 0))174 || strcmp (mask, "*") == 0) 174 175 data.dir_pass = 0; 175 176 data.attr = A_HIDDEN | A_SYSTEM; -
trunk/libc/src/libc/process/sleep.c
r2918 r2935 31 31 #include <klibc/logstrict.h> 32 32 33 unsigned sleep(unsigned cSeconds)33 unsigned _STD(sleep)(unsigned cSeconds) 34 34 { 35 35 uint64_t cNanoRem = 0;
Note:
See TracChangeset
for help on using the changeset viewer.