You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-09-16 09:26:30 +02:00
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
This commit is contained in:
13
catalog.c
13
catalog.c
@@ -9,14 +9,15 @@
|
||||
|
||||
#include "pg_rman.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pgut/pgut-port.h"
|
||||
|
||||
@@ -96,7 +97,7 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
|
||||
return ent->d_type == DT_DIR;
|
||||
#elif defined(_finddata_t)
|
||||
return (dir->dd_dta.attrib & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
#else
|
||||
#elif defined(WIN32)
|
||||
char path[MAXPGPATH];
|
||||
DWORD attr;
|
||||
|
||||
@@ -106,6 +107,8 @@ IsDir(const char *dirpath, const DIR *dir, const struct dirent *ent)
|
||||
strlcat(path, ent->d_name, MAXPGPATH);
|
||||
attr = GetFileAttributes(path);
|
||||
return attr != (DWORD) -1 && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
#else
|
||||
#error IsDir: this platform is not supported.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,11 @@
|
||||
#include "c.h"
|
||||
#include "pgut-port.h"
|
||||
|
||||
#undef flock
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <winioctl.h>
|
||||
@@ -119,13 +124,18 @@ readlink(const char *path, char *target, size_t size)
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PGUT_FLOCK
|
||||
|
||||
#ifdef WIN32
|
||||
int
|
||||
flock(int fd, int operation)
|
||||
pgut_flock(int fd, int operation)
|
||||
{
|
||||
BOOL ret;
|
||||
HANDLE handle = (HANDLE) _get_osfhandle(fd);
|
||||
DWORD lo = 0;
|
||||
DWORD hi = 1;
|
||||
DWORD hi = 0;
|
||||
|
||||
if (operation & LOCK_UN)
|
||||
{
|
||||
@@ -150,4 +160,34 @@ flock(int fd, int operation)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
pgut_flock(int fd, int operation)
|
||||
{
|
||||
struct flock lck;
|
||||
int cmd;
|
||||
|
||||
memset(&lck, 0, sizeof(lck));
|
||||
lck.l_whence = SEEK_SET;
|
||||
lck.l_start = 0;
|
||||
lck.l_len = 0;
|
||||
lck.l_pid = getpid();
|
||||
|
||||
if (operation & LOCK_UN)
|
||||
lck.l_type = F_UNLCK;
|
||||
else if (operation & LOCK_EX)
|
||||
lck.l_type = F_WRLCK;
|
||||
else
|
||||
lck.l_type = F_RDLCK;
|
||||
|
||||
if (operation & LOCK_NB)
|
||||
cmd = F_SETLK;
|
||||
else
|
||||
cmd = F_SETLKW;
|
||||
|
||||
return fcntl(fd, cmd, &lck);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -10,21 +10,41 @@
|
||||
#ifndef PGUT_PORT_H
|
||||
#define PGUT_PORT_H
|
||||
|
||||
/*
|
||||
* readlink ports
|
||||
*/
|
||||
#ifdef WIN32
|
||||
|
||||
#define LOCK_SH 1 /* Shared lock. */
|
||||
#define LOCK_EX 2 /* Exclusive lock. */
|
||||
#define LOCK_UN 8 /* Unlock. */
|
||||
#define LOCK_NB 4 /* Don't block when locking. */
|
||||
|
||||
#define S_IFLNK (0)
|
||||
#define S_IRWXG (0)
|
||||
#define S_IRWXO (0)
|
||||
#define S_ISLNK(mode) (0)
|
||||
|
||||
extern int flock(int fd, int operation);
|
||||
extern ssize_t readlink(const char *path, char *target, size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* flock ports
|
||||
*/
|
||||
#ifndef LOCK_EX
|
||||
|
||||
#define PGUT_FLOCK
|
||||
|
||||
#undef LOCK_SH
|
||||
#undef LOCK_EX
|
||||
#undef LOCK_UN
|
||||
#undef LOCK_NB
|
||||
|
||||
#define LOCK_SH 1 /* Shared lock. */
|
||||
#define LOCK_EX 2 /* Exclusive lock. */
|
||||
#define LOCK_UN 8 /* Unlock. */
|
||||
#define LOCK_NB 4 /* Don't block when locking. */
|
||||
|
||||
extern int pgut_flock(int fd, int operation);
|
||||
|
||||
#define flock pgut_flock
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* PGUT_PORT_H */
|
||||
|
Reference in New Issue
Block a user