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 - 2019 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#ifdef NATIVE_WIN32
23
24#include <stdio.h>
25
26struct DIR {
27 char *dir_name;
28 int just_opened;
29 HANDLE find_file_handle;
30 void *find_file_data;
31};
32
33typedef struct DIR DIR;
34struct dirent {
35 char d_name[FILENAME_MAX];
36 int d_namelen;
37};
38
39mutils_export int winerror(int);
40mutils_export DIR *opendir(const char *dirname);
41mutils_export struct dirent *readdir(DIR *dir);
42mutils_export void rewinddir(DIR *dir);
43mutils_export int closedir(DIR *dir);
44
45mutils_export char *dirname(char *path);
46
47#endif
48
49#ifndef S_IWGRP
50/* if one doesn't exist, presumably they all don't exist - Not so on MinGW */
51#define S_IRUSR 0000400 /* read permission, owner */
52#define S_IWUSR 0000200 /* write permission, owner */
53#define S_IXUSR 0000100 /* execute permission, owner */
54#define S_IRGRP 0000040 /* read permission, group */
55#define S_IWGRP 0000020 /* write permission, group */
56#define S_IXGRP 0000010 /* execute permission, group */
57#define S_IROTH 0000004 /* read permission, other */
58#define S_IWOTH 0000002 /* write permission, other */
59#define S_IXOTH 0000001 /* execute permission, other */
60#endif
61
62#define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
63#define MONETDB_DIRMODE (MONETDB_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
64
65#define F_TEST 3 /* test a region for other processes locks. */
66#define F_TLOCK 2 /* test and lock a region for exclusive use */
67#define F_ULOCK 0 /* unlock a previously locked region */
68#define F_LOCK 1 /* lock a region for exclusive use */
69
70mutils_export int MT_lockf(char *filename, int mode, off_t off, off_t len);
71
72mutils_export void print_trace(void);
73
74/* Retrieves the absolute path to the executable being run, with no
75 * extra /, /./, or /../ sequences. On Darwin and Solaris this function
76 * needs to be called before any chdirs are performed. Returns a
77 * pointer to a static buffer that is overwritten by subsequent calls to
78 * this function. */
79mutils_export char *get_bin_path(void);
80
81/* Returns the Mercurial changeset of the current checkout, if available */
82mutils_export const char *mercurial_revision(void);
83
84#endif /* _MUTILS_H_ */
85