]>
diplodocus.org Git - nmh/blob - h/utils.h
3 * utils.h -- utility prototypes
6 /* Call malloc(3), exiting on NULL return. */
7 void *mh_xmalloc(size_t size
);
9 /* Call realloc(3), exiting on NULL return. */
10 void *mh_xrealloc(void *ptr
, size_t size
);
12 /* Call calloc(3), exiting on NULL return. */
13 void *mh_xcalloc(size_t nelem
, size_t elsize
);
15 /* Duplicate a NUL-terminated string, exit on failure. */
16 char *mh_xstrdup(const char *src
);
18 /* Call free(3), if ptr isn't NULL. */
19 void mh_xfree(void *ptr
);
21 /* Set p to point to newly allocated, uninitialised, memory. */
22 #define NEW(p) ((p) = mh_xmalloc(sizeof *(p)))
24 /* Set p to point to newly allocated, zeroed, memory. */
25 #define NEW0(p) ((p) = mh_xcalloc(1, sizeof *(p)))
28 char *add(const char *, char *);
29 char *addlist(char *, const char *);
30 int folder_exists(const char *);
31 void create_folder(char *, int, void (*)(int));
35 * A vector of char array, used to hold a list of string message numbers
36 * or command arguments.
45 * Same as msgs_array, but for a vector of ints
54 * Add a argument to the given msgs_array or msgnum_array structure; extend
55 * the array size if necessary
58 void app_msgarg(struct msgs_array
*, char *);
59 void app_msgnum(struct msgnum_array
*, int);
61 int open_form(char **, char *);
62 char *find_str (const char [], size_t, const char *);
63 char *rfind_str (const char [], size_t, const char *);
64 char *nmh_strcasestr (const char *, const char *);
66 void trunccpy(char *dst
, const char *src
, size_t size
);
67 /* A convenience for the common case of dst being an array. */
68 #define TRUNCCPY(dst, src) trunccpy(dst, src, sizeof (dst))
70 bool has_prefix(const char *s
, const char *prefix
);
71 bool has_suffix(const char *s
, const char *suffix
);
72 bool has_suffix_c(const char *s
, int c
);
73 void trim_suffix_c(char *s
, int c
);
74 void to_lower(char *s
);
75 void to_upper(char *s
);
78 * See if a string contains 8 bit characters (use isascii() for the test).
81 * start - Pointer to start of string to test.
82 * end - End of string to test (test will stop before reaching
83 * this point). If NULL, continue until reaching '\0'.
85 * This function always stops at '\0' regardless of the value of 'end'.
86 * Returns 1 if the string contains an 8-bit character, 0 if it does not.
88 int contains8bit(const char *start
, const char *end
);
91 * See if file has any 8-bit bytes.
94 * fd - file descriptor
95 * eightbit - address of result, will be set to 1 if the file contains
96 * any 8-bit bytes, 0 otherwise.
98 * Returns OK on success, NOTOK on read failure.
101 int scan_input (int fd
, int *eightbit
);
105 * Compares prior version of nmh with current version. Returns 1
106 * if they compare the be the same, 0 if not.
108 * older - 0 for difference comparison, 1 for only if older
110 int nmh_version_changed (int older
);