Changeset 1194
- Timestamp:
- Oct 6, 2007, 3:59:35 AM (18 years ago)
- Location:
- trunk/src/kmk/kmkbuiltin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/kmk/kmkbuiltin/cp.c ¶
r1183 r1194 100 100 #endif 101 101 102 #if defined(__WIN32__) || defined(__WIN64__) || defined(__OS2__) 103 # define IS_SLASH(ch) ((ch) == '/' || (ch) == '\\') 104 #else 105 # define IS_SLASH(ch) ((ch) == '/') 106 #endif 107 102 108 #define STRIP_TRAILING_SLASH(p) { \ 103 while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \109 while ((p).p_end > (p).p_path + 1 && IS_SLASH((p).p_end[-1])) \ 104 110 *--(p).p_end = 0; \ 105 111 } … … 257 263 *to.p_end = 0; 258 264 } 259 have_trailing_slash = (to.p_end[-1] == '/');265 have_trailing_slash = IS_SLASH(to.p_end[-1]); 260 266 if (have_trailing_slash) 261 267 STRIP_TRAILING_SLASH(to); … … 388 394 if (type != DIR_TO_DNE) { 389 395 p = strrchr(curr->fts_path, '/'); 396 #if defined(__WIN32__) || defined(__WIN64__) || defined(__OS2__) 397 if (strrchr(curr->fts_path, '\\') > p) 398 p = strrchr(curr->fts_path, '\\'); 399 #endif 390 400 base = (p == NULL) ? 0 : 391 401 (int)(p - curr->fts_path + 1); … … 401 411 nlen = curr->fts_pathlen - base; 402 412 target_mid = to.target_end; 403 if ( *p != '/' && target_mid[-1] != '/')413 if (!IS_SLASH(*p) && !IS_SLASH(target_mid[-1])) 404 414 *target_mid++ = '/'; 405 415 *target_mid = 0; -
TabularUnified trunk/src/kmk/kmkbuiltin/install.c ¶
r1193 r1194 115 115 #endif 116 116 117 #if defined(__WIN32__) || defined(__WIN64__) || defined(__OS2__) 118 # define IS_SLASH(ch) ((ch) == '/' || (ch) == '\\') 119 #else 120 # define IS_SLASH(ch) ((ch) == '/') 121 #endif 122 117 123 static gid_t gid; 118 124 static uid_t uid; … … 141 147 #endif 142 148 static int usage(FILE *); 149 static char *last_slash(const char *); 143 150 144 151 int … … 389 396 (void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s", 390 397 to_name, 391 (p = strrchr(from_name, '/')) ? ++p : from_name);398 (p = last_slash(from_name)) ? ++p : from_name); 392 399 to_name = pathbuf; 393 400 } … … 744 751 (void)strncpy(temp, path, tsize); 745 752 temp[tsize - 1] = '\0'; 746 if ((p = strrchr(temp, '/')) != NULL)753 if ((p = last_slash(temp)) != NULL) 747 754 p++; 748 755 else … … 915 922 916 923 for (p = path;; ++p) 917 if (!*p || (p != path && *p == '/')) {924 if (!*p || (p != path && IS_SLASH(*p))) { 918 925 ch = *p; 919 926 *p = '\0'; … … 981 988 } 982 989 #endif 990 991 /* figures out where the last slash or colon is. */ 992 static char * 993 last_slash(const char *path) 994 { 995 #if defined(__WIN32__) || defined(__WIN64__) || defined(__OS2__) 996 char *p = (char *)strrchr(path, '/'); 997 if (p) 998 { 999 char *p2 = strrchr(p, '\\'); 1000 if (p2) 1001 p = p2; 1002 } 1003 else 1004 { 1005 p = (char *)strrchr(path, '\\'); 1006 if (!p && isalpha(path[0]) && path[1] == ':') 1007 p = (char *)&path[1]; 1008 } 1009 return p; 1010 #else 1011 return strrchr(path, '/'); 1012 #endif 1013 } 1014
Note:
See TracChangeset
for help on using the changeset viewer.