LCOV - code coverage report
Current view: top level - common/utils - mutils.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 8 100.0 %
Date: 2021-10-27 03:06:47 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 _MUTILS_H_
      10             : #define _MUTILS_H_
      11             : 
      12             : #ifdef WIN32
      13             : #if !defined(LIBMUTILS) && !defined(LIBGDK) && !defined(LIBMEROUTIL)
      14             : #define mutils_export extern __declspec(dllimport)
      15             : #else
      16             : #define mutils_export extern __declspec(dllexport)
      17             : #endif
      18             : #else
      19             : #define mutils_export extern
      20             : #endif
      21             : 
      22             : #ifndef S_IWGRP
      23             : /* if one doesn't exist, presumably they all don't exist - Not so on MinGW */
      24             : #define S_IRUSR 0000400         /* read permission, owner */
      25             : #define S_IWUSR 0000200         /* write permission, owner */
      26             : #define S_IXUSR 0000100         /* execute permission, owner */
      27             : #define S_IRGRP 0000040         /* read permission, group */
      28             : #define S_IWGRP 0000020         /* write permission, group */
      29             : #define S_IXGRP 0000010         /* execute permission, group */
      30             : #define S_IROTH 0000004         /* read permission, other */
      31             : #define S_IWOTH 0000002         /* write permission, other */
      32             : #define S_IXOTH 0000001         /* execute permission, other */
      33             : #endif
      34             : 
      35             : #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
      36             : #define MONETDB_DIRMODE         (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
      37             : 
      38             : #define F_TEST  3               /* test a region for other processes locks.  */
      39             : #define F_TLOCK 2               /* test and lock a region for exclusive use */
      40             : #define F_ULOCK 0               /* unlock a previously locked region */
      41             : #define F_LOCK  1               /* lock a region for exclusive use */
      42             : 
      43             : #ifdef NATIVE_WIN32
      44             : 
      45             : #include <stdio.h>
      46             : 
      47             : struct DIR;
      48             : 
      49             : typedef struct DIR DIR;
      50             : struct dirent {
      51             :         char d_name[FILENAME_MAX];
      52             :         int d_namelen;
      53             : };
      54             : 
      55             : mutils_export int winerror(int);
      56             : mutils_export DIR *opendir(const char *dirname);
      57             : mutils_export struct dirent *readdir(DIR *dir);
      58             : mutils_export void rewinddir(DIR *dir);
      59             : mutils_export int closedir(DIR *dir);
      60             : 
      61             : mutils_export char *dirname(char *path);
      62             : 
      63             : mutils_export wchar_t *utf8towchar(const char *src);
      64             : mutils_export char *wchartoutf8(const wchar_t *src);
      65             : 
      66             : mutils_export FILE *MT_fopen(const char *filename, const char *mode);
      67             : mutils_export int MT_open(const char *filename, int flags);
      68             : mutils_export int MT_stat(const char *filename, struct stat *stb);
      69             : mutils_export int MT_rmdir(const char *dirname);
      70             : mutils_export int MT_rename(const char *old, const char *new);
      71             : mutils_export int MT_remove(const char *filename);
      72             : mutils_export int MT_mkdir(const char *dirname);
      73             : mutils_export char *MT_getcwd(char *buffer, size_t size);
      74             : mutils_export int MT_access(const char *pathname, int mode);
      75             : 
      76             : #else
      77             : 
      78             : #include <stdlib.h>
      79             : #include <fcntl.h>
      80             : #include <unistd.h>
      81             : #include <sys/stat.h>
      82             : 
      83             : #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
      84             : #define MONETDB_DIRMODE         (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
      85             : 
      86             : static inline FILE *
      87             : MT_fopen(const char *filename, const char *mode)
      88             : {
      89       41418 :         return fopen(filename, mode);
      90             : }
      91             : 
      92             : static inline int
      93             : MT_open(const char *filename, int flags)
      94             : {
      95      740538 :         return open(filename, flags, MONETDB_MODE);
      96             : }
      97             : 
      98             : static inline int
      99             : MT_stat(const char *filename, struct stat *stb)
     100             : {
     101             :         return stat(filename, stb);
     102             : }
     103             : 
     104             : static inline int
     105             : MT_mkdir(const char *dirname)
     106             : {
     107       37521 :         return mkdir(dirname, MONETDB_DIRMODE);
     108             : }
     109             : 
     110             : static inline int
     111             : MT_rmdir(const char *dirname)
     112             : {
     113       16230 :         return rmdir(dirname);
     114             : }
     115             : 
     116             : static inline int
     117             : MT_rename(const char *old, const char *new)
     118             : {
     119      229050 :         return rename(old, new);
     120             : }
     121             : 
     122             : static inline int
     123             : MT_remove(const char *filename)
     124             : {
     125    20076054 :         return remove(filename);
     126             : }
     127             : 
     128             : static inline char *
     129             : MT_getcwd(char *buffer, size_t size)
     130             : {
     131         255 :         return getcwd(buffer, size);
     132             : }
     133             : 
     134             : static inline int
     135             : MT_access(const char *pathname, int mode)
     136             : {
     137       60791 :         return access(pathname, mode);
     138             : }
     139             : 
     140             : #endif
     141             : 
     142             : mutils_export int MT_lockf(const char *filename, int mode);
     143             : 
     144             : mutils_export void print_trace(void);
     145             : 
     146             : /* Retrieves the absolute path to the executable being run, with no
     147             :  * extra /, /./, or /../ sequences.  On Darwin and Solaris this function
     148             :  * needs to be called before any chdirs are performed.  Returns a
     149             :  * pointer to a static buffer that is overwritten by subsequent calls to
     150             :  * this function. */
     151             : mutils_export char *get_bin_path(void);
     152             : 
     153             : /* Returns the Mercurial changeset of the current checkout, if available */
     154             : mutils_export const char *mercurial_revision(void)
     155             :         __attribute__((__const__));
     156             : 
     157             : #endif  /* _MUTILS_H_ */

Generated by: LCOV version 1.14