~ubuntu-branches/ubuntu/oneiric/luatex/oneiric

« back to all changes in this revision

Viewing changes to source/texk/kpathsea/xgetcwd.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2011-04-10 21:08:04 UTC
  • mfrom: (0.3.1) (1.6.1) (19.1.5 natty)
  • Revision ID: package-import@ubuntu.com-20110410210804-m979ehyw4hnzvhu3
Tags: 0.65.0-1ubuntu3
RebuildĀ againstĀ libpoppler13.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
                                       -- Olaf Weber <infovore@xs4all.nl */
50
50
#if defined (HAVE_GETCWD) && !defined (GETCWD_FORKS)
51
51
    string path = (string)xmalloc(PATH_MAX + 1);
52
 
  
 
52
 
53
53
    if (getcwd (path, PATH_MAX + 1) == 0) {
54
54
        fprintf(stderr, "getcwd: %s", path);
55
55
        exit(EXIT_FAILURE);
56
56
    }
57
 
    
 
57
 
58
58
    return path;
59
59
#elif defined (HAVE_GETWD)
60
60
    string path = (string)xmalloc(PATH_MAX + 1);
61
 
    
 
61
 
62
62
    if (getwd (path) == 0) {
63
63
        fprintf(stderr, "getwd: %s", path);
64
64
        exit(EXIT_FAILURE);
65
65
    }
66
 
  
 
66
 
67
67
    return path;
68
68
#else /* not HAVE_GETCWD && not HAVE_GETWD */
69
69
    struct stat root_stat, cwd_stat;
70
70
    string cwd_path = (string)xmalloc(2); /* In case we assign "/" below.  */
71
 
  
 
71
 
72
72
    *cwd_path = 0;
73
 
  
 
73
 
74
74
    /* Find the inodes of the root and current directories.  */
75
75
    root_stat = xstat("/");
76
76
    cwd_stat  = xstat(".");
81
81
        struct dirent *e;
82
82
        DIR *parent_dir;
83
83
        boolean found = false;
84
 
        
 
84
 
85
85
        xchdir("..");
86
86
        parent_dir = xopendir(".");
87
87
 
90
90
        while ((e = readdir (parent_dir)) != NULL && !found) {
91
91
            struct stat test_stat;
92
92
            test_stat = xlstat(e->d_name);
93
 
            
 
93
 
94
94
            if (SAME_FILE_P(test_stat, cwd_stat)) {
95
95
                /* We've found it.  Prepend the pathname.  */
96
96
                string temp = cwd_path;
97
97
                cwd_path = concat3("/", e->d_name, cwd_path);
98
98
                free(temp);
99
 
              
 
99
 
100
100
                /* Set up to test the next parent.  */
101
101
                cwd_stat = xstat(".");
102
 
              
 
102
 
103
103
                /* Stop reading this directory.  */
104
104
                found = true;
105
105
            }
107
107
        if (!found)
108
108
            LIB_FATAL2("No inode %d/device %d in parent directory",
109
109
                   cwd_stat.st_ino, cwd_stat.st_dev);
110
 
      
 
110
 
111
111
        xclosedir(parent_dir);
112
112
    }
113
 
  
 
113
 
114
114
    /* If the current directory is the root, cwd_path will be the empty
115
115
       string, and we will have not gone through the loop.  */
116
116
    if (*cwd_path == 0)
122
122
#ifdef DOSISH
123
123
    /* Prepend the drive letter to CWD_PATH, since this technique
124
124
       never tells us what the drive is.
125
 
 
 
125
 
126
126
       Note that on MS-DOS/MS-Windows, the branch that works around
127
127
       missing `getwd' will probably only work for DJGPP (which does
128
128
       have `getwd'), because only DJGPP reports meaningful
130
130
    {
131
131
        char drive[3];
132
132
        string temp = cwd_path;
133
 
    
 
133
 
134
134
        /* Make the drive letter lower-case, unless it is beyond Z: (yes,
135
135
           there ARE such drives, in case of Novell Netware on MS-DOS).  */
136
136
        drive[0] = root_stat.st_dev + (root_stat.st_dev < 26 ? 'a' : 'A');
137
137
        drive[1] = ':';
138
138
        drive[2] = '\0';
139
 
        
 
139
 
140
140
        cwd_path = concat(drive, cwd_path);
141
141
        free(temp);
142
142
    }