-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathoscompat.h
More file actions
47 lines (36 loc) · 1017 Bytes
/
oscompat.h
File metadata and controls
47 lines (36 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef __OSCOMPAT_H__
#define __OSCOMPAT_H__
#include <ctype.h>
#include <stdbool.h>
#ifndef _WIN32
#include <err.h>
#define O_BINARY 0
#else // _WIN32
#include <sys/time.h>
void timeradd(const struct timeval *a, const struct timeval *b, struct timeval *result);
void err(int eval, const char *fmt, ...);
void errx(int eval, const char *fmt, ...);
void warn(const char *fmt, ...);
void warnx(const char *fmt, ...);
#endif
/**
* path_is_absolute() - check if a path is absolute
* @path: path string to check
*
* On POSIX systems, a path starting with '/' is absolute.
* On Windows, absolute paths are either drive-letter paths (e.g. "C:\...")
* or UNC paths (e.g. "\\server\share").
*
* Returns: true if @path is absolute, false otherwise
*/
static inline bool path_is_absolute(const char *path)
{
#ifndef _WIN32
return path[0] == '/';
#else
return (isalpha(path[0]) && path[1] == ':') ||
(path[0] == '\\' && path[1] == '\\');
#endif
}
#endif