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) && !defined(LIBMAPI) 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 : #ifdef NATIVE_WIN32 27 : 28 : #include <stdio.h> 29 : 30 : #define F_TEST 3 /* test a region for other processes locks. */ 31 : #define F_TLOCK 2 /* test and lock a region for exclusive use */ 32 : #define F_ULOCK 0 /* unlock a previously locked region */ 33 : #define F_LOCK 1 /* lock a region for exclusive use */ 34 : 35 : struct DIR; 36 : 37 : typedef struct DIR DIR; 38 : struct dirent { 39 : char d_name[FILENAME_MAX]; 40 : int d_namelen; 41 : }; 42 : 43 : mutils_export int winerror(int); 44 : mutils_export DIR *opendir(const char *dirname); 45 : mutils_export struct dirent *readdir(DIR *dir); 46 : mutils_export void rewinddir(DIR *dir); 47 : mutils_export int closedir(DIR *dir); 48 : 49 : mutils_export char *dirname(char *path); 50 : 51 : mutils_export wchar_t *utf8towchar(const char *src); 52 : mutils_export char *wchartoutf8(const wchar_t *src); 53 : 54 : mutils_export FILE *MT_fopen(const char *filename, const char *mode); 55 : mutils_export int MT_open(const char *filename, int flags); 56 : mutils_export int MT_stat(const char *filename, struct stat *stb); 57 : mutils_export int MT_rmdir(const char *dirname); 58 : mutils_export int MT_rename(const char *old, const char *new); 59 : mutils_export int MT_remove(const char *filename); 60 : mutils_export int MT_mkdir(const char *dirname); 61 : mutils_export char *MT_getcwd(char *buffer, size_t size); 62 : mutils_export int MT_access(const char *pathname, int mode); 63 : 64 : #else 65 : 66 : #include <stdlib.h> 67 : #include <fcntl.h> 68 : #include <unistd.h> 69 : #include <sys/stat.h> 70 : 71 : #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) 72 : #define MONETDB_DIRMODE (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH) 73 : 74 : static inline FILE * 75 170116 : MT_fopen(const char *filename, const char *mode) 76 : { 77 170116 : return fopen(filename, mode); 78 : } 79 : 80 : static inline int 81 442092 : MT_open(const char *filename, int flags) 82 : { 83 442092 : return open(filename, flags, MONETDB_MODE); 84 : } 85 : 86 : static inline int 87 3319037 : MT_stat(const char *filename, struct stat *stb) 88 : { 89 3319037 : return stat(filename, stb); 90 : } 91 : 92 : static inline int 93 51922 : MT_mkdir(const char *dirname) 94 : { 95 51922 : return mkdir(dirname, MONETDB_DIRMODE); 96 : } 97 : 98 : static inline int 99 12831 : MT_rmdir(const char *dirname) 100 : { 101 12831 : return rmdir(dirname); 102 : } 103 : 104 : static inline int 105 2775633 : MT_rename(const char *old, const char *new) 106 : { 107 2775633 : return rename(old, new); 108 : } 109 : 110 : static inline int 111 372021 : MT_remove(const char *filename) 112 : { 113 372021 : return remove(filename); 114 : } 115 : 116 : static inline char * 117 318 : MT_getcwd(char *buffer, size_t size) 118 : { 119 318 : return getcwd(buffer, size); 120 : } 121 : 122 : static inline int 123 631 : MT_access(const char *pathname, int mode) 124 : { 125 631 : return access(pathname, mode); 126 : } 127 : 128 : #endif 129 : 130 : mutils_export int MT_lockf(const char *filename, int mode); 131 : 132 : mutils_export void print_trace(void); 133 : 134 : /* Retrieves the absolute path to the executable being run, with no 135 : * extra /, /./, or /../ sequences. On Darwin and Solaris this function 136 : * needs to be called before any chdirs are performed. Returns a 137 : * pointer to a static buffer that is overwritten by subsequent calls to 138 : * this function. */ 139 : mutils_export char *get_bin_path(void); 140 : 141 : /* Returns the Mercurial changeset of the current checkout, if available */ 142 : mutils_export const char *mercurial_revision(void) 143 : __attribute__((__const__)); 144 : 145 : #endif /* _MUTILS_H_ */