ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.15 by root, Sat May 17 12:26:57 2008 UTC vs.
Revision 1.16 by root, Fri May 30 04:50:21 2008 UTC

314 X_LOCK (reqlock); 314 X_LOCK (reqlock);
315 X_LOCK (reslock); 315 X_LOCK (reslock);
316#if !HAVE_PREADWRITE 316#if !HAVE_PREADWRITE
317 X_LOCK (preadwritelock); 317 X_LOCK (preadwritelock);
318#endif 318#endif
319#if !HAVE_READDIR_R
320 X_LOCK (readdirlock);
321#endif
322} 319}
323 320
324static void etp_atfork_parent (void) 321static void etp_atfork_parent (void)
325{ 322{
326#if !HAVE_READDIR_R
327 X_UNLOCK (readdirlock);
328#endif
329#if !HAVE_PREADWRITE 323#if !HAVE_PREADWRITE
330 X_UNLOCK (preadwritelock); 324 X_UNLOCK (preadwritelock);
331#endif 325#endif
332 X_UNLOCK (reslock); 326 X_UNLOCK (reslock);
333 X_UNLOCK (reqlock); 327 X_UNLOCK (reqlock);
801 return count; 795 return count;
802} 796}
803 797
804#endif 798#endif
805 799
806#if !HAVE_READDIR_R
807# define readdir_r eio__readdir_r
808
809static mutex_t readdirlock = X_MUTEX_INIT;
810
811static int
812eio__readdir_r (DIR *dirp, EIO_STRUCT_DIRENT *ent, EIO_STRUCT_DIRENT **res)
813{
814 EIO_STRUCT_DIRENT *e;
815 int errorno;
816
817 X_LOCK (readdirlock);
818
819 e = readdir (dirp);
820 errorno = errno;
821
822 if (e)
823 {
824 *res = ent;
825 strcpy (ent->d_name, e->d_name);
826 }
827 else
828 *res = 0;
829
830 X_UNLOCK (readdirlock);
831
832 errno = errorno;
833 return e ? 0 : -1;
834}
835#endif
836
837/* sendfile always needs emulation */ 800/* sendfile always needs emulation */
838static ssize_t 801static ssize_t
839eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) 802eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self)
840{ 803{
841 ssize_t res; 804 ssize_t res;
931/* read a full directory */ 894/* read a full directory */
932static void 895static void
933eio__scandir (eio_req *req, etp_worker *self) 896eio__scandir (eio_req *req, etp_worker *self)
934{ 897{
935 DIR *dirp; 898 DIR *dirp;
936 union
937 {
938 EIO_STRUCT_DIRENT d;
939 char b [offsetof (EIO_STRUCT_DIRENT, d_name) + NAME_MAX + 1];
940 } *u;
941 EIO_STRUCT_DIRENT *entp; 899 EIO_STRUCT_DIRENT *entp;
942 char *name, *names; 900 char *name, *names;
943 int memlen = 4096; 901 int memlen = 4096;
944 int memofs = 0; 902 int memofs = 0;
945 int res = 0; 903 int res = 0;
946 904
947 X_LOCK (wrklock); 905 X_LOCK (wrklock);
948 self->dirp = dirp = opendir (req->ptr1); 906 self->dirp = dirp = opendir (req->ptr1);
949 self->dbuf = u = malloc (sizeof (*u));
950 req->flags |= EIO_FLAG_PTR2_FREE; 907 req->flags |= EIO_FLAG_PTR2_FREE;
951 req->ptr2 = names = malloc (memlen); 908 req->ptr2 = names = malloc (memlen);
952 X_UNLOCK (wrklock); 909 X_UNLOCK (wrklock);
953 910
954 if (dirp && u && names) 911 if (dirp && names)
955 for (;;) 912 for (;;)
956 { 913 {
957 errno = 0; 914 errno = 0;
958 readdir_r (dirp, &u->d, &entp); 915 entp = readdir (dirp);
959 916
960 if (!entp) 917 if (!entp)
961 break; 918 break;
962 919
963 name = entp->d_name; 920 name = entp->d_name;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines