Use Unix line endings instead of DOS ones, per Magnus.
This commit is contained in:
parent
e2fee8cf6d
commit
e56756e94e
src
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Headers for port/dirent.c, win32 native implementation of dirent functions
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/port/win32_msvc/dirent.h,v 1.1 2006/06/07 22:24:45 momjian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _WIN32VC_DIRENT_H
|
||||
#define _WIN32VC_DIRENT_H
|
||||
struct dirent {
|
||||
long d_ino;
|
||||
unsigned short d_reclen;
|
||||
unsigned short d_namlen;
|
||||
char d_name[MAX_PATH];
|
||||
};
|
||||
|
||||
typedef struct DIR DIR;
|
||||
|
||||
DIR* opendir(const char *);
|
||||
struct dirent* readdir(DIR *);
|
||||
int closedir(DIR*);
|
||||
#endif
|
||||
/*
|
||||
* Headers for port/dirent.c, win32 native implementation of dirent functions
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/port/win32_msvc/dirent.h,v 1.2 2006/06/26 12:59:44 momjian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _WIN32VC_DIRENT_H
|
||||
#define _WIN32VC_DIRENT_H
|
||||
struct dirent {
|
||||
long d_ino;
|
||||
unsigned short d_reclen;
|
||||
unsigned short d_namlen;
|
||||
char d_name[MAX_PATH];
|
||||
};
|
||||
|
||||
typedef struct DIR DIR;
|
||||
|
||||
DIR* opendir(const char *);
|
||||
struct dirent* readdir(DIR *);
|
||||
int closedir(DIR*);
|
||||
#endif
|
||||
|
@ -1,108 +1,108 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* dirent.c
|
||||
* opendir/readdir/closedir for win32/msvc
|
||||
*
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/port/dirent.c,v 1.1 2006/06/07 22:24:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
struct DIR {
|
||||
char *dirname;
|
||||
struct dirent ret; /* Used to return to caller */
|
||||
HANDLE handle;
|
||||
};
|
||||
|
||||
DIR* opendir(const char *dirname)
|
||||
{
|
||||
DWORD attr;
|
||||
DIR *d;
|
||||
|
||||
/* Make sure it is a directory */
|
||||
attr = GetFileAttributes(dirname);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = malloc(sizeof(DIR));
|
||||
if (!d)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
d->dirname = malloc(strlen(dirname)+4);
|
||||
if (!d->dirname)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(d->dirname, dirname);
|
||||
if (d->dirname[strlen(d->dirname)-1] != '/' &&
|
||||
d->dirname[strlen(d->dirname)-1] != '\\')
|
||||
strcat(d->dirname,"\\"); /* Append backslash if not already there */
|
||||
strcat(d->dirname,"*"); /* Search for entries named anything */
|
||||
d->handle = INVALID_HANDLE_VALUE;
|
||||
d->ret.d_ino = 0; /* no inodes on win32 */
|
||||
d->ret.d_reclen = 0; /* not used on win32 */
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
struct dirent* readdir(DIR * d)
|
||||
{
|
||||
WIN32_FIND_DATA fd;
|
||||
|
||||
if (d->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
d->handle = FindFirstFile(d->dirname, &fd);
|
||||
if (d->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!FindNextFile(d->handle, &fd))
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
{
|
||||
/* No more files, force errno=0 (unlike mingw) */
|
||||
errno = 0;
|
||||
return NULL;
|
||||
}
|
||||
_dosmaperr(GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH long */
|
||||
d->ret.d_namlen = strlen(d->ret.d_name);
|
||||
return &d->ret;
|
||||
}
|
||||
|
||||
int closedir(DIR *d)
|
||||
{
|
||||
if (d->handle != INVALID_HANDLE_VALUE)
|
||||
FindClose(d->handle);
|
||||
free(d->dirname);
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* dirent.c
|
||||
* opendir/readdir/closedir for win32/msvc
|
||||
*
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/port/dirent.c,v 1.2 2006/06/26 12:58:17 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
struct DIR {
|
||||
char *dirname;
|
||||
struct dirent ret; /* Used to return to caller */
|
||||
HANDLE handle;
|
||||
};
|
||||
|
||||
DIR* opendir(const char *dirname)
|
||||
{
|
||||
DWORD attr;
|
||||
DIR *d;
|
||||
|
||||
/* Make sure it is a directory */
|
||||
attr = GetFileAttributes(dirname);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = malloc(sizeof(DIR));
|
||||
if (!d)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
d->dirname = malloc(strlen(dirname)+4);
|
||||
if (!d->dirname)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(d->dirname, dirname);
|
||||
if (d->dirname[strlen(d->dirname)-1] != '/' &&
|
||||
d->dirname[strlen(d->dirname)-1] != '\\')
|
||||
strcat(d->dirname,"\\"); /* Append backslash if not already there */
|
||||
strcat(d->dirname,"*"); /* Search for entries named anything */
|
||||
d->handle = INVALID_HANDLE_VALUE;
|
||||
d->ret.d_ino = 0; /* no inodes on win32 */
|
||||
d->ret.d_reclen = 0; /* not used on win32 */
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
struct dirent* readdir(DIR * d)
|
||||
{
|
||||
WIN32_FIND_DATA fd;
|
||||
|
||||
if (d->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
d->handle = FindFirstFile(d->dirname, &fd);
|
||||
if (d->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!FindNextFile(d->handle, &fd))
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
{
|
||||
/* No more files, force errno=0 (unlike mingw) */
|
||||
errno = 0;
|
||||
return NULL;
|
||||
}
|
||||
_dosmaperr(GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH long */
|
||||
d->ret.d_namlen = strlen(d->ret.d_name);
|
||||
return &d->ret;
|
||||
}
|
||||
|
||||
int closedir(DIR *d)
|
||||
{
|
||||
if (d->handle != INVALID_HANDLE_VALUE)
|
||||
FindClose(d->handle);
|
||||
free(d->dirname);
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,200 +1,200 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* win32error.c
|
||||
* Map win32 error codes to errno values
|
||||
*
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/port/win32error.c,v 1.1 2006/06/07 22:24:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
static const struct
|
||||
{
|
||||
DWORD winerr;
|
||||
int doserr;
|
||||
} doserrors[] =
|
||||
|
||||
{
|
||||
{
|
||||
ERROR_INVALID_FUNCTION, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_FILE_NOT_FOUND, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_PATH_NOT_FOUND, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_TOO_MANY_OPEN_FILES, EMFILE
|
||||
},
|
||||
{
|
||||
ERROR_ACCESS_DENIED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_ARENA_TRASHED, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_NOT_ENOUGH_MEMORY, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_BLOCK, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_BAD_ENVIRONMENT, E2BIG
|
||||
},
|
||||
{
|
||||
ERROR_BAD_FORMAT, ENOEXEC
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_ACCESS, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_DATA, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_DRIVE, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_CURRENT_DIRECTORY, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_NOT_SAME_DEVICE, EXDEV
|
||||
},
|
||||
{
|
||||
ERROR_NO_MORE_FILES, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_LOCK_VIOLATION, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_SHARING_VIOLATION, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_NETPATH, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_NETWORK_ACCESS_DENIED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_NET_NAME, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_FILE_EXISTS, EEXIST
|
||||
},
|
||||
{
|
||||
ERROR_CANNOT_MAKE, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_FAIL_I24, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_PARAMETER, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_NO_PROC_SLOTS, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_DRIVE_LOCKED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BROKEN_PIPE, EPIPE
|
||||
},
|
||||
{
|
||||
ERROR_DISK_FULL, ENOSPC
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_TARGET_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_HANDLE, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_WAIT_NO_CHILDREN, ECHILD
|
||||
},
|
||||
{
|
||||
ERROR_CHILD_NOT_COMPLETE, ECHILD
|
||||
},
|
||||
{
|
||||
ERROR_DIRECT_ACCESS_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_NEGATIVE_SEEK, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_SEEK_ON_DEVICE, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_DIR_NOT_EMPTY, ENOTEMPTY
|
||||
},
|
||||
{
|
||||
ERROR_NOT_LOCKED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_PATHNAME, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_MAX_THRDS_REACHED, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_LOCK_FAILED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_ALREADY_EXISTS, EEXIST
|
||||
},
|
||||
{
|
||||
ERROR_FILENAME_EXCED_RANGE, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_NESTING_NOT_ALLOWED, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_NOT_ENOUGH_QUOTA, ENOMEM
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
_dosmaperr(unsigned long e)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (e == 0)
|
||||
{
|
||||
errno = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < lengthof(doserrors); i++)
|
||||
{
|
||||
if (doserrors[i].winerr == e)
|
||||
{
|
||||
errno = doserrors[i].doserr;
|
||||
#ifndef FRONTEND
|
||||
ereport(DEBUG5,
|
||||
(errmsg_internal("mapped win32 error code %lu to %d",
|
||||
e, errno)));
|
||||
#else
|
||||
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef FRONTEND
|
||||
ereport(LOG,
|
||||
(errmsg_internal("unrecognized win32 error code: %lu",
|
||||
e)));
|
||||
#else
|
||||
fprintf(stderr, _("unrecognized win32 error code: %lu"), e);
|
||||
#endif
|
||||
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* win32error.c
|
||||
* Map win32 error codes to errno values
|
||||
*
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/port/win32error.c,v 1.2 2006/06/26 12:58:43 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
static const struct
|
||||
{
|
||||
DWORD winerr;
|
||||
int doserr;
|
||||
} doserrors[] =
|
||||
|
||||
{
|
||||
{
|
||||
ERROR_INVALID_FUNCTION, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_FILE_NOT_FOUND, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_PATH_NOT_FOUND, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_TOO_MANY_OPEN_FILES, EMFILE
|
||||
},
|
||||
{
|
||||
ERROR_ACCESS_DENIED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_ARENA_TRASHED, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_NOT_ENOUGH_MEMORY, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_BLOCK, ENOMEM
|
||||
},
|
||||
{
|
||||
ERROR_BAD_ENVIRONMENT, E2BIG
|
||||
},
|
||||
{
|
||||
ERROR_BAD_FORMAT, ENOEXEC
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_ACCESS, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_DATA, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_DRIVE, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_CURRENT_DIRECTORY, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_NOT_SAME_DEVICE, EXDEV
|
||||
},
|
||||
{
|
||||
ERROR_NO_MORE_FILES, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_LOCK_VIOLATION, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_SHARING_VIOLATION, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_NETPATH, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_NETWORK_ACCESS_DENIED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_NET_NAME, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_FILE_EXISTS, EEXIST
|
||||
},
|
||||
{
|
||||
ERROR_CANNOT_MAKE, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_FAIL_I24, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_PARAMETER, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_NO_PROC_SLOTS, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_DRIVE_LOCKED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BROKEN_PIPE, EPIPE
|
||||
},
|
||||
{
|
||||
ERROR_DISK_FULL, ENOSPC
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_TARGET_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_INVALID_HANDLE, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_WAIT_NO_CHILDREN, ECHILD
|
||||
},
|
||||
{
|
||||
ERROR_CHILD_NOT_COMPLETE, ECHILD
|
||||
},
|
||||
{
|
||||
ERROR_DIRECT_ACCESS_HANDLE, EBADF
|
||||
},
|
||||
{
|
||||
ERROR_NEGATIVE_SEEK, EINVAL
|
||||
},
|
||||
{
|
||||
ERROR_SEEK_ON_DEVICE, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_DIR_NOT_EMPTY, ENOTEMPTY
|
||||
},
|
||||
{
|
||||
ERROR_NOT_LOCKED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_BAD_PATHNAME, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_MAX_THRDS_REACHED, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_LOCK_FAILED, EACCES
|
||||
},
|
||||
{
|
||||
ERROR_ALREADY_EXISTS, EEXIST
|
||||
},
|
||||
{
|
||||
ERROR_FILENAME_EXCED_RANGE, ENOENT
|
||||
},
|
||||
{
|
||||
ERROR_NESTING_NOT_ALLOWED, EAGAIN
|
||||
},
|
||||
{
|
||||
ERROR_NOT_ENOUGH_QUOTA, ENOMEM
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
_dosmaperr(unsigned long e)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (e == 0)
|
||||
{
|
||||
errno = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < lengthof(doserrors); i++)
|
||||
{
|
||||
if (doserrors[i].winerr == e)
|
||||
{
|
||||
errno = doserrors[i].doserr;
|
||||
#ifndef FRONTEND
|
||||
ereport(DEBUG5,
|
||||
(errmsg_internal("mapped win32 error code %lu to %d",
|
||||
e, errno)));
|
||||
#else
|
||||
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef FRONTEND
|
||||
ereport(LOG,
|
||||
(errmsg_internal("unrecognized win32 error code: %lu",
|
||||
e)));
|
||||
#else
|
||||
fprintf(stderr, _("unrecognized win32 error code: %lu"), e);
|
||||
#endif
|
||||
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user