Changeset 1194


Ignore:
Timestamp:
Oct 6, 2007, 3:59:35 AM (18 years ago)
Author:
bird
Message:

Fixed a couple of slash problems in cp and install (dos based systems).

Location:
trunk/src/kmk/kmkbuiltin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/kmk/kmkbuiltin/cp.c

    r1183 r1194  
    100100#endif
    101101
     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
    102108#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]))   \
    104110                *--(p).p_end = 0;                                       \
    105111}
     
    257263                *to.p_end = 0;
    258264        }
    259         have_trailing_slash = (to.p_end[-1] == '/');
     265        have_trailing_slash = IS_SLASH(to.p_end[-1]);
    260266        if (have_trailing_slash)
    261267                STRIP_TRAILING_SLASH(to);
     
    388394                                if (type != DIR_TO_DNE) {
    389395                                        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
    390400                                        base = (p == NULL) ? 0 :
    391401                                            (int)(p - curr->fts_path + 1);
     
    401411                        nlen = curr->fts_pathlen - base;
    402412                        target_mid = to.target_end;
    403                         if (*p != '/' && target_mid[-1] != '/')
     413                        if (!IS_SLASH(*p) && !IS_SLASH(target_mid[-1]))
    404414                                *target_mid++ = '/';
    405415                        *target_mid = 0;
  • TabularUnified trunk/src/kmk/kmkbuiltin/install.c

    r1193 r1194  
    115115#endif
    116116
     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
    117123static gid_t gid;
    118124static uid_t uid;
     
    141147#endif
    142148static int      usage(FILE *);
     149static char    *last_slash(const char *);
    143150
    144151int
     
    389396                        (void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s",
    390397                            to_name,
    391                             (p = strrchr(from_name, '/')) ? ++p : from_name);
     398                            (p = last_slash(from_name)) ? ++p : from_name);
    392399                        to_name = pathbuf;
    393400                }
     
    744751        (void)strncpy(temp, path, tsize);
    745752        temp[tsize - 1] = '\0';
    746         if ((p = strrchr(temp, '/')) != NULL)
     753        if ((p = last_slash(temp)) != NULL)
    747754                p++;
    748755        else
     
    915922
    916923        for (p = path;; ++p)
    917                 if (!*p || (p != path && *p  == '/')) {
     924                if (!*p || (p != path && IS_SLASH(*p))) {
    918925                        ch = *p;
    919926                        *p = '\0';
     
    981988}
    982989#endif
     990
     991/* figures out where the last slash or colon is. */
     992static char *
     993last_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.