File include/jlib/fs/directory.h changed (mode: 100644) (index bc018c3..befb317) |
22 |
22 |
#pragma once |
#pragma once |
23 |
23 |
#include "staff.h" |
#include "staff.h" |
24 |
24 |
#include <libgen.h> |
#include <libgen.h> |
|
25 |
|
#ifdef _WIN32 |
|
26 |
|
#include <jlib/allocate.h> |
|
27 |
|
#endif |
25 |
28 |
/** |
/** |
26 |
29 |
* @brief Namespace with functions for system directories manipulation. |
* @brief Namespace with functions for system directories manipulation. |
27 |
30 |
*/ |
*/ |
|
... |
... |
namespace jl::fs::dir |
73 |
76 |
[[nodiscard]] inline bool current(char *p_dst, uint64_t limit) { |
[[nodiscard]] inline bool current(char *p_dst, uint64_t limit) { |
74 |
77 |
return getcwd(p_dst, limit) != nullptr; |
return getcwd(p_dst, limit) != nullptr; |
75 |
78 |
} |
} |
|
79 |
|
[[nodiscard]] inline bool current(char **pp_dst) { |
|
80 |
|
#ifdef _WIN32 |
|
81 |
|
if (not jl::allocate_bytes(pp_dst, MAX_PATH)) |
|
82 |
|
return false; |
|
83 |
|
if (not current(*pp_dst, MAX_PATH)) { |
|
84 |
|
jl::deallocate(pp_dst); |
|
85 |
|
return false; |
|
86 |
|
} |
|
87 |
|
return true; |
|
88 |
|
#else |
|
89 |
|
*pp_dst = get_current_dir_name(); |
|
90 |
|
return *pp_dst != nullptr; |
|
91 |
|
#endif |
|
92 |
|
} |
76 |
93 |
/** |
/** |
77 |
94 |
* @brief Modify file path to be directory path where this file is. |
* @brief Modify file path to be directory path where this file is. |
78 |
95 |
* |
* |
File include/jlib/fs/staff.h changed (mode: 100644) (index fcb24af..348b4f5) |
21 |
21 |
*/ |
*/ |
22 |
22 |
#pragma once |
#pragma once |
23 |
23 |
#include <sys/stat.h> |
#include <sys/stat.h> |
24 |
|
#ifndef _WIN32 |
|
|
24 |
|
#ifdef _WIN32 |
|
25 |
|
#include <minwindef.h> |
|
26 |
|
#else |
25 |
27 |
#include <linux/limits.h> |
#include <linux/limits.h> |
26 |
28 |
#endif |
#endif |
27 |
29 |
#include <cinttypes> |
#include <cinttypes> |
|
32 |
34 |
#ifndef _WIN32 |
#ifndef _WIN32 |
33 |
35 |
namespace jl::fs::details { |
namespace jl::fs::details { |
34 |
36 |
[[nodiscard]] inline bool |
[[nodiscard]] inline bool |
35 |
|
fs_info(const char *fname, int type, uint64_t *p_dst) { |
|
36 |
|
auto length = pathconf(fname, type); |
|
37 |
|
if (length < 0) |
|
38 |
|
return false; |
|
39 |
|
*p_dst = uint64_t(length); |
|
40 |
|
return true; |
|
|
37 |
|
fs_info(const char *fname, int type, int64_t *p_dst) { |
|
38 |
|
errno = 0; |
|
39 |
|
*p_dst = pathconf(fname, type); |
|
40 |
|
return *p_dst < 0 ? errno == 0 : true; |
41 |
41 |
} |
} |
42 |
42 |
} |
} |
43 |
43 |
#endif |
#endif |
|
... |
... |
namespace jl::fs |
66 |
66 |
permissions(mode user, mode group = mode::READ, mode other = mode::READ) { |
permissions(mode user, mode group = mode::READ, mode other = mode::READ) { |
67 |
67 |
return perm(perm(user) << 6 | perm(group) << 3 | perm(other)); |
return perm(perm(user) << 6 | perm(group) << 3 | perm(other)); |
68 |
68 |
} |
} |
69 |
|
#ifndef _WIN32 |
|
70 |
|
/// @brief Get max file path length |
|
|
69 |
|
/// @brief Get max file path length. |
|
70 |
|
/// @param p_dst Limit or -1 (unlimited) will be set. |
|
71 |
|
/// @return If failed - check errno for details. |
71 |
72 |
[[nodiscard]] inline bool |
[[nodiscard]] inline bool |
72 |
|
max_path_length(const char *fname, uint64_t *p_dst) { |
|
|
73 |
|
max_path_length(const char *fname, int64_t *p_dst) { |
|
74 |
|
#ifdef _WIN32 |
|
75 |
|
(void)fname; |
|
76 |
|
return *p_dst = MAX_PATH, true; |
|
77 |
|
#else |
73 |
78 |
return details::fs_info(fname, _PC_PATH_MAX, p_dst); |
return details::fs_info(fname, _PC_PATH_MAX, p_dst); |
|
79 |
|
#endif |
74 |
80 |
} |
} |
75 |
|
/// @brief Get max file name length |
|
|
81 |
|
/// @brief Get max file name length. |
|
82 |
|
/// @param p_dst Limit or -1 (unlimited) will be set. |
|
83 |
|
/// @return If failed - check errno for details. |
76 |
84 |
[[nodiscard]] inline bool |
[[nodiscard]] inline bool |
77 |
|
max_name_length(const char *fname, uint64_t *p_dst) { |
|
78 |
|
return details::fs_info(fname, _PC_NAME_MAX, p_dst); |
|
79 |
|
} |
|
|
85 |
|
max_name_length(const char *fname, int64_t *p_dst) { |
|
86 |
|
#ifdef _WIN32 |
|
87 |
|
(void)fname; |
|
88 |
|
return *p_dst = MAX_PATH, true; |
80 |
89 |
#else |
#else |
81 |
|
/// @brief Get max file path length |
|
82 |
|
[[nodiscard]] inline bool max_path_length(const char *, uint64_t *p_dst) { |
|
83 |
|
return *p_dst = PATH_MAX, true; |
|
84 |
|
} |
|
85 |
|
/// @brief Get max file name length |
|
86 |
|
[[nodiscard]] inline bool max_name_length(const char *, uint64_t *p_dst) { |
|
87 |
|
return *p_dst = PATH_MAX, true; |
|
88 |
|
} |
|
|
90 |
|
return details::fs_info(fname, _PC_NAME_MAX, p_dst); |
89 |
91 |
#endif |
#endif |
|
92 |
|
} |
90 |
93 |
/// @brief Get file or directory modification time. |
/// @brief Get file or directory modification time. |
91 |
94 |
[[nodiscard]] inline bool |
[[nodiscard]] inline bool |
92 |
95 |
modification_time(const char *path, time_t *p_dst) { |
modification_time(const char *path, time_t *p_dst) { |
|
... |
... |
namespace jl::fs |
117 |
120 |
return strerror(errno); |
return strerror(errno); |
118 |
121 |
} |
} |
119 |
122 |
} |
} |
120 |
|
|
|