2026-04-02 16:00:27 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2026-04-02 16:25:49 +02:00
|
|
|
// Copyright (C) 2011 Andrea Mazzoleni
|
2013-02-27 20:20:49 +01:00
|
|
|
|
|
|
|
|
#ifndef __UNIX_H
|
|
|
|
|
#define __UNIX_H
|
|
|
|
|
|
2015-01-02 22:51:10 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
|
#define HAVE_LINUX_DEVICE 1 /**< In Linux enables special device support. */
|
2016-05-15 14:18:44 +02:00
|
|
|
#define HAVE_DIRECT_IO 1 /**< Support O_DIRECT in open(). */
|
2015-01-02 22:51:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
2013-02-27 20:20:49 +01:00
|
|
|
#define O_BINARY 0 /**< Not used in Unix. */
|
|
|
|
|
#define O_SEQUENTIAL 0 /**< In Unix posix_fadvise() shall be used. */
|
|
|
|
|
|
2026-04-04 20:02:30 +02:00
|
|
|
|
|
|
|
|
#if HAVE_POSIX_FADVISE
|
|
|
|
|
int posix_fadvise_wrapper(int fd, off_t offset, off_t len, int advice);
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-08-18 18:02:25 +02:00
|
|
|
/**
|
|
|
|
|
* If nanoseconds are not supported, we report the special STAT_NSEC_INVALID value,
|
|
|
|
|
* to mark that it's undefined.
|
|
|
|
|
*/
|
|
|
|
|
#define STAT_NSEC_INVALID -1
|
|
|
|
|
|
2013-02-27 20:20:49 +01:00
|
|
|
/* Check if we have nanoseconds support */
|
|
|
|
|
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
2017-10-27 22:54:42 +02:00
|
|
|
#define STAT_NSEC(st) ((int)(st)->st_mtim.tv_nsec) /* Linux */
|
2013-02-27 20:20:49 +01:00
|
|
|
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
|
2017-10-27 22:54:42 +02:00
|
|
|
#define STAT_NSEC(st) ((int)(st)->st_mtimensec) /* NetBSD */
|
2013-02-27 20:20:49 +01:00
|
|
|
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
|
2017-10-27 22:54:42 +02:00
|
|
|
#define STAT_NSEC(st) ((int)(st)->st_mtimespec.tv_nsec) /* FreeBSD, Mac OS X */
|
2013-02-27 20:20:49 +01:00
|
|
|
#else
|
2013-08-18 18:02:25 +02:00
|
|
|
#define STAT_NSEC(st) STAT_NSEC_INVALID
|
2013-02-27 20:20:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-02 16:52:20 +01:00
|
|
|
* Open a file with the O_NOATIME flag to avoid to update the access time.
|
2013-02-27 20:20:49 +01:00
|
|
|
*/
|
|
|
|
|
int open_noatime(const char* file, int flags);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the specified file is hidden.
|
|
|
|
|
*/
|
|
|
|
|
int dirent_hidden(struct dirent* dd);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a description of the file type.
|
|
|
|
|
*/
|
|
|
|
|
const char* stat_desc(struct stat* st);
|
|
|
|
|
|
2016-05-15 14:18:44 +02:00
|
|
|
/**
|
2020-05-02 14:21:40 +02:00
|
|
|
* Return the alignment requirement for direct IO.
|
2016-05-15 14:18:44 +02:00
|
|
|
*/
|
|
|
|
|
size_t direct_size(void);
|
|
|
|
|
|
2026-03-02 01:13:19 +01:00
|
|
|
/****************************************************************************/
|
|
|
|
|
/* thread */
|
|
|
|
|
|
|
|
|
|
#if HAVE_PTHREAD_H
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-04-30 11:38:01 +02:00
|
|
|
#if HAVE_PTHREAD
|
2026-03-02 01:13:19 +01:00
|
|
|
#define HAVE_THREAD 1
|
|
|
|
|
typedef pthread_t thread_id_t;
|
|
|
|
|
typedef pthread_mutex_t thread_mutex_t;
|
|
|
|
|
typedef pthread_cond_t thread_cond_t;
|
2026-05-29 11:01:44 +02:00
|
|
|
typedef pthread_key_t thread_key_t;
|
2026-03-02 01:13:19 +01:00
|
|
|
#endif
|
|
|
|
|
|
2013-02-27 20:20:49 +01:00
|
|
|
#endif
|
|
|
|
|
|