#include "fcint.h"
#include <errno.h>
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef O_CLOEXEC
#define FC_O_CLOEXEC …
#else
#define FC_O_CLOEXEC …
#endif
#ifdef O_LARGEFILE
#define FC_O_LARGEFILE …
#else
#define FC_O_LARGEFILE …
#endif
#ifdef O_BINARY
#define FC_O_BINARY …
#else
#define FC_O_BINARY …
#endif
#ifdef O_TEMPORARY
#define FC_O_TEMPORARY …
#else
#define FC_O_TEMPORARY …
#endif
#ifdef O_NOINHERIT
#define FC_O_NOINHERIT …
#else
#define FC_O_NOINHERIT …
#endif
#ifndef HAVE_UNISTD_H
#ifndef R_OK
#define R_OK …
#endif
#ifndef W_OK
#define W_OK …
#endif
#ifndef F_OK
#define F_OK …
#endif
typedef int mode_t;
#endif
#if !defined (HAVE_MKOSTEMP) && !defined(HAVE_MKSTEMP) && !defined(HAVE__MKTEMP_S)
static int
mkstemp (char *template)
{
static const char s[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int fd, i;
size_t l;
if (template == NULL)
{
errno = EINVAL;
return -1;
}
l = strlen (template);
if (l < 6 || strcmp (&template[l - 6], "XXXXXX") != 0)
{
errno = EINVAL;
return -1;
}
do
{
errno = 0;
for (i = l - 6; i < l; i++)
{
int r = FcRandom ();
template[i] = s[r % 62];
}
fd = FcOpen (template, FC_O_BINARY | O_CREAT | O_EXCL | FC_O_TEMPORARY | FC_O_NOINHERIT | O_RDWR, 0600);
} while (fd < 0 && errno == EEXIST);
if (fd >= 0)
errno = 0;
return fd;
}
#define HAVE_MKSTEMP …
#endif
int
FcOpen(const char *pathname, int flags, ...)
{ … }
int
FcMakeTempfile (char *template)
{ … }
int32_t
FcRandom(void)
{ … }
#ifdef _WIN32
#include <direct.h>
#define mkdir …
#endif
FcBool
FcMakeDirectory (const FcChar8 *dir)
{ … }
ssize_t
FcReadLink (const FcChar8 *pathname,
FcChar8 *buf,
size_t bufsiz)
{ … }
#ifndef HAVE_DIRENT_H
struct DIR {
struct dirent d_ent;
HANDLE handle;
WIN32_FIND_DATA fdata;
FcBool valid;
};
FcPrivate DIR *
FcCompatOpendirWin32 (const char *dirname)
{
size_t len;
char *name;
DIR *dir;
dir = calloc (1, sizeof (struct DIR));
if (dir == NULL)
return NULL;
len = strlen (dirname);
name = malloc (len + 3);
if (name == NULL)
{
free (dir);
return NULL;
}
memcpy (name, dirname, len);
name[len++] = FC_DIR_SEPARATOR;
name[len++] = '*';
name[len] = '\0';
dir->handle = FindFirstFileEx (name, FindExInfoBasic, &dir->fdata, FindExSearchNameMatch, NULL, 0);
free (name);
if (!dir->handle)
{
free (dir);
dir = NULL;
if (GetLastError () == ERROR_FILE_NOT_FOUND)
errno = ENOENT;
else
errno = EACCES;
}
dir->valid = FcTrue;
return dir;
}
FcPrivate struct dirent *
FcCompatReaddirWin32 (DIR *dir)
{
if (dir->valid != FcTrue)
return NULL;
dir->d_ent.d_name = dir->fdata.cFileName;
if ((dir->fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
dir->d_ent.d_type = DT_DIR;
else if (dir->fdata.dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
dir->d_ent.d_type = DT_REG;
else
dir->d_ent.d_type = DT_UNKNOWN;
if (!FindNextFile (dir->handle, &dir->fdata))
dir->valid = FcFalse;
return &dir->d_ent;
}
FcPrivate int
FcCompatClosedirWin32 (DIR *dir)
{
if (dir != NULL && dir->handle != NULL)
{
FindClose (dir->handle);
free (dir);
}
return 0;
}
#endif
#define __fccompat__
#include "fcaliastail.h"
#undef __fccompat__