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

Commitf0d7a12

Browse files
author
itagaki.takahiro
committed
Add missing headers and portable flock() implemented with fcntl() for Solaris.
git-svn-id:http://pg-rman.googlecode.com/svn/trunk@19 182aca00-e38e-11de-a668-6fd11605f5ce
1 parent6545c64 commitf0d7a12

File tree

4 files changed

+77
-13
lines changed

4 files changed

+77
-13
lines changed

‎catalog.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
#include"pg_rman.h"
1111

12-
#include<stdlib.h>
13-
#include<libgen.h>
14-
#include<unistd.h>
1512
#include<dirent.h>
16-
#include<time.h>
13+
#include<fcntl.h>
14+
#include<libgen.h>
1715
#include<sys/stat.h>
1816
#include<sys/types.h>
1917
#include<sys/file.h>
18+
#include<stdlib.h>
19+
#include<time.h>
20+
#include<unistd.h>
2021

2122
#include"pgut/pgut-port.h"
2223

@@ -96,7 +97,7 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
9697
returnent->d_type==DT_DIR;
9798
#elif defined(_finddata_t)
9899
return (dir->dd_dta.attrib&FILE_ATTRIBUTE_DIRECTORY)!=0;
99-
#else
100+
#elif defined(WIN32)
100101
charpath[MAXPGPATH];
101102
DWORDattr;
102103

@@ -106,6 +107,8 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
106107
strlcat(path,ent->d_name,MAXPGPATH);
107108
attr=GetFileAttributes(path);
108109
returnattr!= (DWORD)-1&& (attr&FILE_ATTRIBUTE_DIRECTORY)!=0;
110+
#else
111+
#error IsDir: this platform is not supported.
109112
#endif
110113
}
111114

‎pgut/pgut-port.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#include"c.h"
1111
#include"pgut-port.h"
1212

13+
#undef flock
14+
15+
#include<unistd.h>
16+
#include<fcntl.h>
17+
1318
#ifdefWIN32
1419

1520
#include<winioctl.h>
@@ -119,13 +124,18 @@ readlink(const char *path, char *target, size_t size)
119124
returnr;
120125
}
121126

127+
#endif
128+
129+
#ifdefPGUT_FLOCK
130+
131+
#ifdefWIN32
122132
int
123-
flock(intfd,intoperation)
133+
pgut_flock(intfd,intoperation)
124134
{
125135
BOOLret;
126136
HANDLEhandle= (HANDLE)_get_osfhandle(fd);
127137
DWORDlo=0;
128-
DWORDhi=1;
138+
DWORDhi=0;
129139

130140
if (operation&LOCK_UN)
131141
{
@@ -150,4 +160,34 @@ flock(int fd, int operation)
150160
return0;
151161
}
152162

163+
#else
164+
165+
int
166+
pgut_flock(intfd,intoperation)
167+
{
168+
structflocklck;
169+
intcmd;
170+
171+
memset(&lck,0,sizeof(lck));
172+
lck.l_whence=SEEK_SET;
173+
lck.l_start=0;
174+
lck.l_len=0;
175+
lck.l_pid=getpid();
176+
177+
if (operation&LOCK_UN)
178+
lck.l_type=F_UNLCK;
179+
elseif (operation&LOCK_EX)
180+
lck.l_type=F_WRLCK;
181+
else
182+
lck.l_type=F_RDLCK;
183+
184+
if (operation&LOCK_NB)
185+
cmd=F_SETLK;
186+
else
187+
cmd=F_SETLKW;
188+
189+
returnfcntl(fd,cmd,&lck);
190+
}
191+
#endif
192+
153193
#endif

‎pgut/pgut-port.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,41 @@
1010
#ifndefPGUT_PORT_H
1111
#definePGUT_PORT_H
1212

13+
/*
14+
* readlink ports
15+
*/
1316
#ifdefWIN32
1417

15-
#defineLOCK_SH1/* Shared lock. */
16-
#defineLOCK_EX2/* Exclusive lock. */
17-
#defineLOCK_UN8/* Unlock. */
18-
#defineLOCK_NB4/* Don't block when locking. */
19-
2018
#defineS_IFLNK(0)
2119
#defineS_IRWXG(0)
2220
#defineS_IRWXO(0)
2321
#defineS_ISLNK(mode)(0)
2422

25-
externintflock(intfd,intoperation);
2623
externssize_treadlink(constchar*path,char*target,size_tsize);
2724

2825
#endif
2926

27+
/*
28+
* flock ports
29+
*/
30+
#ifndefLOCK_EX
31+
32+
#definePGUT_FLOCK
33+
34+
#undef LOCK_SH
35+
#undef LOCK_EX
36+
#undef LOCK_UN
37+
#undef LOCK_NB
38+
39+
#defineLOCK_SH1/* Shared lock. */
40+
#defineLOCK_EX2/* Exclusive lock. */
41+
#defineLOCK_UN8/* Unlock. */
42+
#defineLOCK_NB4/* Don't block when locking. */
43+
44+
externintpgut_flock(intfd,intoperation);
45+
46+
#defineflockpgut_flock
47+
48+
#endif
49+
3050
#endif/* PGUT_PORT_H */

‎restore.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include<fcntl.h>
1313
#include<sys/stat.h>
14+
#include<sys/types.h>
1415
#include<unistd.h>
1516

1617
#include"catalog/pg_control.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp