NeoMutt  2021-10-22-8-g9cb437
Teaching an old dog new tricks
DOXYGEN
path.c File Reference

Type representing a path. More...

#include "config.h"
#include <stddef.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "set.h"
#include "types.h"
+ Include dependency graph for path.c:

Go to the source code of this file.

Functions

static char * path_tidy (const char *path, bool is_dir)
 Tidy a path for storage. More...
 
static void path_destroy (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
 Destroy a Path - Implements ConfigSetType::destroy() -. More...
 
static int path_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Path by string - Implements ConfigSetType::string_set() -. More...
 
static int path_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Path as a string - Implements ConfigSetType::string_get() -. More...
 
static int path_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Path config item by string - Implements ConfigSetType::native_set() -. More...
 
static intptr_t path_native_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get a string from a Path config item - Implements ConfigSetType::native_get() -. More...
 
static int path_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Path to its initial value - Implements ConfigSetType::reset() -. More...
 

Variables

char * HomeDir
 User's home directory. More...
 
const struct ConfigSetType CstPath
 Config type representing a path. More...
 

Detailed Description

Type representing a path.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file path.c.

Function Documentation

◆ path_tidy()

static char* path_tidy ( const char *  path,
bool  is_dir 
)
static

Tidy a path for storage.

Parameters
pathPath to be tidied
is_dirIs the path a directory?
Return values
ptrTidy path

Expand ~ and remove junk like /./

Note
The caller must free the returned string

Definition at line 56 of file path.c.

57 {
58  if (!path || (*path == '\0'))
59  return NULL;
60 
61  char buf[PATH_MAX] = { 0 };
62  mutt_str_copy(buf, path, sizeof(buf));
63 
64  mutt_path_tilde(buf, sizeof(buf), HomeDir);
65  mutt_path_tidy(buf, is_dir);
66 
67  return mutt_str_dup(buf);
68 }
char * HomeDir
User's home directory.
Definition: mutt_globals.h:51
bool mutt_path_tidy(char *buf, bool is_dir)
Remove unnecessary parts of a path.
Definition: path.c:165
bool mutt_path_tilde(char *buf, size_t buflen, const char *homedir)
Expand '~' in a path.
Definition: path.c:223
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:749
#define PATH_MAX
Definition: mutt.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ HomeDir

char* HomeDir
extern

User's home directory.

Definition at line 51 of file mutt_globals.h.

◆ CstPath

const struct ConfigSetType CstPath
Initial value:
= {
"path",
NULL,
NULL,
}
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:73
static intptr_t path_native_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get a string from a Path config item - Implements ConfigSetType::native_get() -.
Definition: path.c:198
static int path_native_set(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a Path config item by string - Implements ConfigSetType::native_set() -.
Definition: path.c:156
static int path_reset(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Path to its initial value - Implements ConfigSetType::reset() -.
Definition: path.c:209
static int path_string_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Path as a string - Implements ConfigSetType::string_get() -.
Definition: path.c:136
static int path_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Path by string - Implements ConfigSetType::string_set() -.
Definition: path.c:85
#define DT_PATH
a path to a file/directory
Definition: types.h:36

Config type representing a path.

Definition at line 209 of file path.c.