~ubuntu-branches/debian/jessie/acfax/jessie

« back to all changes in this revision

Viewing changes to .pc/remove-getwd.patch/Directory.c

  • Committer: Package Import Robot
  • Author(s): Colin Tuckley
  • Date: 2014-02-10 20:23:51 UTC
  • Revision ID: package-import@ubuntu.com-20140210202351-id1r9lub15jv2dti
Tags: 981011-16
* Convert to source format 3.0 (quilt)
* Remove refs to unused and deprecated getwd
* Change Arch to linux-any since osspd isn't available elsewhere
* Fix various implicit def warnings by adding required .h file includes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 
 
3
        Directory.c
 
4
 
 
5
        This file contains the C code that implements the directory
 
6
        iteration and file information subsystem.
 
7
 
 
8
        This code is intended to be used as a convenient, machine
 
9
        independent interface to iterate through the contents of a
 
10
        directory.
 
11
 
 
12
 ****************************************************************************/
 
13
 
 
14
/*
 
15
 * Author:
 
16
 *      Brian Totty
 
17
 *      Department of Computer Science
 
18
 *      University Of Illinois at Urbana-Champaign
 
19
 *      1304 West Springfield Avenue
 
20
 *      Urbana, IL 61801
 
21
 * 
 
22
 *      totty@cs.uiuc.edu
 
23
 *      
 
24
 */ 
 
25
 
 
26
#include "Directory.h"
 
27
#include "RegExp.h"
 
28
 
 
29
/*--------------------------------------------------------------------------*
 
30
 
 
31
        L O W    L E V E L    D I R E C T O R Y    I N T E R F A C E
 
32
 
 
33
 *--------------------------------------------------------------------------*/
 
34
 
 
35
int DirectoryOpen(dir_name,dp)
 
36
char *dir_name;
 
37
Directory *dp;
 
38
{
 
39
        if (DirectoryPathExpand(dir_name,DirectoryPath(dp)) == NULL)
 
40
        {
 
41
                return(FALSE);
 
42
        }
 
43
        DirectoryDir(dp) = opendir(DirectoryPath(dp));
 
44
        if (DirectoryDir(dp) == NULL) return(FALSE);
 
45
        return(TRUE);
 
46
} /* End DirectoryOpen */
 
47
 
 
48
 
 
49
void DirectoryRestart(dp)
 
50
Directory *dp;
 
51
{
 
52
        rewinddir(DirectoryDir(dp));
 
53
} /* End DirectoryRestart */
 
54
 
 
55
 
 
56
void DirectoryClose(dp)
 
57
Directory *dp;
 
58
{
 
59
        closedir(DirectoryDir(dp));
 
60
} /* End DirectoryClose */
 
61
 
 
62
 
 
63
long DirectoryTellPosition(dp)
 
64
Directory *dp;
 
65
{
 
66
        return(telldir(DirectoryDir(dp)));
 
67
} /* End DirectoryTellPosition */
 
68
 
 
69
 
 
70
void DirectorySetPosition(dp,pos)
 
71
Directory *dp;
 
72
long pos;
 
73
{
 
74
        seekdir(dp->filep,pos);
 
75
} /* End DirectorySetPosition */
 
76
 
 
77
 
 
78
int DirectoryReadNextEntry(dp,de)
 
79
Directory *dp;
 
80
DirEntry *de;
 
81
{
 
82
        u_short orig_file_type;
 
83
        static struct dirent *_ep;
 
84
        static struct stat _lstats,_stats;
 
85
        char full_path[MAXPATHLEN + 2];
 
86
 
 
87
        _ep = readdir(DirectoryDir(dp));
 
88
        if (_ep == NULL) return(FALSE);
 
89
        strcpy(DirEntryFileName(de),_ep->d_name);
 
90
        strcpy(full_path,DirectoryPath(dp));
 
91
        strcat(full_path,DirEntryFileName(de));
 
92
 
 
93
        if (lstat(full_path,&_lstats) != 0) return(FALSE);
 
94
 
 
95
        orig_file_type = _lstats.st_mode & S_IFMT;
 
96
        switch (orig_file_type)
 
97
        {
 
98
            case S_IFDIR:
 
99
                DirEntryType(de) = F_TYPE_DIR;
 
100
                break;
 
101
            case S_IFREG:
 
102
                DirEntryType(de) = F_TYPE_FILE;
 
103
                break;
 
104
            case S_IFCHR:
 
105
                DirEntryType(de) = F_TYPE_CHAR_SPECIAL;
 
106
                break;
 
107
            case S_IFBLK:
 
108
                DirEntryType(de) = F_TYPE_BLOCK_SPECIAL;
 
109
                break;
 
110
            case S_IFLNK:
 
111
                DirEntryType(de) = F_TYPE_SYM_LINK;
 
112
                break;
 
113
            case S_IFSOCK:
 
114
                DirEntryType(de) = F_TYPE_SOCKET;
 
115
                break;
 
116
#ifdef S_IFIFO
 
117
            case S_IFIFO:
 
118
                DirEntryType(de) = F_TYPE_FIFO;
 
119
                break;
 
120
#endif
 
121
            default:
 
122
                DirEntryType(de) = orig_file_type;
 
123
                break;
 
124
        }
 
125
 
 
126
        DirEntryIsBrokenLink(de) = FALSE;
 
127
        DirEntryIsDirectoryLink(de) = FALSE;
 
128
        if (DirEntryIsSymLink(de))                      /* Symbolic Link */
 
129
        {
 
130
                if (stat(full_path,&_stats) != 0)       /* Can't Stat File */
 
131
                {
 
132
                        DirEntryIsBrokenLink(de) = TRUE;
 
133
                        _stats = _lstats;
 
134
                }
 
135
                    else                                /* Link Not Broken */
 
136
                {
 
137
#ifdef SLOW_DIRLINK_TEST
 
138
                        char temp_path[MAXPATHLEN + 2];
 
139
 
 
140
                        if (DirectoryPathExpand(full_path,temp_path) != NULL)
 
141
                        {
 
142
#else
 
143
                        if ((_stats.st_mode & S_IFMT) == S_IFDIR)
 
144
                        {
 
145
#endif
 
146
                                DirEntryIsDirectoryLink(de) = TRUE;
 
147
                        }
 
148
 
 
149
                }
 
150
        }
 
151
            else                                        /* Not Symbolic Link */
 
152
        {
 
153
                _stats = _lstats;
 
154
        }
 
155
 
 
156
        FileInfoOrigMode(DirEntrySelfInfo(de)) = _lstats.st_mode;
 
157
        FileInfoProt(DirEntrySelfInfo(de)) = _lstats.st_mode & 0777;
 
158
        FileInfoUserID(DirEntrySelfInfo(de)) = _lstats.st_uid;
 
159
        FileInfoGroupID(DirEntrySelfInfo(de)) = _lstats.st_gid;
 
160
        FileInfoFileSize(DirEntrySelfInfo(de)) = _lstats.st_size;
 
161
        FileInfoLastAccess(DirEntrySelfInfo(de)) = _lstats.st_atime;
 
162
        FileInfoLastModify(DirEntrySelfInfo(de)) = _lstats.st_mtime;
 
163
        FileInfoLastStatusChange(DirEntrySelfInfo(de)) = _lstats.st_ctime;
 
164
 
 
165
        FileInfoOrigMode(DirEntryActualInfo(de)) = _stats.st_mode;
 
166
        FileInfoProt(DirEntryActualInfo(de)) = _stats.st_mode & 0777;
 
167
        FileInfoUserID(DirEntryActualInfo(de)) = _stats.st_uid;
 
168
        FileInfoGroupID(DirEntryActualInfo(de)) = _stats.st_gid;
 
169
        FileInfoFileSize(DirEntryActualInfo(de)) = _stats.st_size;
 
170
        FileInfoLastAccess(DirEntryActualInfo(de)) = _stats.st_atime;
 
171
        FileInfoLastModify(DirEntryActualInfo(de)) = _stats.st_mtime;
 
172
        FileInfoLastStatusChange(DirEntryActualInfo(de)) = _stats.st_ctime;
 
173
 
 
174
        return(TRUE);
 
175
} /* End DirectoryReadNextEntry */
 
176
 
 
177
 
 
178
char *DirectoryPathExpand(old_path,new_path)
 
179
char *old_path,*new_path;
 
180
{
 
181
        register char *p;
 
182
        char path[MAXPATHLEN + 2];
 
183
 
 
184
        if (getwd(path) == NULL) return(NULL);
 
185
        if (chdir(old_path) != 0) return(NULL);
 
186
        if (getwd(new_path) == NULL) strcpy(new_path,old_path);
 
187
        if (chdir(path) != 0) return(NULL);
 
188
        for (p = new_path; *p != '\0'; p++);
 
189
        /* append trailing slash if not already in place... */
 
190
        if ((p != new_path) && *(p - 1) != '/')
 
191
        {
 
192
                *p++ = '/';
 
193
                *p = '\0';
 
194
        }
 
195
        return(new_path);
 
196
} /* End DirectoryPathExpand */
 
197
 
 
198
 
 
199
/*---------------------------------------------------------------------------*
 
200
 
 
201
             D I R E C T O R Y    E N T R Y    R O U T I N E S
 
202
 
 
203
 *---------------------------------------------------------------------------*/
 
204
 
 
205
void DirEntryDump(fp,de)
 
206
FILE *fp;
 
207
DirEntry *de;
 
208
{
 
209
        fprintf(fp,"%20s, Size %7d, Prot %3o\n",
 
210
                DirEntryFileName(de),DirEntryFileSize(de),DirEntryProt(de));
 
211
} /* End DirEntryDump */