Blender  V3.3
BLI_path_util.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 #pragma once
4 
9 #include "BLI_compiler_attrs.h"
10 #include "BLI_utildefines.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
20 void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
27 void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
36 const char *BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
37 
47 void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
53 bool BLI_make_existing_file(const char *name);
62 void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen);
66 void BLI_split_dir_part(const char *string, char *dir, size_t dirlen);
70 void BLI_split_file_part(const char *string, char *file, size_t filelen);
75 const char *BLI_path_extension(const char *filepath) ATTR_NONNULL();
76 
80 void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file)
81  ATTR_NONNULL();
89 void BLI_join_dirfile(char *__restrict dst,
90  size_t maxlen,
91  const char *__restrict dir,
92  const char *__restrict file) ATTR_NONNULL();
100 size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...)
108 const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
118 bool BLI_path_name_at_index(const char *__restrict path,
119  int index,
120  int *__restrict r_offset,
121  int *__restrict r_len) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
122 
124 bool BLI_path_contains(const char *container_path,
125  const char *containee_path) ATTR_WARN_UNUSED_RESULT;
126 
130 const char *BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
134 const char *BLI_path_slash_rfind(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
139 int BLI_path_slash_ensure(char *string) ATTR_NONNULL();
143 void BLI_path_slash_rstrip(char *string) ATTR_NONNULL();
147 void BLI_path_slash_native(char *path) ATTR_NONNULL();
148 
149 #ifdef _WIN32
150 bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen);
151 #endif
155 bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name);
156 
160 bool BLI_path_extension_check(const char *str, const char *ext)
162 bool BLI_path_extension_check_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
166 bool BLI_path_extension_check_array(const char *str, const char **ext_array)
172 bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch)
183 bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL();
188 bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
192 bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
197 bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL();
209 int BLI_path_sequence_decode(const char *string,
210  char *head,
211  char *tail,
212  unsigned short *r_digits_len);
218  char *string, const char *head, const char *tail, unsigned short numlen, int pic);
219 
229 void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2);
235 void BLI_path_normalize_dir(const char *relabase, char *dir) ATTR_NONNULL(2);
236 
263 bool BLI_filename_make_safe_ex(char *fname, bool allow_tokens) ATTR_NONNULL(1);
264 bool BLI_filename_make_safe(char *fname) ATTR_NONNULL(1);
265 
271 bool BLI_path_make_safe(char *path) ATTR_NONNULL(1);
272 
279 bool BLI_path_parent_dir(char *path) ATTR_NONNULL();
287 
298 bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL();
303 bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL();
309 bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL();
313 bool BLI_path_frame_get(char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL();
320 void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxlen) ATTR_NONNULL();
339 bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL();
344 void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL();
345 
350 bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
354 bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
355 
360 void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL();
361 
362 #if defined(WIN32)
363 void BLI_path_normalize_unc_16(wchar_t *path_16);
364 void BLI_path_normalize_unc(char *path_16, int maxlen);
365 #endif
366 
379 bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep)
380  ATTR_NONNULL();
381 
382 /* Path string comparisons: case-insensitive for Windows, case-sensitive otherwise. */
383 #if defined(WIN32)
384 # define BLI_path_cmp BLI_strcasecmp
385 # define BLI_path_ncmp BLI_strncasecmp
386 #else
387 # define BLI_path_cmp strcmp
388 # define BLI_path_ncmp strncmp
389 #endif
390 
402 int BLI_path_cmp_normalized(const char *p1, const char *p2)
404 
405 /* These values need to be hard-coded in structs, dna does not recognize defines */
406 /* also defined in `DNA_space_types.h`. */
407 #ifndef FILE_MAXDIR
408 # define FILE_MAXDIR 768
409 # define FILE_MAXFILE 256
410 # define FILE_MAX 1024
411 #endif
412 
413 #ifdef WIN32
414 # define SEP '\\'
415 # define ALTSEP '/'
416 # define SEP_STR "\\"
417 # define ALTSEP_STR "/"
418 #else
419 # define SEP '/'
420 # define ALTSEP '\\'
421 # define SEP_STR "/"
422 # define ALTSEP_STR "\\"
423 #endif
424 
425 /* Parent and current dir helpers. */
426 #define FILENAME_PARENT ".."
427 #define FILENAME_CURRENT "."
428 
429 /* Avoid calling `strcmp` on one or two chars! */
430 #define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
431 #define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
432 #define FILENAME_IS_CURRPAR(_n) \
433  (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
434 
435 #ifdef __cplusplus
436 }
437 #endif
#define ATTR_NONNULL(...)
const char * BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1750
void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL()
Definition: path_util.c:859
bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL()
Definition: path_util.c:639
bool BLI_path_extension_check_array(const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1326
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
Definition: path_util.c:1490
int BLI_path_sequence_decode(const char *string, char *head, char *tail, unsigned short *r_digits_len)
Definition: path_util.c:56
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1653
bool BLI_path_make_safe(char *path) ATTR_NONNULL(1)
Definition: path_util.c:314
bool BLI_path_name_at_index(const char *__restrict path, int index, int *__restrict r_offset, int *__restrict r_len) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1659
bool BLI_filename_make_safe_ex(char *fname, bool allow_tokens) ATTR_NONNULL(1)
Definition: path_util.c:232
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:347
bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL()
Definition: path_util.c:709
void BLI_path_normalize_dir(const char *relabase, char *dir) ATTR_NONNULL(2)
Definition: path_util.c:221
size_t ATTR_SENTINEL(0)
const char * BLI_path_extension(const char *filepath) ATTR_NONNULL()
Definition: path_util.c:1500
bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL()
Definition: path_util.c:1452
bool BLI_make_existing_file(const char *name)
Definition: path_util.c:1197
bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:853
void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen)
Definition: path_util.c:1465
bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL()
Definition: path_util.c:1367
void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2)
Definition: path_util.c:131
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1)
Definition: path_util.c:1143
bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
Definition: path_util.c:1420
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:998
bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name)
Definition: path_util.c:1091
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file)
Definition: path_util.c:1206
void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1514
bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1341
bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
Definition: path_util.c:1393
void BLI_path_slash_rstrip(char *string) ATTR_NONNULL()
Definition: path_util.c:1791
int ATTR_WARN_UNUSED_RESULT
bool BLI_path_frame_get(char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL()
Definition: path_util.c:753
bool BLI_path_extension_check(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1299
void BLI_path_sequence_encode(char *string, const char *head, const char *tail, unsigned short numlen, int pic)
Definition: path_util.c:123
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1717
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1168
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first,...) ATTR_NONNULL(1
bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL()
Definition: path_util.c:1015
int BLI_path_slash_ensure(char *string) ATTR_NONNULL()
Definition: path_util.c:1780
bool BLI_filename_make_safe(char *fname) ATTR_NONNULL(1)
Definition: path_util.c:309
void BLI_path_slash_native(char *path) ATTR_NONNULL()
Definition: path_util.c:1805
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL()
Definition: path_util.c:450
void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1)
Definition: path_util.c:1161
bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL()
Definition: path_util.c:727
const char * BLI_path_slash_rfind(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1765
void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxlen) ATTR_NONNULL()
Definition: path_util.c:805
bool BLI_path_parent_dir(char *path) ATTR_NONNULL()
Definition: path_util.c:623
void BLI_split_file_part(const char *string, char *file, size_t filelen)
Definition: path_util.c:1495
bool BLI_path_extension_check_n(const char *str,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
Definition: path_util.c:1304
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:352
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
Definition: path_util.c:897
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1531
bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep) ATTR_NONNULL()
Definition: path_util.c:588
FILE * file
#define str(s)