Changeset 1108 in kBuild for trunk/src/kmk/kmkbuiltin
- Timestamp:
- Sep 23, 2007 8:33:10 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/mscfakes.c
r936 r1108 31 31 #include <io.h> 32 32 #include <fcntl.h> 33 #include <sys/stat.h> 33 34 #include "err.h" 34 35 #include "mscfakes.h" 36 37 #define timeval windows_timeval 38 #include <Windows.h> 39 #undef timeval 35 40 36 41 … … 55 60 if (rc) 56 61 { 57 int len = strlen(path);62 size_t len = strlen(path); 58 63 if (len > 0 && (path[len - 1] == '/' || path[len - 1] == '\\')) 59 64 { … … 73 78 if (rc) 74 79 { 75 int len = strlen(path);80 size_t len = strlen(path); 76 81 if (len > 0 && (path[len - 1] == '/' || path[len - 1] == '\\')) 77 82 { … … 126 131 127 132 133 /** Unix to DOS. */ 134 static char *fix_slashes(char *psz) 135 { 136 char *pszRet = psz; 137 for (; *psz; psz++) 138 if (*psz == '/') 139 *psz = '\\'; 140 return pszRet; 141 } 142 143 144 /** Calcs the SYMBOLIC_LINK_FLAG_DIRECTORY flag for CreatesymbolcLink. */ 145 static DWORD is_directory(const char *pszPath, const char *pszRelativeTo) 146 { 147 size_t cchPath = strlen(pszPath); 148 struct stat st; 149 if (cchPath > 0 && pszPath[cchPath - 1] == '\\' || pszPath[cchPath - 1] == '/') 150 return 1; /* SYMBOLIC_LINK_FLAG_DIRECTORY */ 151 152 if (stat(pszPath, &st)) 153 { 154 size_t cchRelativeTo = strlen(pszRelativeTo); 155 char *psz = malloc(cchPath + cchRelativeTo + 4); 156 memcpy(psz, pszRelativeTo, cchRelativeTo); 157 memcpy(psz + cchRelativeTo, "\\", 1); 158 memcpy(psz + cchRelativeTo + 1, pszPath, cchPath + 1); 159 if (stat(pszPath, &st)) 160 st.st_mode = _S_IFREG; 161 free(psz); 162 } 163 164 return (st.st_mode & _S_IFMT) == _S_IFDIR ? 1 : 0; 165 } 166 167 128 168 int symlink(const char *pszDst, const char *pszLink) 129 169 { 170 static BOOL (WINAPI *s_pfnCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD) = 0; 171 static BOOL s_fTried = FALSE; 172 173 if (!s_fTried) 174 { 175 HMODULE hmod = LoadLibrary("KERNEL32.DLL"); 176 if (hmod) 177 *(FARPROC *)&s_pfnCreateSymbolicLinkA = GetProcAddress(hmod, "CreateSymbolicLinkA"); 178 s_fTried = TRUE; 179 } 180 181 if (s_pfnCreateSymbolicLinkA) 182 { 183 char *pszDstCopy = fix_slashes(strdup(pszDst)); 184 char *pszLinkCopy = fix_slashes(strdup(pszLink)); 185 BOOL fRc = s_pfnCreateSymbolicLinkA(pszLinkCopy, pszDstCopy, 186 is_directory(pszDstCopy, pszLinkCopy)); 187 DWORD err = GetLastError(); 188 free(pszDstCopy); 189 free(pszLinkCopy); 190 if (fRc) 191 return 0; 192 switch (err) 193 { 194 case ERROR_NOT_SUPPORTED: errno = ENOSYS; break; 195 case ERROR_ALREADY_EXISTS: 196 case ERROR_FILE_EXISTS: errno = EEXIST; break; 197 case ERROR_DIRECTORY: errno = ENOTDIR; break; 198 case ERROR_ACCESS_DENIED: 199 case ERROR_PRIVILEGE_NOT_HELD: errno = EPERM; break; 200 default: errno = EINVAL; break; 201 } 202 return -1; 203 } 204 130 205 errno = ENOSYS; 131 206 err(1, "symlink() is not implemented on windows!"); … … 160 235 for (i = 0; i < count; i++) 161 236 { 162 int cb = write(fd, vector[i].iov_base,vector[i].iov_len);237 int cb = (int)write(fd, vector[i].iov_base, (int)vector[i].iov_len); 163 238 if (cb < 0) 164 239 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.