netatalk: compat.h Source File

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
compat.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1996 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
4 */
5
6#ifndef _ATALK_COMPAT_H
7#define _ATALK_COMPAT_H
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include <signal.h>
14#include <sys/stat.h>
15#include <sys/time.h>
16#include <time.h>
17
18/* OpenBSD */
19#if defined(__OpenBSD__) && !defined(ENOTSUP)
20#define ENOTSUP EOPNOTSUPP
21#endif
22
23#if !defined(HAVE_PSELECT) || defined(__OpenBSD__)
24 extern int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
25 const sigset_t *);
26#endif
27
28#ifndef HAVE_STRNLEN
29extern size_t strnlen(const char *s, size_t n);
30#endif
31
32#ifndef HAVE_STRLCPY
33extern size_t strlcpy(char *, const char *, size_t);
34#endif
35
36#ifndef HAVE_STRLCAT
37extern size_t strlcat(char *, const char *, size_t);
38#endif
39
40#ifndef HAVE_VASPRINTF
41#include <stdio.h>
42#include <stdarg.h>
43extern int vasprintf(char **ret, const char *fmt, va_list ap);
44#endif
45
46/* Secure memory clearing - prefer memset_explicit (C23) over explicit_bzero */
47#if !defined(HAVE_MEMSET_EXPLICIT) && !defined(HAVE_EXPLICIT_BZERO)
48#include <stddef.h>
49extern void explicit_bzero(void *s, size_t n);
50#elif defined(HAVE_MEMSET_EXPLICIT) && !defined(HAVE_EXPLICIT_BZERO)
51#include <string.h>
52#define explicit_bzero(s, n) memset_explicit((s), 0, (n))
53#endif
54
55 static inline struct timespec atalk_stat_mtime_timespec(const struct stat *st)
56{
57 struct timespec ts;
58#if defined(HAVE_STRUCT_STAT_ST_MTIM)
59 ts = st->st_mtim;
60#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
61 ts = st->st_mtimespec;
62#else
63 ts.tv_sec = st->st_mtime;
64 ts.tv_nsec = 0;
65#endif
66 return ts;
67}
68
69 static inline struct timespec atalk_stat_atime_timespec(const struct stat *st)
70{
71 struct timespec ts;
72#if defined(HAVE_STRUCT_STAT_ST_ATIM)
73 ts = st->st_atim;
74#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
75 ts = st->st_atimespec;
76#else
77 ts.tv_sec = st->st_atime;
78 ts.tv_nsec = 0;
79#endif
80 return ts;
81}
82
83 static inline void atalk_timespec_to_timeval(struct timeval *tv,
84 const struct timespec *ts)
85{
86 tv->tv_sec = ts->tv_sec;
87 tv->tv_usec = ts->tv_nsec / 1000;
88}
89
90#endif /* _ATALK_COMPAT_H */
atalk_stat_atime_timespec
static struct timespec atalk_stat_atime_timespec(const struct stat *st)
Definition compat.h:69
explicit_bzero
void explicit_bzero(void *s, size_t n)
Definition explicit_bzero.c:32
vasprintf
int vasprintf(char **ret, const char *fmt, va_list ap)
Definition misc.c:34
strlcat
size_t strlcat(char *, const char *, size_t)
Definition strlcpy.c:59
strlcpy
size_t strlcpy(char *, const char *, size_t)
Definition strlcpy.c:36
strnlen
size_t strnlen(const char *s, size_t n)
Definition misc.c:19
atalk_timespec_to_timeval
static void atalk_timespec_to_timeval(struct timeval *tv, const struct timespec *ts)
Definition compat.h:83
atalk_stat_mtime_timespec
static struct timespec atalk_stat_mtime_timespec(const struct stat *st)
Definition compat.h:55
pselect
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *)
config.h