]>
diplodocus.org Git - nmh/blob - h/utils.h
1 /* utils.h -- utility prototypes
4 /* Call malloc(3), exiting on NULL return. */
5 void *mh_xmalloc(size_t size
);
7 /* Call realloc(3), exiting on NULL return. */
8 void *mh_xrealloc(void *ptr
, size_t size
);
10 /* Call calloc(3), exiting on NULL return. */
11 void *mh_xcalloc(size_t nelem
, size_t elsize
);
13 /* Duplicate a NUL-terminated string, exit on failure. */
14 char *mh_xstrdup(const char *src
);
16 /* Call free(3), if ptr isn't NULL. */
17 void mh_xfree(void *ptr
);
19 /* Set p to point to newly allocated, uninitialised, memory. */
20 #define NEW(p) ((p) = mh_xmalloc(sizeof *(p)))
22 /* Set p to point to newly allocated, zeroed, memory. */
23 #define NEW0(p) ((p) = mh_xcalloc(1, sizeof *(p)))
26 char *add(const char *, char *);
27 char *addlist(char *, const char *);
28 int folder_exists(const char *);
29 void create_folder(char *, int, void (*)(int));
33 * A vector of char array, used to hold a list of string message numbers
34 * or command arguments.
43 * Same as msgs_array, but for a vector of ints
52 * Add a argument to the given msgs_array or msgnum_array structure; extend
53 * the array size if necessary
56 void app_msgarg(struct msgs_array
*, char *);
57 void app_msgnum(struct msgnum_array
*, int);
59 int open_form(char **, char *);
60 char *find_str (const char [], size_t, const char *);
61 char *rfind_str (const char [], size_t, const char *);
62 char *nmh_strcasestr (const char *, const char *);
64 void trunccpy(char *dst
, const char *src
, size_t size
);
65 /* A convenience for the common case of dst being an array. */
66 #define TRUNCCPY(dst, src) trunccpy(dst, src, sizeof (dst))
68 bool has_prefix(const char *s
, const char *prefix
);
69 bool has_suffix(const char *s
, const char *suffix
);
70 bool has_suffix_c(const char *s
, int c
);
71 void trim_suffix_c(char *s
, int c
);
72 void to_lower(char *s
);
73 void to_upper(char *s
);
76 * See if a string contains 8 bit characters (use isascii() for the test).
79 * start - Pointer to start of string to test.
80 * end - End of string to test (test will stop before reaching
81 * this point). If NULL, continue until reaching '\0'.
83 * This function always stops at '\0' regardless of the value of 'end'.
84 * Returns 1 if the string contains an 8-bit character, 0 if it does not.
86 int contains8bit(const char *start
, const char *end
);
89 * See if file has any 8-bit bytes.
92 * fd - file descriptor
93 * eightbit - address of result, will be set to 1 if the file contains
94 * any 8-bit bytes, 0 otherwise.
96 * Returns OK on success, NOTOK on read failure.
99 int scan_input (int fd
, int *eightbit
);
103 * Compares prior version of nmh with current version. Returns 1
104 * if they compare the be the same, 0 if not.
106 * older - 0 for difference comparison, 1 for only if older
108 int nmh_version_changed (int older
);