comparison mercurial/osutil.c @ 5398:ecde0b7e0b3f

osutil.c: use readdir instead of readdir64 Some systems (e.g. *BSD) don't have a readdir64 function - the regular readdir already uses 64-bit types. On other systems (Linux, Solaris, ...), if Python was compiled with large file support, Python.h will define _LARGEFILE_SOURCE and _FILE_OFFSET_BITS=64, so that any call to readdir will actually be a call to readdir64. If Python was not compiled with large file support, we probably don't want to define these macros to avoid ABI problems.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sat, 06 Oct 2007 14:14:11 -0300
parents 11caa374f497
children ca890c0c3f1f
comparison
equal deleted inserted replaced
5397:11caa374f497 5398:ecde0b7e0b3f
6 This software may be used and distributed according to the terms of 6 This software may be used and distributed according to the terms of
7 the GNU General Public License, incorporated herein by reference. 7 the GNU General Public License, incorporated herein by reference.
8 */ 8 */
9 9
10 #define _ATFILE_SOURCE 10 #define _ATFILE_SOURCE
11 #define _LARGEFILE64_SOURCE
12 #include <Python.h> 11 #include <Python.h>
13 #include <alloca.h> 12 #include <alloca.h>
14 #include <dirent.h> 13 #include <dirent.h>
15 #include <fcntl.h> 14 #include <fcntl.h>
16 #include <string.h> 15 #include <string.h>
111 } 110 }
112 111
113 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) 112 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
114 { 113 {
115 DIR *dir = NULL; 114 DIR *dir = NULL;
116 struct dirent64 *ent; 115 struct dirent *ent;
117 PyObject *list = NULL; 116 PyObject *list = NULL;
118 PyObject *ctor_args = NULL; 117 PyObject *ctor_args = NULL;
119 int all_kinds = 1; 118 int all_kinds = 1;
120 char *full_path; 119 char *full_path;
121 int path_len; 120 int path_len;
144 143
145 full_path = alloca(path_len + PATH_MAX + 2); 144 full_path = alloca(path_len + PATH_MAX + 2);
146 memcpy(full_path, path, path_len); 145 memcpy(full_path, path, path_len);
147 full_path[path_len] = '/'; 146 full_path[path_len] = '/';
148 147
149 while ((ent = readdir64(dir))) { 148 while ((ent = readdir(dir))) {
150 PyObject *name = NULL; 149 PyObject *name = NULL;
151 PyObject *py_kind = NULL; 150 PyObject *py_kind = NULL;
152 PyObject *val = NULL; 151 PyObject *val = NULL;
153 unsigned char d_type; 152 unsigned char d_type;
154 int kind = -1; 153 int kind = -1;