* *
* C Implementation File *
* *
- * Copyright (C) 1992-2017, Free Software Foundation, Inc. *
+ * Copyright (C) 1992-2019, Free Software Foundation, Inc. *
* *
* GNAT is free software; you can redistribute it and/or modify it under *
* terms of the GNU General Public License as published by the Free Soft- *
#define _THREAD_SAFE
/* Use 64 bit Large File API */
-#ifndef _LARGEFILE_SOURCE
+#if defined (__QNX__)
+#define _LARGEFILE64_SOURCE 1
+#elif !defined(_LARGEFILE_SOURCE)
#define _LARGEFILE_SOURCE
#endif
#define _FILE_OFFSET_BITS 64
#define __BSD_VISIBLE 1
#endif
+#ifdef __QNX__
+#include <sys/syspage.h>
+#endif
+
#ifdef IN_RTS
+
+#ifdef STANDALONE
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* for CPU_SET/CPU_ZERO */
+#define _GNU_SOURCE
+#define __USE_GNU
+
+#include "runtime.h"
+
+#else
#include "tconfig.h"
#include "tsystem.h"
+#endif
+
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
system provides the routine readdir_r.
... but we never define it anywhere??? */
#undef HAVE_READDIR_R
-\f
+
#define MAYBE_TO_PTR32(argv) argv
static const char ATTR_UNSET = 127;
struct tm *res;
time_t time = (time_t) *p_time;
-#ifdef _WIN32
- /* On Windows systems, the time is sometimes rounded up to the nearest
- even second, so if the number of seconds is odd, increment it. */
- if (time & 1)
- time++;
-#endif
-
res = gmtime (&time);
if (res)
{
__gnat_get_executable_suffix_ptr (int *len, const char **value)
{
*value = HOST_EXECUTABLE_SUFFIX;
+
if (!*value)
*len = 0;
else
}
#if defined (_WIN32) || defined (__linux__) || defined (__sun__) \
- || defined (__FreeBSD__) || defined(__DragonFly__)
+ || defined (__FreeBSD__) || defined(__DragonFly__) || defined (__QNX__)
#define HAS_TARGET_WCHAR_T
#endif
/* Fill up the name buffer from the last position. */
seed++;
- for (t = seed; 0 <= --index; t >>= 3)
+ for (t = seed; --index >= 0; t >>= 3)
*--pos = '0' + (t & 07);
/* Check to see if its unique, if not bump the seed and try again. */
utimbuf.modtime = time_stamp;
/* Set access time to now in local time. */
- t = time ((time_t) 0);
+ t = time (NULL);
utimbuf.actime = mktime (localtime (&t));
utime (name, &utimbuf);
|| defined (__DragonFly__) || defined (__NetBSD__)
cores = (int) sysconf (_SC_NPROCESSORS_ONLN);
+#elif defined (__QNX__)
+ cores = (int) _syspage_ptr->num_cpu;
+
#elif defined (__hpux__)
struct pst_dynamic psd;
if (pstat_getdynamic (&psd, sizeof (psd), 1, 0) != -1)
#else
/* Note that index 0 contains the event handle that is signaled when the
process list has changed */
- hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len + 1);
+ hl = (HANDLE *) xmalloc (sizeof (HANDLE) * (hl_len + 1));
hl[0] = ProcListEvt;
memmove (&hl[1], HANDLES_LIST, sizeof (HANDLE) * hl_len);
- pidl = (int *) xmalloc (sizeof (int) * hl_len + 1);
+ pidl = (int *) xmalloc (sizeof (int) * (hl_len + 1));
memmove (&pidl[1], PID_LIST, sizeof (int) * hl_len);
hl_len++;
#endif
/* If there was an error, exit now */
if (res == WAIT_FAILED)
{
+ free (hl);
+ free (pidl);
errno = EINVAL;
return -1;
}
char *
__gnat_locate_exec (char *exec_name, char *path_val)
{
+ const unsigned int len = strlen (HOST_EXECUTABLE_SUFFIX);
char *ptr;
- if (!strstr (exec_name, HOST_EXECUTABLE_SUFFIX))
+
+ if (len > 0 && !strstr (exec_name, HOST_EXECUTABLE_SUFFIX))
{
- char *full_exec_name =
- (char *) alloca
- (strlen (exec_name) + strlen (HOST_EXECUTABLE_SUFFIX) + 1);
+ char *full_exec_name = (char *) alloca (strlen (exec_name) + len + 1);
strcpy (full_exec_name, exec_name);
strcat (full_exec_name, HOST_EXECUTABLE_SUFFIX);
#endif
#if defined (__APPLE__)
-#include <mach/thread_info.h>
-#include <mach/mach_init.h>
-#include <mach/thread_act.h>
+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060
+# include <mach/thread_info.h>
+# include <mach/mach_init.h>
+# include <mach/thread_act.h>
+# else
+# include <pthread.h>
+# endif
/* System-wide thread identifier. Note it could be truncated on 32 bit
hosts.
void *
__gnat_lwp_self (void)
{
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060
thread_identifier_info_data_t data;
mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
kern_return_t kret;
return (void *)(uintptr_t)data.thread_id;
else
return 0;
+#else
+ return (void *)pthread_mach_thread_np (pthread_self ());
+#endif
}
#endif