2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
5 * This program is free software; you can redistribute it
6 * and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later
11 * This program is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111, USA.
23 /* mutt functions which are generally useful. */
33 # include <unistd.h> /* needed for SEEK_SET */
35 # include <sys/types.h>
36 # include <sys/stat.h>
42 # ifndef _POSIX_PATH_MAX
43 # include <posix1_lim.h>
48 # define _(a) (gettext (a))
50 # define N_(a) gettext_noop (a)
62 # define HUGE_STRING 5120
63 # define LONG_STRING 1024
65 # define SHORT_STRING 128
68 * Create a format string to be used with scanf.
69 * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
71 * See K&R 2nd ed, p. 231 for an explanation.
73 # define _MUTT_FORMAT_2(a,b) "%" a b
74 # define _MUTT_FORMAT_1(a, b) _MUTT_FORMAT_2(#a, b)
75 # define MUTT_FORMAT(a) _MUTT_FORMAT_1(a, "s")
76 # define MUTT_FORMAT2(a,b) _MUTT_FORMAT_1(a, b)
79 # define FREE(x) safe_free(x)
80 # define NONULL(x) x?x:""
81 # define ISSPACE(c) isspace((unsigned char)c)
82 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
86 # define MAX(a,b) ((a) < (b) ? (b) : (a))
87 # define MIN(a,b) ((a) < (b) ? (a) : (b))
90 #define FOREVER while (1)
92 /* this macro must check for *c == 0 since isspace(0) has unreliable behavior
94 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
97 * These functions aren't defined in lib.c, but
98 * they are used there.
100 * A non-mutt "implementation" (ahem) can be found in extlib.c.
104 extern void (*mutt_error) (const char *, ...);
106 void mutt_exit (int);
108 /* The actual library functions. */
110 FILE *safe_fopen (const char *, const char *);
112 char *mutt_concat_path (char *, const char *, const char *, size_t);
113 char *mutt_read_line (char *, size_t *, FILE *, int *);
114 char *mutt_skip_whitespace (char *);
115 char *mutt_strlower (char *);
116 char *mutt_substrcpy (char *, const char *, const char *, size_t);
117 char *mutt_substrdup (const char *, const char *);
118 char *safe_strdup (const char *);
120 const char *mutt_stristr (const char *, const char *);
121 const char *mutt_basename (const char *);
123 int mutt_copy_stream (FILE *, FILE *);
124 int mutt_copy_bytes (FILE *, FILE *, size_t);
125 int mutt_rx_sanitize_string (char *, size_t, const char *);
126 int mutt_strcasecmp (const char *, const char *);
127 int mutt_strcmp (const char *, const char *);
128 int mutt_strncasecmp (const char *, const char *, size_t);
129 int mutt_strncmp (const char *, const char *, size_t);
130 int mutt_strcoll (const char *, const char *);
131 int safe_open (const char *, int);
132 int safe_symlink (const char *, const char *);
133 int safe_rename (const char *, const char *);
134 int safe_fclose (FILE **);
136 size_t mutt_quote_filename (char *, size_t, const char *);
137 size_t mutt_strlen (const char *);
139 void *safe_calloc (size_t, size_t);
140 void *safe_malloc (size_t);
141 void mutt_nocurses_error (const char *, ...);
142 void mutt_remove_trailing_ws (char *);
143 void mutt_sanitize_filename (char *, short);
144 void mutt_str_replace (char **p, const char *s);
145 void mutt_str_adjust (char **p);
146 void mutt_unlink (const char *);
147 void safe_free (void *);
148 void safe_realloc (void *, size_t);