wget2 2.3.0
Loading...
Searching...
No Matches
utils.c File Reference

General utility functions. More...

#include <config.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
#include <glob.h>
#include "c-ctype.h"
#include "c-strcase.h"
#include "timespec.h"
#include <wget.h>
#include "private.h"

Functions

int wget_strcmp (const char *s1, const char *s2)
int wget_strcasecmp (const char *s1, const char *s2)
int wget_strcasecmp_ascii (const char *s1, const char *s2)
int wget_strncasecmp_ascii (const char *s1, const char *s2, size_t n)
char * wget_strtolower (char *s)
int wget_strncmp (const char *s1, const char *s2, size_t n)
int wget_strncasecmp (const char *s1, const char *s2, size_t n)
void wget_memtohex (const unsigned char *src, size_t src_len, char *dst, size_t dst_size)
void wget_millisleep (int ms)
long long wget_get_timemillis (void)
int wget_percent_unescape (char *src)
int wget_match_tail (const char *s, const char *tail)
int wget_match_tail_nocase (const char *s, const char *tail)
char * wget_strnglob (const char *str, size_t n, int flags)
char * wget_human_readable (char *buf, size_t bufsize, uint64_t n)
int wget_get_screen_size (WGET_GCC_UNUSED int *width, WGET_GCC_UNUSED int *height)
char * wget_path_sanitize (const char *path)

Detailed Description

General utility functions.

Function Documentation

◆ wget_path_sanitize()

char * wget_path_sanitize ( const char * path)
Parameters
[in]pathInput path to sanitize
Returns
Newly allocated sanitized path, or NULL on error

Sanitizes the given file path by resolving ".", "..", and multiple slashes.

Examples: "/root/foo/../bar/.//x.txt" -> "/root/bar/x.txt" "foo/../bar" -> "bar" "/foo/./bar" -> "/foo/bar" "/foo//bar" -> "/foo/bar" "foo/bar/.." -> "foo" ".." -> ".." (preserved, cannot resolve past root) "/../foo" -> "/foo" (stays at root) "" -> "." (empty path becomes current directory)

The returned string must be freed with wget_free().