]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/core/util_posix.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2015-2020, Intel Corporation */
5 * util_posix.c -- Abstraction layer for misc utilities (Posix implementation)
17 /* pass through for Posix */
19 util_strerror(int errnum
, char *buff
, size_t bufflen
)
21 strerror_r(errnum
, buff
, bufflen
);
25 * util_strwinerror -- should never be called on posix OS - abort()
28 util_strwinerror(unsigned long err
, char *buff
, size_t bufflen
)
34 * util_part_realpath -- get canonicalized absolute pathname
36 * As paths used in a poolset file have to be absolute (checked when parsing
37 * a poolset file), here we only have to resolve symlinks.
40 util_part_realpath(const char *path
)
42 return realpath(path
, NULL
);
46 * util_compare_file_inodes -- compare device and inodes of two files;
47 * this resolves hard links
50 util_compare_file_inodes(const char *path1
, const char *path2
)
53 if (os_stat(path1
, &sb1
)) {
54 if (errno
!= ENOENT
) {
55 ERR("!stat failed for %s", path1
);
58 LOG(1, "stat failed for %s", path1
);
60 return strcmp(path1
, path2
) != 0;
63 if (os_stat(path2
, &sb2
)) {
64 if (errno
!= ENOENT
) {
65 ERR("!stat failed for %s", path2
);
68 LOG(1, "stat failed for %s", path2
);
70 return strcmp(path1
, path2
) != 0;
73 return sb1
.st_dev
!= sb2
.st_dev
|| sb1
.st_ino
!= sb2
.st_ino
;
77 * util_aligned_malloc -- allocate aligned memory
80 util_aligned_malloc(size_t alignment
, size_t size
)
84 errno
= posix_memalign(&retval
, alignment
, size
);
90 * util_aligned_free -- free allocated memory in util_aligned_malloc
93 util_aligned_free(void *ptr
)
99 * util_getexecname -- return name of current executable
102 util_getexecname(char *path
, size_t pathlen
)
104 ASSERT(pathlen
!= 0);
108 #include <sys/types.h>
109 #include <sys/sysctl.h>
111 int mib
[4] = {CTL_KERN
, KERN_PROC
, KERN_PROC_PATHNAME
, -1};
113 cc
= (sysctl(mib
, 4, path
, &pathlen
, NULL
, 0) == -1) ?
114 -1 : (ssize_t
)pathlen
;
116 cc
= readlink("/proc/self/exe", path
, pathlen
);
119 strncpy(path
, "unknown", pathlen
);
120 path
[pathlen
- 1] = '\0';