~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/file/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-30 12:56:49 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730125649-97sfj5li8axiseoo
Tags: 2009.07.22-179896-2
* Temporarily building without dumbnet, the recently uploaded
  new dumbnet upstream version broke down (Closes: #539006).
* Using more common name to store local debian additions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "safetime.h"
31
31
#if defined(_WIN32)
32
32
#include <io.h>
 
33
#define S_IXUSR    0100
33
34
#else
34
35
#include <unistd.h>
35
36
#endif
149
150
 
150
151
 
151
152
/*
 
153
 *-----------------------------------------------------------------------------
 
154
 *
 
155
 * File_GetFilePermissions --
 
156
 *
 
157
 *      Return the read / write / execute permissions of a file.
 
158
 *
 
159
 * Results:
 
160
 *      TRUE if success, FALSE otherwise.
 
161
 *
 
162
 * Side effects:
 
163
 *      None
 
164
 *
 
165
 *-----------------------------------------------------------------------------
 
166
 */
 
167
 
 
168
Bool
 
169
File_GetFilePermissions(ConstUnicode pathName,  // IN:
 
170
                        int *mode)              // OUT: file mode
 
171
{
 
172
   FileData fileData;
 
173
 
 
174
   ASSERT(mode);
 
175
   if (FileAttributes(pathName, &fileData) != 0) {
 
176
      return FALSE;
 
177
   }
 
178
   *mode = fileData.fileMode;
 
179
#ifdef _WIN32
 
180
      /*
 
181
       *  On Win32 implementation of FileAttributes does not return execution bit.
 
182
       */
 
183
      if (FileIO_Access(pathName, FILEIO_ACCESS_EXEC) == FILEIO_SUCCESS) {
 
184
         *mode |= S_IXUSR;
 
185
      }
 
186
#endif
 
187
   return TRUE;
 
188
}
 
189
 
 
190
 
 
191
/*
152
192
 *----------------------------------------------------------------------
153
193
 *
154
194
 * File_Unlink --
1674
1714
}
1675
1715
 
1676
1716
 
 
1717
/*
 
1718
 *-----------------------------------------------------------------------------
 
1719
 *
 
1720
 * File_MapPathPrefix --
 
1721
 *
 
1722
 *      Given a path and a newPrefix -> oldPrefix mapping, transform
 
1723
 *      oldPath according to the mapping.
 
1724
 *
 
1725
 * Results:
 
1726
 *      The new path, or NULL if there is no mapping.
 
1727
 *
 
1728
 * Side effects:
 
1729
 *      The returned string is allocated, free it.
 
1730
 *
 
1731
 *-----------------------------------------------------------------------------
 
1732
 */
 
1733
 
 
1734
char *
 
1735
File_MapPathPrefix(const char *oldPath,               // IN
 
1736
                   const char **oldPrefixes,          // IN
 
1737
                   const char **newPrefixes,          // IN
 
1738
                   size_t numPrefixes)                // IN
 
1739
{
 
1740
   int i;
 
1741
   size_t oldPathLen = strlen(oldPath);
 
1742
 
 
1743
   for (i = 0; i < numPrefixes; i++) {
 
1744
      char *newPath;
 
1745
      char *oldPrefix;
 
1746
      char *newPrefix;
 
1747
      size_t oldPrefixLen;
 
1748
 
 
1749
      oldPrefix = File_StripSlashes(oldPrefixes[i]);
 
1750
      newPrefix = File_StripSlashes(newPrefixes[i]);
 
1751
      oldPrefixLen = strlen(oldPrefix);
 
1752
 
 
1753
      /*
 
1754
       * If the prefix matches on a DIRSEPS boundary, or the prefix is the
 
1755
       * whole string, replace it.
 
1756
       * If we don't insist on matching a whole directory name, we could
 
1757
       * mess things of if one directory is a substring of another.
 
1758
       */
 
1759
 
 
1760
      if (oldPathLen >= oldPrefixLen &&
 
1761
          memcmp(oldPath, oldPrefix, oldPrefixLen) == 0
 
1762
          && (strchr(VALID_DIRSEPS, oldPath[oldPrefixLen]) ||
 
1763
              oldPath[oldPrefixLen] == '\0')) {
 
1764
         size_t newPrefixLen = strlen(newPrefix);
 
1765
         size_t newPathLen = (oldPathLen - oldPrefixLen) + newPrefixLen;
 
1766
 
 
1767
         ASSERT(newPathLen > 0);
 
1768
         ASSERT(oldPathLen >= oldPrefixLen);
 
1769
 
 
1770
         newPath = Util_SafeMalloc((newPathLen + 1) * sizeof(char));
 
1771
         memcpy(newPath, newPrefix, newPrefixLen);
 
1772
         memcpy(newPath + newPrefixLen, oldPath + oldPrefixLen,
 
1773
                oldPathLen - oldPrefixLen + 1);
 
1774
         /*
 
1775
          * It should only match once.  Weird self-referencing mappings
 
1776
          * aren't allowed.
 
1777
          */
 
1778
         free(oldPrefix);
 
1779
         free(newPrefix);
 
1780
         return newPath;
 
1781
      }
 
1782
      free(oldPrefix);
 
1783
      free(newPrefix);
 
1784
   }
 
1785
 
 
1786
   return NULL;
 
1787
}
 
1788
 
 
1789
 
1677
1790
#if !defined(N_PLAT_NLM)
1678
1791
/*
1679
1792
 *----------------------------------------------------------------------------