LCOV - code coverage report
Current view: top level - common/utils - mutils.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 18 100.0 %
Date: 2024-04-25 20:03:45 Functions: 0 0 -

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #ifndef _MUTILS_H_
      14             : #define _MUTILS_H_
      15             : 
      16             : #ifdef WIN32
      17             : #if !defined(LIBMUTILS) && !defined(LIBGDK) && !defined(LIBMEROUTIL)
      18             : #define mutils_export extern __declspec(dllimport)
      19             : #else
      20             : #define mutils_export extern __declspec(dllexport)
      21             : #endif
      22             : #else
      23             : #define mutils_export extern
      24             : #endif
      25             : 
      26             : #ifndef S_IWGRP
      27             : /* if one doesn't exist, presumably they all don't exist - Not so on MinGW */
      28             : #define S_IRUSR 0000400         /* read permission, owner */
      29             : #define S_IWUSR 0000200         /* write permission, owner */
      30             : #define S_IXUSR 0000100         /* execute permission, owner */
      31             : #define S_IRGRP 0000040         /* read permission, group */
      32             : #define S_IWGRP 0000020         /* write permission, group */
      33             : #define S_IXGRP 0000010         /* execute permission, group */
      34             : #define S_IROTH 0000004         /* read permission, other */
      35             : #define S_IWOTH 0000002         /* write permission, other */
      36             : #define S_IXOTH 0000001         /* execute permission, other */
      37             : #endif
      38             : 
      39             : #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
      40             : #define MONETDB_DIRMODE         (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
      41             : 
      42             : #ifdef NATIVE_WIN32
      43             : 
      44             : #include <stdio.h>
      45             : 
      46             : #define F_TEST  3               /* test a region for other processes locks.  */
      47             : #define F_TLOCK 2               /* test and lock a region for exclusive use */
      48             : #define F_ULOCK 0               /* unlock a previously locked region */
      49             : #define F_LOCK  1               /* lock a region for exclusive use */
      50             : 
      51             : struct DIR;
      52             : 
      53             : typedef struct DIR DIR;
      54             : struct dirent {
      55             :         char d_name[FILENAME_MAX];
      56             :         int d_namelen;
      57             : };
      58             : 
      59             : mutils_export int winerror(int);
      60             : mutils_export DIR *opendir(const char *dirname);
      61             : mutils_export struct dirent *readdir(DIR *dir);
      62             : mutils_export void rewinddir(DIR *dir);
      63             : mutils_export int closedir(DIR *dir);
      64             : 
      65             : mutils_export char *dirname(char *path);
      66             : 
      67             : mutils_export wchar_t *utf8towchar(const char *src);
      68             : mutils_export char *wchartoutf8(const wchar_t *src);
      69             : 
      70             : mutils_export FILE *MT_fopen(const char *filename, const char *mode);
      71             : mutils_export int MT_open(const char *filename, int flags);
      72             : mutils_export int MT_stat(const char *filename, struct stat *stb);
      73             : mutils_export int MT_rmdir(const char *dirname);
      74             : mutils_export int MT_rename(const char *old, const char *new);
      75             : mutils_export int MT_remove(const char *filename);
      76             : mutils_export int MT_mkdir(const char *dirname);
      77             : mutils_export char *MT_getcwd(char *buffer, size_t size);
      78             : mutils_export int MT_access(const char *pathname, int mode);
      79             : 
      80             : #else
      81             : 
      82             : #include <stdlib.h>
      83             : #include <fcntl.h>
      84             : #include <unistd.h>
      85             : #include <sys/stat.h>
      86             : 
      87             : #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
      88             : #define MONETDB_DIRMODE         (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
      89             : 
      90             : static inline FILE *
      91      168481 : MT_fopen(const char *filename, const char *mode)
      92             : {
      93      168481 :         return fopen(filename, mode);
      94             : }
      95             : 
      96             : static inline int
      97      418433 : MT_open(const char *filename, int flags)
      98             : {
      99      418433 :         return open(filename, flags, MONETDB_MODE);
     100             : }
     101             : 
     102             : static inline int
     103     2996050 : MT_stat(const char *filename, struct stat *stb)
     104             : {
     105     2996050 :         return stat(filename, stb);
     106             : }
     107             : 
     108             : static inline int
     109       71536 : MT_mkdir(const char *dirname)
     110             : {
     111       71536 :         return mkdir(dirname, MONETDB_DIRMODE);
     112             : }
     113             : 
     114             : static inline int
     115       12046 : MT_rmdir(const char *dirname)
     116             : {
     117       12046 :         return rmdir(dirname);
     118             : }
     119             : 
     120             : static inline int
     121      263690 : MT_rename(const char *old, const char *new)
     122             : {
     123      263690 :         return rename(old, new);
     124             : }
     125             : 
     126             : static inline int
     127      295520 : MT_remove(const char *filename)
     128             : {
     129      295520 :         return remove(filename);
     130             : }
     131             : 
     132             : static inline char *
     133         327 : MT_getcwd(char *buffer, size_t size)
     134             : {
     135         327 :         return getcwd(buffer, size);
     136             : }
     137             : 
     138             : static inline int
     139         671 : MT_access(const char *pathname, int mode)
     140             : {
     141         671 :         return access(pathname, mode);
     142             : }
     143             : 
     144             : #endif
     145             : 
     146             : mutils_export int MT_lockf(const char *filename, int mode);
     147             : 
     148             : mutils_export void print_trace(void);
     149             : 
     150             : /* Retrieves the absolute path to the executable being run, with no
     151             :  * extra /, /./, or /../ sequences.  On Darwin and Solaris this function
     152             :  * needs to be called before any chdirs are performed.  Returns a
     153             :  * pointer to a static buffer that is overwritten by subsequent calls to
     154             :  * this function. */
     155             : mutils_export char *get_bin_path(void);
     156             : 
     157             : /* Returns the Mercurial changeset of the current checkout, if available */
     158             : mutils_export const char *mercurial_revision(void)
     159             :         __attribute__((__const__));
     160             : 
     161             : #endif  /* _MUTILS_H_ */

Generated by: LCOV version 1.14