2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
6 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
11 /* mutt functions which are generally useful. */
19 # include <unistd.h> /* needed for SEEK_SET */
21 # include <sys/types.h>
22 # include <sys/stat.h>
28 # ifndef _POSIX_PATH_MAX
29 # include <posix1_lim.h>
34 # define _(a) (gettext (a))
36 # define N_(a) gettext_noop (a)
48 # define HUGE_STRING 5120
49 # define LONG_STRING 1024
51 # define SHORT_STRING 128
54 * Create a format string to be used with scanf.
55 * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
57 * See K&R 2nd ed, p. 231 for an explanation.
59 # define _MUTT_FORMAT_2(a,b) "%" a b
60 # define _MUTT_FORMAT_1(a, b) _MUTT_FORMAT_2(#a, b)
61 # define MUTT_FORMAT(a) _MUTT_FORMAT_1(a, "s")
62 # define MUTT_FORMAT2(a,b) _MUTT_FORMAT_1(a, b)
65 # define FREE(x) safe_free(x)
66 # define NONULL(x) x?x:""
67 # define ISSPACE(c) isspace((unsigned char)c)
68 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
72 # define MAX(a,b) ((a) < (b) ? (b) : (a))
73 # define MIN(a,b) ((a) < (b) ? (a) : (b))
76 #define FOREVER while (1)
78 /* this macro must check for *c == 0 since isspace(0) has unreliable behavior
80 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
82 #define ISBLANK(c) (c == ' ' || c == '\t')
84 * These functions aren't defined in lib.c, but
85 * they are used there.
87 * A non-mutt "implementation" (ahem) can be found in extlib.c.
91 extern void (*mutt_error) (const char *, ...);
95 /* The actual library functions. */
97 FILE *safe_fopen (const char *, const char *);
99 char *mutt_concat_path (char *, const char *, const char *, size_t);
100 char *mutt_read_line (char *, size_t *, FILE *, int *);
101 char *mutt_skip_whitespace (char *);
102 char *mutt_strlower (char *);
103 char *mutt_substrcpy (char *, const char *, const char *, size_t);
104 char *mutt_substrdup (const char *, const char *);
105 char *safe_strcat (char *, size_t, const char *);
106 char *safe_strncat (char *, size_t, const char *, size_t);
107 char *safe_strdup (const char *);
109 const char *mutt_stristr (const char *, const char *);
110 const char *mutt_basename (const char *);
112 int mutt_copy_stream (FILE *, FILE *);
113 int mutt_copy_bytes (FILE *, FILE *, size_t);
114 int mutt_rx_sanitize_string (char *, size_t, const char *);
115 int mutt_strcasecmp (const char *, const char *);
116 int mutt_strcmp (const char *, const char *);
117 int mutt_strncasecmp (const char *, const char *, size_t);
118 int mutt_strncmp (const char *, const char *, size_t);
119 int mutt_strcoll (const char *, const char *);
120 int safe_open (const char *, int);
121 int safe_symlink (const char *, const char *);
122 int safe_rename (const char *, const char *);
123 int safe_fclose (FILE **);
125 size_t mutt_quote_filename (char *, size_t, const char *);
126 size_t mutt_strlen (const char *);
128 void *safe_calloc (size_t, size_t);
129 void *safe_malloc (size_t);
130 void mutt_nocurses_error (const char *, ...);
131 void mutt_remove_trailing_ws (char *);
132 void mutt_sanitize_filename (char *, short);
133 void mutt_str_replace (char **p, const char *s);
134 void mutt_str_adjust (char **p);
135 void mutt_unlink (const char *);
136 void safe_free (void *);
137 void safe_realloc (void *, size_t);