mirror of https://github.com/postgres/postgres
Simplify errno generating in thread testing program.
This commit is contained in:
parent
b33f78df17
commit
e319ec4b73
|
@ -263,6 +263,9 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* func_call_1
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
func_call_1(void)
|
func_call_1(void)
|
||||||
{
|
{
|
||||||
|
@ -272,23 +275,38 @@ func_call_1(void)
|
||||||
void *p;
|
void *p;
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE h1, h2;
|
HANDLE h1;
|
||||||
|
#else
|
||||||
|
int fd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unlink(TEMP_FILENAME_1);
|
unlink(TEMP_FILENAME_1);
|
||||||
|
|
||||||
|
/* Set errno = EEXIST */
|
||||||
|
|
||||||
/* create, then try to fail on exclusive create open */
|
/* create, then try to fail on exclusive create open */
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
h1 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL);
|
if ((h1 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL)) ==
|
||||||
h2 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
INVALID_HANDLE_VALUE)
|
||||||
if (h1 == INVALID_HANDLE_VALUE || GetLastError() != ERROR_FILE_EXISTS)
|
|
||||||
#else
|
#else
|
||||||
if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT, 0600) < 0 ||
|
if ((fd = open(TEMP_FILENAME_1, O_RDWR | O_CREAT, 0600)) < 0)
|
||||||
open(TEMP_FILENAME_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Could not create file in current directory or\n");
|
fprintf(stderr, "Could not create file %s in current directory\n",
|
||||||
fprintf(stderr, "could not generate failure for create file in current directory **\nexiting\n");
|
TEMP_FILENAME_1);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
if (CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL)
|
||||||
|
!= INVALID_HANDLE_VALUE || GetLastError() != ERROR_FILE_EXISTS)
|
||||||
|
#else
|
||||||
|
if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"Could not generate failure for exclusive file create of %s in current directory **\nexiting\n",
|
||||||
|
TEMP_FILENAME_1);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,6 +333,11 @@ func_call_1(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
CloseHandle(h1);
|
||||||
|
#else
|
||||||
|
close(fd);
|
||||||
|
#endif
|
||||||
unlink(TEMP_FILENAME_1);
|
unlink(TEMP_FILENAME_1);
|
||||||
|
|
||||||
#ifndef HAVE_STRERROR_R
|
#ifndef HAVE_STRERROR_R
|
||||||
|
@ -352,6 +375,9 @@ func_call_1(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* func_call_2
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
func_call_2(void)
|
func_call_2(void)
|
||||||
{
|
{
|
||||||
|
@ -363,15 +389,14 @@ func_call_2(void)
|
||||||
|
|
||||||
unlink(TEMP_FILENAME_2);
|
unlink(TEMP_FILENAME_2);
|
||||||
|
|
||||||
/* open non-existant file */
|
/* Set errno = ENOENT */
|
||||||
#ifdef WIN32
|
|
||||||
CreateFile(TEMP_FILENAME_2, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
/* This will fail, but we can't check errno yet */
|
||||||
if (GetLastError() != ERROR_FILE_NOT_FOUND)
|
if (unlink(TEMP_FILENAME_2) != -1)
|
||||||
#else
|
|
||||||
if (open(TEMP_FILENAME_2, O_RDONLY, 0600) >= 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Read-only open succeeded without create **\nexiting\n");
|
fprintf(stderr,
|
||||||
|
"Could not generate failure for unlink of %s in current directory **\nexiting\n",
|
||||||
|
TEMP_FILENAME_2);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,12 +419,9 @@ func_call_2(void)
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "errno not thread-safe **\nexiting\n");
|
fprintf(stderr, "errno not thread-safe **\nexiting\n");
|
||||||
#endif
|
#endif
|
||||||
unlink(TEMP_FILENAME_2);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(TEMP_FILENAME_2);
|
|
||||||
|
|
||||||
#ifndef HAVE_STRERROR_R
|
#ifndef HAVE_STRERROR_R
|
||||||
/*
|
/*
|
||||||
* If strerror() uses sys_errlist, the pointer might change for different
|
* If strerror() uses sys_errlist, the pointer might change for different
|
||||||
|
|
Loading…
Reference in New Issue