~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: 2008-11-20 21:56:00 UTC
  • mfrom: (1.1.3 upstream) (2.2.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20081120215600-0jujiv17a2ja92xu
Tags: 2008.11.18-130226-1
* Replacing obsolete dh_clean -k with dh_prep.
* Merging upstream version 2008.11.18-130226.
* Updating debian directory for addition of pvscsi and vmxnet3 modules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1834
1834
   ASSERT(searchPath);
1835
1835
   ASSERT(elem);
1836
1836
 
1837
 
   newPath = Str_SafeAsprintf(NULL, "%s" FILE_SEARCHPATHTOKEN "%s",
1838
 
                          elem, searchPath);
 
1837
   newPath = Str_SafeAsprintf(NULL, "%s%s%s", elem, FILE_SEARCHPATHTOKEN,
 
1838
                              searchPath);
1839
1839
 
1840
1840
   n = strlen(elem);
1841
1841
   path = newPath + n + 1;
1885
1885
                          const char *cwd,          // IN
1886
1886
                          char **result)            // OUT
1887
1887
{
1888
 
   Bool found = FALSE;
1889
 
   char *cur = NULL;
 
1888
   char *cur;
 
1889
   char *tok;
 
1890
   Bool found;
 
1891
   char *saveptr;
1890
1892
   char *sp = NULL;
1891
1893
   char *file = NULL;
1892
 
   char *tok;
1893
1894
 
1894
1895
   ASSERT(fileIn);
1895
1896
   ASSERT(cwd);
1896
1897
   ASSERT(searchPath);
1897
1898
 
1898
1899
   /*
1899
 
    * First check the usual places, the fullpath, and the cwd.
 
1900
    * First check the usual places - the fullpath or the cwd.
1900
1901
    */
1901
1902
 
1902
1903
   if (File_IsFullPath(fileIn)) {
1903
1904
      cur = Util_SafeStrdup(fileIn);
1904
1905
   } else {
1905
 
      cur = Str_SafeAsprintf(NULL, "%s"DIRSEPS"%s", cwd, fileIn);
 
1906
      cur = Str_SafeAsprintf(NULL, "%s%s%s", cwd, DIRSEPS, fileIn);
1906
1907
   }
1907
1908
 
1908
1909
   if (File_Exists(cur)) {
1909
 
      goto found;
 
1910
      goto done;
1910
1911
   }
 
1912
 
1911
1913
   free(cur);
 
1914
   cur = NULL;
1912
1915
 
1913
1916
   /*
1914
1917
    * Didn't find it in the usual places so strip it to its bare minimum and
1915
1918
    * start searching.
1916
1919
    */
 
1920
 
1917
1921
   File_GetPathName(fileIn, NULL, &file);
1918
1922
 
1919
1923
   sp = Util_SafeStrdup(searchPath);
1920
 
   tok = strtok(sp, FILE_SEARCHPATHTOKEN);
 
1924
   tok = strtok_r(sp, FILE_SEARCHPATHTOKEN, &saveptr);
1921
1925
 
1922
1926
   while (tok) {
1923
1927
      if (File_IsFullPath(tok)) {
1927
1931
         /* Relative Path.  Prepend the cwd. */
1928
1932
         if (Str_Strcasecmp(tok, ".") == 0) {
1929
1933
            /* Don't append "." */
1930
 
            cur = Str_SafeAsprintf(NULL, "%s"DIRSEPS"%s", cwd, file);
 
1934
            cur = Str_SafeAsprintf(NULL, "%s%s%s", cwd, DIRSEPS, file);
1931
1935
         } else {
1932
 
            cur = Str_SafeAsprintf(NULL, "%s"DIRSEPS"%s"DIRSEPS"%s", cwd,
1933
 
                                   tok, file);
 
1936
            cur = Str_SafeAsprintf(NULL, "%s%s%s%s%s", cwd, DIRSEPS, tok,
 
1937
                                   DIRSEPS, file);
1934
1938
         }
1935
1939
      }
1936
1940
 
1937
1941
      if (File_Exists(cur)) {
1938
 
         goto found;
1939
 
      }
1940
 
      free(cur);
1941
 
      tok = strtok(NULL, FILE_SEARCHPATHTOKEN);
1942
 
   }
1943
 
 
1944
 
  exit:
 
1942
         break;
 
1943
      }
 
1944
 
 
1945
      free(cur);
 
1946
      cur = NULL;
 
1947
 
 
1948
      tok = strtok_r(NULL, FILE_SEARCHPATHTOKEN, &saveptr);
 
1949
   }
 
1950
 
 
1951
done:
 
1952
   if (cur) {
 
1953
      found = TRUE;
 
1954
 
 
1955
      if (result) {
 
1956
         *result = File_FullPath(cur);
 
1957
 
 
1958
         if (*result == NULL) {
 
1959
            found = FALSE;
 
1960
         }
 
1961
      }
 
1962
 
 
1963
      free(cur);
 
1964
   } else {
 
1965
      found = FALSE;
 
1966
   }
 
1967
 
1945
1968
   free(sp);
1946
1969
   free(file);
 
1970
 
1947
1971
   return found;
1948
 
 
1949
 
  found:
1950
 
   ASSERT(cur);
1951
 
   found = TRUE;
1952
 
   if (result) {
1953
 
      *result = File_FullPath(cur);
1954
 
 
1955
 
      if (*result == NULL) {
1956
 
         found = FALSE;
1957
 
      }
1958
 
   }
1959
 
   free(cur);
1960
 
   goto exit;
1961
1972
}
1962
1973
 
1963
1974