DBD-cubrid
view release on metacpan or search on metacpan
cci-src/src/base/porting.c view on Meta::CPAN
#if defined(AIX)
#define _BOOL
#include <unistd.h>
#include <curses.h>
#else
#include <unistd.h>
#include <curses.h>
#endif
#endif
#include "porting.h"
#if !defined(HAVE_ASPRINTF)
#include <stdarg.h>
#endif
#ifndef HAVE_STRLCPY
#include <sys/types.h>
#include <string.h>
#endif
#if defined(AIX) && !defined(DONT_HOOK_MALLOC)
#undef malloc
void *
aix_malloc (size_t size)
{
/* malloc 0 size memory will be failed in AIX */
if (size == 0)
{
size = 1;
}
return malloc (size);
}
#define malloc(a) aix_malloc(a)
#endif
#if defined (WINDOWS)
/*
* realpath() -
* return: pointer to resolved_path or NULL if error occurred
* path(in): the relative path to be resolved
* resolved_path(out): the buffer to output resolved path
*/
char *
realpath (const char *path, char *resolved_path)
{
struct stat stat_buf;
char *tmp_str = _fullpath (resolved_path, path, _MAX_PATH);
char tmp_path[_MAX_PATH] = { 0 };
int len = 0;
if (tmp_str != NULL)
{
strncpy (tmp_path, tmp_str, _MAX_PATH);
/*
* The output of _fullpath() ends with '\'(Windows format) or without it.
* It doesn't end with '/'(Linux format).
*
* Even if the directory path exists, the stat() in Windows fails when
* the directory path ends with '\'.
*/
len = strlen (tmp_path);
if (len > 0 && tmp_path[len - 1] == '\\')
{
tmp_path[len - 1] = '\0';
}
if (stat (tmp_path, &stat_buf) == 0)
{
return tmp_str;
}
}
return NULL;
}
/*
* poll() -
* return: return poll result
* fds(in): socket descriptors to wait
* nfds(in): number of descriptors
* timeout(in): timeout in milliseconds
*/
int
poll (struct pollfd *fds, nfds_t nfds, int timeout)
{
struct timeval to, *tp;
fd_set rset, wset, eset;
fd_set *rp, *wp, *ep;
unsigned long int i;
int r;
unsigned int max_fd;
tp = NULL;
if (timeout >= 0)
{
to.tv_sec = timeout / 1000;
to.tv_usec = (timeout % 1000) * 1000;
tp = &to;
}
FD_ZERO (&rset);
FD_ZERO (&wset);
FD_ZERO (&eset);
rp = wp = ep = NULL;
max_fd = 0;
for (i = 0; i < nfds; i++)
{
if (fds[i].events & POLLIN)
{
if (rp == NULL)
{
rp = &rset;
}
FD_SET (fds[i].fd, rp);
max_fd = MAX (fds[i].fd, max_fd);
}
if (fds[i].events & POLLOUT)
cci-src/src/base/porting.c view on Meta::CPAN
* set(in/out):
*/
static void
sync_mask (sigset_t * set)
{
set->mask |= (set->term_state == SIG_IGN) ? SIGTERM_BIT : set->mask;
set->mask |= (set->sev_state == SIG_IGN) ? SIGSEGV_BIT : set->mask;
set->mask |= (set->int_state == SIG_IGN) ? SIGINT_BIT : set->mask;
set->mask |= (set->ill_state == SIG_IGN) ? SIGILL_BIT : set->mask;
set->mask |= (set->fpe_state == SIG_IGN) ? SIGFPE_BIT : set->mask;
set->mask |= (set->abrt_state == SIG_IGN) ? SIGABRT_BIT : set->mask;
}
/*
* sigprocmask -
* return:
* how(in):
* set(in/out):
* oldset(out):
*
* Note:
*/
int
sigprocmask (int how, sigset_t * set, sigset_t * oldset)
{
switch (how)
{
case SIG_BLOCK:
return (block_signals (set, oldset));
case SIG_UNBLOCK:
return (unblock_signals (set, oldset));
case SIG_SETMASK:
return (setmask (set, oldset));
}
return (-1);
}
/*
* getpagesize -
* return:
*/
DWORD
getpagesize ()
{
static DWORD NT_PageSize = 0;
SYSTEM_INFO sysinfo;
if (NT_PageSize == 0)
{
GetSystemInfo (&sysinfo);
NT_PageSize = sysinfo.dwPageSize;
}
return (NT_PageSize);
}
#if 0
/*
* stat - Windows port of Unix stat()
* return: 0 or -1
* path(in): file path
* buffer(in): struct _stat
*/
int
stat (const char *path, struct stat *buf)
{
struct _stat _buf;
int rc;
rc = _stat (path, &_buf);
if (buf)
*buf = _buf;
return rc;
}
#endif
/*
* pc_init()
* return: none
*/
void
pc_init (void)
{
unsigned int fpbits;
fpbits = _EM_OVERFLOW | _EM_UNDERFLOW | _EM_ZERODIVIDE;
(void) _control87 (fpbits, fpbits);
}
/*
* pc_final()
* return: none
*/
void
pc_final (void)
{
}
#if defined (ENABLE_UNUSED_FUNCTION)
/*
* lock_region() - lock/unlock region of a file
* return: 0 if success, -1 otherwise
* fd(in): file descriptor
* cmd(in): locking command to perform
* offset(in): start offset
* size(in): number of bytes
*/
int
lock_region (int fd, int cmd, long offset, long size)
{
if (lseek (fd, offset, SEEK_SET) != offset)
{
return -1;
}
return lockf (fd, cmd, size);
}
#endif /* ENABLE_UNUSED_FUNCTION */
/* free_space -
( run in 0.528 second using v1.01-cache-2.11-cpan-5b529ec07f3 )