LCOV - code coverage report
Current view: top level - gdk - gdk_posix.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2021-09-14 19:48:19 Functions: 0 0 -

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #ifndef GDK_POSIX_H
      10             : #define GDK_POSIX_H
      11             : 
      12             : #include <sys/types.h>
      13             : 
      14             : #include <time.h>
      15             : 
      16             : #ifdef HAVE_FTIME
      17             : #include <sys/timeb.h>            /* ftime */
      18             : #endif
      19             : #ifdef HAVE_SYS_TIME_H
      20             : #include <sys/time.h>             /* gettimeofday */
      21             : #endif
      22             : 
      23             : #ifndef HAVE_SYS_SOCKET_H
      24             : #ifdef HAVE_WINSOCK_H
      25             : #include <winsock.h>              /* for timeval */
      26             : #endif
      27             : #endif
      28             : 
      29             : #include "gdk_system.h" /* gdk_export */
      30             : 
      31             : #ifdef NATIVE_WIN32
      32             : #include <io.h>
      33             : #include <direct.h>
      34             : #endif
      35             : 
      36             : /*
      37             :  * @- virtual memory
      38             :  */
      39             : #define MT_VMUNITLOG    16
      40             : #define MT_VMUNITSIZE   (1 << MT_VMUNITLOG)
      41             : 
      42             : /* make sure POSIX_MADV_* and posix_madvise() are defined somehow */
      43             : #ifdef HAVE_SYS_MMAN_H
      44             : # ifndef __USE_BSD
      45             : #  define __USE_BSD
      46             : # endif
      47             : # include <sys/mman.h>
      48             : #endif
      49             : 
      50             : #ifdef __linux__
      51             : /* on Linux, posix_madvise does not seem to work, fall back to classic
      52             :  * madvise */
      53             : #undef HAVE_POSIX_MADVISE
      54             : #undef HAVE_POSIX_FADVISE
      55             : #undef POSIX_MADV_NORMAL
      56             : #undef POSIX_MADV_RANDOM
      57             : #undef POSIX_MADV_SEQUENTIAL
      58             : #undef POSIX_MADV_WILLNEED
      59             : #undef POSIX_MADV_DONTNEED
      60             : #endif
      61             : 
      62             : #ifndef HAVE_POSIX_MADVISE
      63             : # ifdef HAVE_MADVISE
      64             : #  define posix_madvise madvise
      65             : #  define HAVE_POSIX_MADVISE 1
      66             : #  ifndef MADV_RANDOM
      67             : #   define MADV_RANDOM  0
      68             : #  endif
      69             : #  ifndef POSIX_MADV_NORMAL
      70             : #   define POSIX_MADV_NORMAL     MADV_NORMAL
      71             : #   define POSIX_MADV_RANDOM     MADV_RANDOM
      72             : #   define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
      73             : #   define POSIX_MADV_WILLNEED   MADV_WILLNEED
      74             : #   define POSIX_MADV_DONTNEED   MADV_DONTNEED
      75             : #  endif
      76             : # else
      77             : #  define posix_madvise(x,y,z)  0
      78             : #  ifndef POSIX_MADV_NORMAL
      79             : #   define POSIX_MADV_NORMAL     0
      80             : #   define POSIX_MADV_RANDOM     0
      81             : #   define POSIX_MADV_SEQUENTIAL 0
      82             : #   define POSIX_MADV_WILLNEED   0
      83             : #   define POSIX_MADV_DONTNEED   0
      84             : #  endif
      85             : # endif
      86             : #endif
      87             : 
      88             : /* in case they are still not defined, define these values as
      89             :  * something that doesn't do anything */
      90             : #ifndef POSIX_MADV_NORMAL
      91             : #define POSIX_MADV_NORMAL 0
      92             : #endif
      93             : #ifndef POSIX_MADV_RANDOM
      94             : #define POSIX_MADV_RANDOM 0
      95             : #endif
      96             : #ifndef POSIX_MADV_SEQUENTIAL
      97             : #define POSIX_MADV_SEQUENTIAL 0
      98             : #endif
      99             : #ifndef POSIX_MADV_WILLNEED
     100             : #define POSIX_MADV_WILLNEED 0
     101             : #endif
     102             : #ifndef POSIX_MADV_DONTNEED
     103             : #define POSIX_MADV_DONTNEED 0
     104             : #endif
     105             : 
     106             : /* the new mmap modes, mimic default MADV_* madvise POSIX constants */
     107             : #define MMAP_NORMAL     POSIX_MADV_NORMAL       /* no further special treatment */
     108             : #define MMAP_RANDOM     POSIX_MADV_RANDOM       /* expect random page references */
     109             : #define MMAP_SEQUENTIAL POSIX_MADV_SEQUENTIAL   /* expect sequential page references */
     110             : #define MMAP_WILLNEED   POSIX_MADV_WILLNEED     /* will need these pages */
     111             : #define MMAP_DONTNEED   POSIX_MADV_DONTNEED     /* don't need these pages */
     112             : 
     113             : #define MMAP_READ               1024    /* region is readable (default if ommitted) */
     114             : #define MMAP_WRITE              2048    /* region may be written into */
     115             : #define MMAP_COPY               4096    /* writable, but changes never reach file */
     116             : #define MMAP_ASYNC              8192    /* asynchronous writes (default if ommitted) */
     117             : #define MMAP_SYNC               16384   /* writing is done synchronously */
     118             : 
     119             : /* in order to be sure of madvise and msync modes, pass them to mmap()
     120             :  * call as well */
     121             : 
     122             : gdk_export size_t MT_getrss(void);
     123             : 
     124             : gdk_export bool MT_path_absolute(const char *path);
     125             : 
     126             : 
     127             : /*
     128             :  * @+ Posix under WIN32
     129             :  * WIN32 actually supports many Posix functions directly.  Some it
     130             :  * does not, though.  For some functionality we move in Monet from
     131             :  * Posix calls to MT_*() calls, which translate easier to WIN32.
     132             :  * Examples are MT_mmap() , MT_sleep_ms() and MT_path_absolute(). Why?
     133             :  * In the case of mmap() it is much easier for WIN32 to get a filename
     134             :  * parameter rather than a file-descriptor.  That is the reason in the
     135             :  * case of mmap() to go for a MT_mmap() solution.
     136             :  *
     137             :  * For some other functionality, we do not need to abandon the Posix
     138             :  * interface, though. Two cases can be distinguished.  Missing
     139             :  * functions in WIN32 are directly implemented
     140             :  * (e.g. dlopen()/dlsym()/dlclose()).  Posix functions in WIN32 whose
     141             :  * functionality should be changed a bit. Examples are
     142             :  * stat()/rename()/mkdir()/rmdir() who under WIN32 do not work if the
     143             :  * path ends with a directory separator, but should work according to
     144             :  * Posix. We remap such functions using a define to an equivalent
     145             :  * win_*() function (which in its implementation calls through to the
     146             :  * WIN32 function).
     147             :  */
     148             : gdk_export void *mdlopen(const char *library, int mode);
     149             : 
     150             : 
     151             : #ifdef NATIVE_WIN32
     152             : 
     153             : #define RTLD_LAZY       1
     154             : #define RTLD_NOW        2
     155             : #define RTLD_GLOBAL     4
     156             : 
     157             : gdk_export void *dlopen(const char *file, int mode);
     158             : gdk_export int dlclose(void *handle);
     159             : gdk_export void *dlsym(void *handle, const char *name);
     160             : gdk_export char *dlerror(void);
     161             : 
     162             : #ifndef HAVE_GETTIMEOFDAY
     163             : gdk_export int gettimeofday(struct timeval *tv, int *ignore_zone);
     164             : #endif
     165             : 
     166             : #endif  /* NATIVE_WIN32 */
     167             : 
     168             : #ifndef HAVE_LOCALTIME_R
     169             : gdk_export struct tm *localtime_r(const time_t *restrict, struct tm *restrict);
     170             : #endif
     171             : #ifndef HAVE_GMTIME_R
     172             : gdk_export struct tm *gmtime_r(const time_t *restrict, struct tm *restrict);
     173             : #endif
     174             : #ifndef HAVE_ASCTIME_R
     175             : gdk_export char *asctime_r(const struct tm *restrict, char *restrict);
     176             : #endif
     177             : #ifndef HAVE_CTIME_R
     178             : gdk_export char *ctime_r(const time_t *restrict, char *restrict);
     179             : #endif
     180             : #ifndef HAVE_STRERROR_R
     181             : gdk_export int strerror_r(int errnum, char *buf, size_t buflen);
     182             : #endif
     183             : 
     184             : static inline const char *
     185             : GDKstrerror(int errnum, char *buf, size_t buflen)
     186             : {
     187             : #if !defined(_GNU_SOURCE) || ((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
     188             :         if (strerror_r(errnum, buf, buflen) == 0)
     189             :                 return buf;
     190             :         snprintf(buf, buflen, "Unknown error %d", errnum);
     191             :         return buf;
     192             : #else
     193           1 :         return strerror_r(errnum, buf, buflen);
     194             : #endif
     195             : }
     196             : 
     197             : #endif /* GDK_POSIX_H */

Generated by: LCOV version 1.14