11 #ifndef HAVE_DCGETTEXT
12 const char *dcgettext(const char *domain, const char *msg, int category)
16 #endif /* !HAVE_DCGETTEXT */
18 #ifndef HAVE_LIBINTL_DGETTEXT
19 const char *libintl_dgettext(const char *domain, const char *msg)
23 #endif /* !HAVE_LIBINTL_DGETTEXT */
26 /* Read a line from IN. LINE points to a malloc'd buffer that is extended as
27 necessary. ALLOC points to the allocated length of LINE. Returns
28 the length of the string read (including any trailing \n) */
30 ssize_t getline(char **line, size_t *alloc, FILE *in)
36 *line = xmalloc(*alloc);
40 if (!fgets(*line + len, *alloc - len, in))
42 len += strlen(*line + len);
43 if (len && (*line)[len - 1] == '\n')
47 *line = xrealloc(*line, *alloc);
52 /* fatal error & exit */
53 void fatal(const char *format, ...)
57 va_start(args, format);
58 fprintf(stderr, "%s: ", elf2flt_progname);
59 vfprintf(stderr, format, args);
60 fprintf(stderr, "\n");
65 /* fatal error, perror & exit */
66 void fatal_perror(const char *format, ...)
71 va_start(args, format);
72 fprintf(stderr, "%s: ", elf2flt_progname);
73 vfprintf(stderr, format, args);
74 fprintf(stderr, ": %s\n", strerror(e));
79 /* open a file or fail */
80 FILE *xfopen(const char *path, const char *mode)
82 FILE *ret = fopen(path, mode);
84 fatal_perror("Unable to open '%s'", path);
88 /* Append a string SRC to an options array DST */
89 void append_option(options_t *dst, const char *src)
91 if (dst->alloc == dst->num) {
92 size_t a = (dst->num + 2) * 2;
93 void *o = xmalloc(sizeof(*dst->options) * a);
95 memcpy(o, dst->options, sizeof(*dst->options) * dst->num);
101 dst->options[dst->num] = src;
105 /* Split and append a string SRC to an options array DST */
106 void append_option_str(options_t *dst, const char *src, const char *delim)
108 char *tok_src = xstrdup(src);
109 char *tok = strtok(tok_src, delim);
111 append_option(dst, tok);
112 tok = strtok(NULL, delim);
114 /* don't free tok_src since options_t now points to it */
117 /* Append an options array SRC to another options array DST */
118 void append_options(options_t *dst, const options_t *src)
120 if (dst->alloc < dst->num + src->num) {
121 size_t a = (dst->num + src->num + 2) * 2;
122 void *o = xmalloc(sizeof(*dst->options) * a);
124 memcpy(o, dst->options, sizeof(*dst->options) * dst->num);
130 memcpy(&dst->options[dst->num], &src->options[0],
131 sizeof(*dst->options) * src->num);
132 dst->num += src->num;