Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4207d6b

Browse files
committed
Add opendir/readdir/closedir() for Win32.
Keep SRA copyright on file because it contains BSD license clause.
1 parent45d0409 commit4207d6b

File tree

4 files changed

+153
-4
lines changed

4 files changed

+153
-4
lines changed

‎configure

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11257,7 +11257,8 @@ esac
1125711257
1125811258
# Win32 can't to rename or unlink on an open file
1125911259
case$host_osin win32*)
11260-
LIBOBJS="$LIBOBJS dirmod.$ac_objext" ;;
11260+
LIBOBJS="$LIBOBJS dirmod.$ac_objext"
11261+
LIBOBJS="$LIBOBJS opendir.$ac_objext" ;;
1126111262
esac
1126211263
1126311264
# On HPUX 9, rint() is not in regular libm.a but in /lib/pa1.1/libm.a;

‎configure.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.245 2003/05/07 03:47:08 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.246 2003/05/09 01:16:29 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -863,7 +863,8 @@ esac
863863

864864
# Win32 can't to rename or unlink on an open file
865865
case $host_os in win32*)
866-
AC_LIBOBJ(dirmod) ;;
866+
AC_LIBOBJ(dirmod)
867+
AC_LIBOBJ(opendir) ;;
867868
esac
868869

869870
# On HPUX 9, rint() is not in regular libm.a but in /lib/pa1.1/libm.a;

‎src/include/c.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: c.h,v 1.141 2003/04/2516:18:40 momjian Exp $
15+
* $Id: c.h,v 1.142 2003/05/09 01:16:29 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -721,6 +721,31 @@ int pgunlink(const char *path);
721721
#defineunlink(from,to)pgunlink(from, to)
722722
#endif
723723

724+
/*
725+
* Win32 doesn't have opendir/readdir/closedir()
726+
*/
727+
#ifdefWIN32
728+
structdirent {
729+
ino_td_ino;/* inode (always 1 on WIN32) */
730+
chard_name[MAX_PATH+1];/* filename (null terminated) */
731+
};
732+
733+
typedefstruct {
734+
HANDLEhandle;/* handle for FindFirstFile or
735+
* FindNextFile */
736+
longoffset;/* offset into directory */
737+
intfinished;/* 1 if there are not more files */
738+
WIN32_FIND_DATAfinddata;/* file data FindFirstFile or FindNextFile
739+
* returns */
740+
char*dir;/* the directory path we are reading */
741+
structdirentent;/* the dirent to return */
742+
}DIR;
743+
744+
externDIR*opendir(constchar*);
745+
externstructdirent*readdir(DIR*);
746+
externintclosedir(DIR*);
747+
#endif
748+
724749
/*
725750
*Win32 requires a special close for sockets and pipes, while on Unix
726751
*close() does them all.

‎src/port/opendir.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* $Header: /cvsroot/pgsql/src/port/Attic/opendir.c,v 1.1 2003/05/09 01:16:29 momjian Exp $
3+
*
4+
* Copyright (c) 2003 SRA, Inc.
5+
* Copyright (c) 2003 SKC, Inc.
6+
*
7+
* Permission to use, copy, modify, and distribute this software and
8+
* its documentation for any purpose, without fee, and without a
9+
* written agreement is hereby granted, provided that the above
10+
* copyright notice and this paragraph and the following two
11+
* paragraphs appear in all copies.
12+
*
13+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
14+
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
15+
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
16+
* DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
17+
* OF THE POSSIBILITY OF SUCH DAMAGE.
18+
*
19+
* THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
22+
* IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
23+
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24+
*/
25+
26+
#include"postgres.h"
27+
28+
#include<stddef.h>
29+
#include<sys/types.h>
30+
#include<windows.h>
31+
32+
#include"dirent.h"
33+
34+
DIR*
35+
opendir(constchar*dir)
36+
{
37+
DIR*dp;
38+
char*findspec;
39+
HANDLEhandle;
40+
size_tdirlen;
41+
42+
dirlen=strlen(dir);
43+
findspec=palloc(dirlen+2+1);
44+
if (findspec==NULL)
45+
returnNULL;
46+
47+
if (dirlen==0)
48+
strcpy(findspec,"*");
49+
elseif (isalpha(dir[0])&&dir[1]==':'&&dir[2]=='\0')
50+
sprintf(findspec,"%s*",dir);
51+
elseif (dir[dirlen-1]=='/'||dir[dirlen-1]=='\\')
52+
sprintf(findspec,"%s*",dir);
53+
else
54+
sprintf(findspec,"%s\\*",dir);
55+
56+
dp= (DIR*)palloc(sizeof(DIR));
57+
if (dp==NULL)
58+
{
59+
pfree(findspec);
60+
errno=ENOMEM;
61+
returnNULL;
62+
}
63+
64+
dp->offset=0;
65+
dp->finished=0;
66+
dp->dir=pstrdup(dir);
67+
if (dp->dir==NULL)
68+
{
69+
pfree(dp);
70+
pfree(findspec);
71+
errno=ENOMEM;
72+
returnNULL;
73+
}
74+
75+
handle=FindFirstFile(findspec,&(dp->finddata));
76+
if (handle==INVALID_HANDLE_VALUE)
77+
{
78+
pfree(dp->dir);
79+
pfree(dp);
80+
pfree(findspec);
81+
errno=ENOENT;
82+
returnNULL;
83+
}
84+
dp->handle=handle;
85+
86+
pfree(findspec);
87+
returndp;
88+
}
89+
90+
91+
structdirent*
92+
readdir(DIR*dp)
93+
{
94+
if (dp==NULL||dp->finished)
95+
returnNULL;
96+
97+
if (dp->offset!=0)
98+
{
99+
if (FindNextFile(dp->handle,&(dp->finddata))==0)
100+
{
101+
dp->finished=1;
102+
returnNULL;
103+
}
104+
}
105+
dp->offset++;
106+
107+
strncpy(dp->ent.d_name,dp->finddata.cFileName,MAX_PATH);
108+
dp->ent.d_ino=1;
109+
110+
return&(dp->ent);
111+
}
112+
113+
114+
int
115+
closedir(DIR*dp)
116+
{
117+
FindClose(dp->handle);
118+
pfree(dp->dir);
119+
pfree(dp);
120+
121+
return0;
122+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp