Changeset 3140 for trunk/src/kmk/w32/compat
- Timestamp:
 - Mar 14, 2018, 10:28:10 PM (8 years ago)
 - Location:
 - trunk/src/kmk
 - Files:
 - 
      
- 2 edited
 - 1 copied
 
- 
          
  . (modified) (1 prop)
 - 
          
  w32/compat/dirent.c (modified) (7 diffs)
 - 
          
  w32/compat/posixfcn.c (copied) (copied from vendor/gnumake/current/w32/compat/posixfcn.c )
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
trunk/src/kmk
- 
Property       svn:mergeinfo
 set to       
/vendor/gnumake/current merged eligible  
 - 
Property       svn:mergeinfo
 set to       
 - 
      
trunk/src/kmk/w32/compat/dirent.c
r2591 r3140 1 1 /* Directory entry code for Window platforms. 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 3 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 2 Copyright (C) 1996-2016 Free Software Foundation, Inc. 4 3 This file is part of GNU Make. 5 4 … … 32 31 opendir(const char* pDirName) 33 32 { 34 struct stat sb;35 DIR*pDir;36 char*pEndDirName;37 intnBufferLen;38 39 /* sanity checks */40 if (!pDirName) {41 errno = EINVAL;42 return NULL;43 }44 if (stat(pDirName, &sb) != 0) {45 errno = ENOENT;46 return NULL;47 }48 if ((sb.st_mode & S_IFMT) != S_IFDIR) {49 errno = ENOTDIR;50 return NULL;51 }52 53 /* allocate a DIR structure to return */54 pDir = (DIR *) malloc(sizeof (DIR));55 56 if (!pDir)57 return NULL;58 59 /* input directory name length */60 nBufferLen = strlen(pDirName);61 62 /* copy input directory name to DIR buffer */63 strcpy(pDir->dir_pDirectoryName, pDirName);64 65 /* point to end of the copied directory name */66 pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];67 68 /* if directory name did not end in '/' or '\', add '/' */69 if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {70 pEndDirName++;71 *pEndDirName = '/';72 }73 74 /* now append the wildcard character to the buffer */75 pEndDirName++;76 *pEndDirName = '*';77 pEndDirName++;78 *pEndDirName = '\0';79 80 /* other values defaulted */81 pDir->dir_nNumFiles = 0;82 pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;83 pDir->dir_ulCookie = __DIRENT_COOKIE;33 struct stat sb; 34 DIR* pDir; 35 char* pEndDirName; 36 int nBufferLen; 37 38 /* sanity checks */ 39 if (!pDirName) { 40 errno = EINVAL; 41 return NULL; 42 } 43 if (stat(pDirName, &sb) != 0) { 44 errno = ENOENT; 45 return NULL; 46 } 47 if ((sb.st_mode & S_IFMT) != S_IFDIR) { 48 errno = ENOTDIR; 49 return NULL; 50 } 51 52 /* allocate a DIR structure to return */ 53 pDir = (DIR *) malloc(sizeof (DIR)); 54 55 if (!pDir) 56 return NULL; 57 58 /* input directory name length */ 59 nBufferLen = strlen(pDirName); 60 61 /* copy input directory name to DIR buffer */ 62 strcpy(pDir->dir_pDirectoryName, pDirName); 63 64 /* point to end of the copied directory name */ 65 pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1]; 66 67 /* if directory name did not end in '/' or '\', add '/' */ 68 if ((*pEndDirName != '/') && (*pEndDirName != '\\')) { 69 pEndDirName++; 70 *pEndDirName = '/'; 71 } 72 73 /* now append the wildcard character to the buffer */ 74 pEndDirName++; 75 *pEndDirName = '*'; 76 pEndDirName++; 77 *pEndDirName = '\0'; 78 79 /* other values defaulted */ 80 pDir->dir_nNumFiles = 0; 81 pDir->dir_hDirHandle = INVALID_HANDLE_VALUE; 82 pDir->dir_ulCookie = __DIRENT_COOKIE; 84 83 85 84 #ifdef KMK_PRF 86 fprintf(stderr, "opendir(%s) -> %p\n", pDirName, pDir);85 fprintf(stderr, "opendir(%s) -> %p\n", pDirName, pDir); 87 86 #endif 88 return pDir;87 return pDir; 89 88 } 90 89 … … 92 91 closedir(DIR *pDir) 93 92 { 94 /* got a valid pointer? */95 if (!pDir) {96 errno = EINVAL;97 return;98 }99 100 /* sanity check that this is a DIR pointer */101 if (pDir->dir_ulCookie != __DIRENT_COOKIE) {102 errno = EINVAL;103 return;104 }105 106 /* close the WINDOWS32 directory handle */107 if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)108 FindClose(pDir->dir_hDirHandle);109 110 free(pDir);111 112 return;93 /* got a valid pointer? */ 94 if (!pDir) { 95 errno = EINVAL; 96 return; 97 } 98 99 /* sanity check that this is a DIR pointer */ 100 if (pDir->dir_ulCookie != __DIRENT_COOKIE) { 101 errno = EINVAL; 102 return; 103 } 104 105 /* close the WINDOWS32 directory handle */ 106 if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE) 107 FindClose(pDir->dir_hDirHandle); 108 109 free(pDir); 110 111 return; 113 112 } 114 113 … … 116 115 readdir(DIR* pDir) 117 116 { 118 WIN32_FIND_DATA wfdFindData;119 120 if (!pDir) {121 errno = EINVAL;122 return NULL;123 }124 125 /* sanity check that this is a DIR pointer */126 if (pDir->dir_ulCookie != __DIRENT_COOKIE) {127 errno = EINVAL;128 return NULL;129 }130 131 if (pDir->dir_nNumFiles == 0) {132 pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);133 if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)134 return NULL;135 } else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))136 return NULL;137 138 /* bump count for next call to readdir() or telldir() */139 pDir->dir_nNumFiles++;140 141 /* fill in struct dirent values */142 pDir->dir_sdReturn.d_ino = (ino_t)-1;143 strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);144 145 return &pDir->dir_sdReturn;117 WIN32_FIND_DATA wfdFindData; 118 119 if (!pDir) { 120 errno = EINVAL; 121 return NULL; 122 } 123 124 /* sanity check that this is a DIR pointer */ 125 if (pDir->dir_ulCookie != __DIRENT_COOKIE) { 126 errno = EINVAL; 127 return NULL; 128 } 129 130 if (pDir->dir_nNumFiles == 0) { 131 pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData); 132 if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE) 133 return NULL; 134 } else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData)) 135 return NULL; 136 137 /* bump count for next call to readdir() or telldir() */ 138 pDir->dir_nNumFiles++; 139 140 /* fill in struct dirent values */ 141 pDir->dir_sdReturn.d_ino = (ino_t)-1; 142 strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName); 143 144 return &pDir->dir_sdReturn; 146 145 } 147 146 … … 149 148 rewinddir(DIR* pDir) 150 149 { 151 if (!pDir) {152 errno = EINVAL;153 return;154 }155 156 /* sanity check that this is a DIR pointer */157 if (pDir->dir_ulCookie != __DIRENT_COOKIE) {158 errno = EINVAL;159 return;160 }161 162 /* close the WINDOWS32 directory handle */163 if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)164 if (!FindClose(pDir->dir_hDirHandle))165 errno = EBADF;166 167 /* reset members which control readdir() */168 pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;169 pDir->dir_nNumFiles = 0;170 171 return;150 if (!pDir) { 151 errno = EINVAL; 152 return; 153 } 154 155 /* sanity check that this is a DIR pointer */ 156 if (pDir->dir_ulCookie != __DIRENT_COOKIE) { 157 errno = EINVAL; 158 return; 159 } 160 161 /* close the WINDOWS32 directory handle */ 162 if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE) 163 if (!FindClose(pDir->dir_hDirHandle)) 164 errno = EBADF; 165 166 /* reset members which control readdir() */ 167 pDir->dir_hDirHandle = INVALID_HANDLE_VALUE; 168 pDir->dir_nNumFiles = 0; 169 170 return; 172 171 } 173 172 … … 175 174 telldir(DIR* pDir) 176 175 { 177 if (!pDir) {178 errno = EINVAL;179 return -1;180 }181 182 /* sanity check that this is a DIR pointer */183 if (pDir->dir_ulCookie != __DIRENT_COOKIE) {184 errno = EINVAL;185 return -1;186 }187 188 /* return number of times readdir() called */189 return pDir->dir_nNumFiles;176 if (!pDir) { 177 errno = EINVAL; 178 return -1; 179 } 180 181 /* sanity check that this is a DIR pointer */ 182 if (pDir->dir_ulCookie != __DIRENT_COOKIE) { 183 errno = EINVAL; 184 return -1; 185 } 186 187 /* return number of times readdir() called */ 188 return pDir->dir_nNumFiles; 190 189 } 191 190 … … 193 192 seekdir(DIR* pDir, long nPosition) 194 193 { 195 if (!pDir)196 return;197 198 /* sanity check that this is a DIR pointer */199 if (pDir->dir_ulCookie != __DIRENT_COOKIE)200 return;201 202 /* go back to beginning of directory */203 rewinddir(pDir);204 205 /* loop until we have found position we care about */206 for (--nPosition; nPosition && readdir(pDir); nPosition--);207 208 /* flag invalid nPosition value */209 if (nPosition)210 errno = EINVAL;211 212 return;213 } 194 if (!pDir) 195 return; 196 197 /* sanity check that this is a DIR pointer */ 198 if (pDir->dir_ulCookie != __DIRENT_COOKIE) 199 return; 200 201 /* go back to beginning of directory */ 202 rewinddir(pDir); 203 204 /* loop until we have found position we care about */ 205 for (--nPosition; nPosition && readdir(pDir); nPosition--); 206 207 /* flag invalid nPosition value */ 208 if (nPosition) 209 errno = EINVAL; 210 211 return; 212 }  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  