Blame src/misc.h

Packit Service a2489d
/*
Packit Service a2489d
 * lftp - file transfer program
Packit Service a2489d
 *
Packit Service a2489d
 * Copyright (c) 1996-2017 by Alexander V. Lukyanov (lav@yars.free.net)
Packit Service a2489d
 *
Packit Service a2489d
 * This program is free software; you can redistribute it and/or modify
Packit Service a2489d
 * it under the terms of the GNU General Public License as published by
Packit Service a2489d
 * the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
 * (at your option) any later version.
Packit Service a2489d
 *
Packit Service a2489d
 * This program is distributed in the hope that it will be useful,
Packit Service a2489d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
 * GNU General Public License for more details.
Packit Service a2489d
 *
Packit Service a2489d
 * You should have received a copy of the GNU General Public License
Packit Service a2489d
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service a2489d
 */
Packit Service a2489d
Packit Service a2489d
#ifndef MISC_H
Packit Service a2489d
#define MISC_H
Packit Service a2489d
Packit Service a2489d
#include "trio.h"
Packit Service a2489d
#include <sys/types.h>
Packit Service a2489d
#include <sys/time.h>
Packit Service a2489d
#ifdef TIME_WITH_SYS_TIME
Packit Service a2489d
# include <time.h>
Packit Service a2489d
#endif
Packit Service a2489d
#include <stdarg.h>
Packit Service a2489d
Packit Service a2489d
#include "xstring.h"
Packit Service a2489d
Packit Service a2489d
// expands tilde; returns pointer to static data
Packit Service a2489d
const char *expand_home_relative(const char *);
Packit Service a2489d
Packit Service a2489d
// returns ptr to last path element
Packit Service a2489d
const char *basename_ptr(const char *);
Packit Service a2489d
static inline char *basename_ptr(char *f) {
Packit Service a2489d
   return const_cast<char*>(basename_ptr(const_cast<const char *>(f)));
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
// glues file to dir; returns pointer to static storage
Packit Service a2489d
const char *dir_file(const char *dir,const char *file);
Packit Service a2489d
Packit Service a2489d
// glues file to given url; returns pointer to static storage
Packit Service a2489d
const char *url_file(const char *url,const char *file);
Packit Service a2489d
Packit Service a2489d
const char *output_file_name(const char *src,const char *dst,bool dst_local,
Packit Service a2489d
			     const char *dst_base,bool make_dirs);
Packit Service a2489d
Packit Service a2489d
const char *squeeze_file_name(const char *name,int w);
Packit Service a2489d
Packit Service a2489d
// mkdir -p
Packit Service a2489d
int   create_directories(char *);
Packit Service a2489d
Packit Service a2489d
// rm -rf
Packit Service a2489d
void  truncate_file_tree(const char *dir);
Packit Service a2489d
Packit Service a2489d
/* returns file descriptor terminal width; -1 on error, 0 on N/A */
Packit Service a2489d
int fd_width(int fd);
Packit Service a2489d
Packit Service a2489d
/* returns true if current pgrp is the foreground pgrp of controlling tty
Packit Service a2489d
 * or if the fg pgrp is unknown */
Packit Service a2489d
bool in_foreground_pgrp();
Packit Service a2489d
Packit Service a2489d
// returns malloc'ed cwd no matter how long it is
Packit Service a2489d
// returns 0 on error.
Packit Service a2489d
char *xgetcwd();
Packit Service a2489d
// store cwd to specified string
Packit Service a2489d
void xgetcwd_to(xstring& s);
Packit Service a2489d
static inline void xgetcwd_to(xstring_c& s) { s.set_allocated(xgetcwd()); }
Packit Service a2489d
Packit Service a2489d
int percent(off_t offset,off_t size);
Packit Service a2489d
Packit Service a2489d
#define find_char(buf,len,ch) ((const char *)memchr(buf,ch,len))
Packit Service a2489d
Packit Service a2489d
extern const char month_names[][4];
Packit Service a2489d
Packit Service a2489d
int parse_month(const char *);
Packit Service a2489d
int parse_perms(const char *);
Packit Service a2489d
const char *format_perms(int p);
Packit Service a2489d
int parse_year_or_time(const char *year_or_time,int *year,int *hour,int *minute);
Packit Service a2489d
int guess_year(int month,int day,int hour,int minute);
Packit Service a2489d
Packit Service a2489d
time_t mktime_from_utc(const struct tm *);
Packit Service a2489d
time_t mktime_from_tz(struct tm *,const char *tz);
Packit Service a2489d
Packit Service a2489d
bool re_match(const char *line,const char *a,int flags=0);
Packit Service a2489d
Packit Service a2489d
struct subst_t {
Packit Service a2489d
   char from;
Packit Service a2489d
   const char *to;
Packit Service a2489d
};
Packit Service a2489d
Packit Service a2489d
/* Subst changes escape sequences to given strings, also substitutes \nnn
Packit Service a2489d
 * with corresponding character. Returns allocated buffer to be free'd */
Packit Service a2489d
xstring& SubstTo(xstring& buf,const char *txt,const subst_t *s);
Packit Service a2489d
Packit Service a2489d
/* uses gettimeofday if available */
Packit Service a2489d
void xgettimeofday(time_t *sec, int *usec);
Packit Service a2489d
Packit Service a2489d
/* returns malloc'd date */
Packit Service a2489d
char *xstrftime(const char *format, const struct tm *tm);
Packit Service a2489d
Packit Service a2489d
const char *xhuman(long long n);
Packit Service a2489d
Packit Service a2489d
void strip_trailing_slashes(xstring& fn);
Packit Service a2489d
xstring& dirname_modify(xstring& fn);
Packit Service a2489d
xstring& dirname(const char *path);  // returns a tmp
Packit Service a2489d
Packit Service a2489d
/* returns last character of string or \0 if string is empty */
Packit Service a2489d
char last_char(const char *str);
Packit Service a2489d
Packit Service a2489d
int  base64_length (int len);
Packit Service a2489d
void base64_encode (const char *s, char *store, int length);
Packit Service a2489d
Packit Service a2489d
bool temporary_network_error(int e);
Packit Service a2489d
Packit Service a2489d
CDECL const char *get_home();
Packit Service a2489d
CDECL const char *get_lftp_config_dir();
Packit Service a2489d
CDECL const char *get_lftp_data_dir();
Packit Service a2489d
CDECL const char *get_lftp_cache_dir();
Packit Service a2489d
Packit Service a2489d
const char *memrchr(const char *buf,char c,size_t len);
Packit Service a2489d
static inline char *memrchr(char *buf,char c,size_t len) {
Packit Service a2489d
   return const_cast<char*>(memrchr(const_cast<const char*>(buf),c,len));
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
bool is_shell_special(char c);
Packit Service a2489d
const xstring& shell_encode(const char *s,int len);
Packit Service a2489d
static inline const xstring& shell_encode(const char *s) { return shell_encode(s,strlen(s)); }
Packit Service a2489d
static inline const xstring& shell_encode(const xstring& s) { return shell_encode(s.get(),s.length()); }
Packit Service a2489d
void remove_tags(char *buf);
Packit Service a2489d
void rtrim(char *s);
Packit Service a2489d
Packit Service a2489d
void random_init();
Packit Service a2489d
double random01();
Packit Service a2489d
Packit Service a2489d
const char *get_nodename();
Packit Service a2489d
Packit Service a2489d
const char *xidna_to_ascii(const char *name);
Packit Service a2489d
bool xtld_name_ok(const char *name);
Packit Service a2489d
Packit Service a2489d
bool is_ipv4_address(const char *);
Packit Service a2489d
bool is_ipv6_address(const char *);
Packit Service a2489d
Packit Service a2489d
int lftp_fallocate(int fd,off_t sz);
Packit Service a2489d
Packit Service a2489d
void call_dynamic_hook(const char *name);
Packit Service a2489d
Packit Service a2489d
#endif // MISC_H